Skip to content

Commit

Permalink
refractor(ressources): remove all .tf files
Browse files Browse the repository at this point in the history
  • Loading branch information
LeCrabe committed Apr 25, 2024
1 parent 0561aaf commit 56b1972
Show file tree
Hide file tree
Showing 31 changed files with 157 additions and 198 deletions.
3 changes: 0 additions & 3 deletions pkg/resources/addon/provider_test_block.tf

This file was deleted.

19 changes: 12 additions & 7 deletions pkg/resources/addon/resource_addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@ import (
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"go.clever-cloud.com/terraform-provider/pkg/helper"
"go.clever-cloud.com/terraform-provider/pkg/provider/impl"
"go.clever-cloud.com/terraform-provider/pkg/tmp"
"go.clever-cloud.dev/client"
)

//go:embed resource_addon_test_block.tf
var addonBlock string

//go:embed provider_test_block.tf
var providerBlock string

var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){
"clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()),
}
Expand All @@ -33,6 +28,16 @@ func TestAccAddon_basic(t *testing.T) {
fullName := fmt.Sprintf("clevercloud_addon.%s", rName)
cc := client.New(client.WithAutoOauthConfig())
org := os.Getenv("ORGANISATION")
providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String()
addonBlock := helper.NewRessource(
"clevercloud_addon",
rName,
helper.SetKeyValues(map[string]any{
"name": rName,
"region": "par",
"plan": "clever_solo",
"third_party_provider": "mailpace",
})).String()

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -57,7 +62,7 @@ func TestAccAddon_basic(t *testing.T) {
},
Steps: []resource.TestStep{{
ResourceName: rName,
Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(addonBlock, rName, rName),
Config: providerBlock + addonBlock,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^addon_.*`)),
//resource.TestMatchResourceAttr(fullName, "password", regexp.MustCompile(`^[a-zA-Z0-9]+$`)),
Expand Down
7 changes: 0 additions & 7 deletions pkg/resources/addon/resource_addon_test_block.tf

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/resources/cellar/bucket/provider_test_block.tf

This file was deleted.

25 changes: 15 additions & 10 deletions pkg/resources/cellar/bucket/resource_cellar_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,23 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"go.clever-cloud.com/terraform-provider/pkg/helper"
"go.clever-cloud.com/terraform-provider/pkg/provider/impl"
"go.clever-cloud.com/terraform-provider/pkg/s3"
"go.clever-cloud.com/terraform-provider/pkg/tmp"
"go.clever-cloud.dev/client"
)

//go:embed resource_cellar_bucket_test_block.tf
var cellarBucketBlock string

//go:embed provider_test_block.tf
var TestProviderBlock string

var TestProtoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){
"clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()),
}

func TestAccCellarBucket_basic(t *testing.T) {
ctx := context.Background()
bName := fmt.Sprintf("my-bucket-%d", time.Now().UnixMilli())
rName := fmt.Sprintf("my-bucket-%d", time.Now().UnixMilli())
cc := client.New(client.WithAutoOauthConfig())
org := os.Getenv("ORGANISATION")
providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String()

cellar := &tmp.AddonResponse{}
if os.Getenv("TF_ACC") == "1" {
Expand All @@ -48,6 +44,7 @@ func TestAccCellarBucket_basic(t *testing.T) {
}

cellar = res.Payload()
fmt.Print(cellar)

defer func() {
rmRes := tmp.DeleteAddon(ctx, cc, org, cellar.ID)
Expand All @@ -57,6 +54,14 @@ func TestAccCellarBucket_basic(t *testing.T) {
}()
}

cellarBucketBlock := helper.NewRessource(
"clevercloud_cellar_bucket",
rName,
helper.SetKeyValues(map[string]any{
"id": rName,
"cellar_id": cellar.RealID,
})).String()

resource.Test(t, resource.TestCase{
PreCheck: func() {
if org == "" {
Expand All @@ -68,8 +73,8 @@ func TestAccCellarBucket_basic(t *testing.T) {
},
ProtoV6ProviderFactories: TestProtoV6Provider,
Steps: []resource.TestStep{{
ResourceName: "cellar_bucket_" + bName,
Config: fmt.Sprintf(TestProviderBlock, org) + fmt.Sprintf(cellarBucketBlock, bName, bName, cellar.RealID),
ResourceName: "cellar_bucket_" + rName,
Config: providerBlock + cellarBucketBlock,
Check: resource.ComposeAggregateTestCheckFunc(
func(*terraform.State) error {
return nil
Expand All @@ -92,7 +97,7 @@ func TestAccCellarBucket_basic(t *testing.T) {
return fmt.Errorf("unexpectd error: %s", res.Error().Error())
}

exists, err := minioClient.BucketExists(ctx, bName)
exists, err := minioClient.BucketExists(ctx, rName)
if err != nil {
return fmt.Errorf("unexpectd error: %s", res.Error().Error())
}
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/resources/cellar/provider_test_block.tf

This file was deleted.

23 changes: 13 additions & 10 deletions pkg/resources/cellar/resource_cellar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,30 @@ import (
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"go.clever-cloud.com/terraform-provider/pkg/helper"
"go.clever-cloud.com/terraform-provider/pkg/provider/impl"
"go.clever-cloud.com/terraform-provider/pkg/tmp"
"go.clever-cloud.dev/client"
)

//go:embed resource_cellar_test_block.tf
var cellarBlock string

//go:embed provider_test_block.tf
var providerBlock string

var TestProtoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){
"clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()),
}

func TestAccCellar_basic(t *testing.T) {
ctx := context.Background()
cName := fmt.Sprintf("tf-test-cellar-%d", time.Now().UnixMilli())
fullName := fmt.Sprintf("clevercloud_cellar.%s", cName)
rName := fmt.Sprintf("tf-test-cellar-%d", time.Now().UnixMilli())
fullName := fmt.Sprintf("clevercloud_cellar.%s", rName)
cc := client.New(client.WithAutoOauthConfig())
org := os.Getenv("ORGANISATION")
providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String()
cellarBlock := helper.NewRessource(
"clevercloud_cellar",
rName,
helper.SetKeyValues(map[string]any{
"name": rName,
"region": "par",
})).String()

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -43,8 +46,8 @@ func TestAccCellar_basic(t *testing.T) {
},
ProtoV6ProviderFactories: TestProtoV6Provider,
Steps: []resource.TestStep{{
ResourceName: "cellar_" + cName,
Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(cellarBlock, cName, cName),
ResourceName: "cellar_" + rName,
Config: providerBlock + cellarBlock,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^cellar_.*`)),
resource.TestMatchResourceAttr(fullName, "host", regexp.MustCompile(`^.*\.services.clever-cloud.com$`)),
Expand Down
5 changes: 0 additions & 5 deletions pkg/resources/cellar/resource_cellar_test_block.tf

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/resources/java/provider_test_block.tf

This file was deleted.

21 changes: 14 additions & 7 deletions pkg/resources/java/resource_java_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@ import (
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"go.clever-cloud.com/terraform-provider/pkg/helper"
"go.clever-cloud.com/terraform-provider/pkg/provider/impl"
"go.clever-cloud.com/terraform-provider/pkg/tmp"
"go.clever-cloud.dev/client"
)

//go:embed provider_test_block.tf
var providerBlock string

//go:embed resource_java_test_block.tf
var javaBlock string

var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){
"clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()),
}
Expand All @@ -34,6 +29,18 @@ func TestAccJava_basic(t *testing.T) {
fullName := fmt.Sprintf("clevercloud_java_war.%s", rName)
cc := client.New(client.WithAutoOauthConfig())
org := os.Getenv("ORGANISATION")
providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String()
javaBlock := helper.NewRessource(
"clevercloud_java_war",
rName,
helper.SetKeyValues(map[string]any{
"name": rName,
"region": "par",
"min_instance_count": 1,
"max_instance_count": 2,
"smallest_flavor": "XS",
"biggest_flavor": "M",
})).String()

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -45,7 +52,7 @@ func TestAccJava_basic(t *testing.T) {
Steps: []resource.TestStep{{
Destroy: false,
ResourceName: rName,
Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(javaBlock, rName, rName),
Config: providerBlock + javaBlock,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^app_.*$`)),
resource.TestMatchResourceAttr(fullName, "deploy_url", regexp.MustCompile(`^git\+ssh.*\.git$`)),
Expand Down
8 changes: 0 additions & 8 deletions pkg/resources/java/resource_java_test_block.tf

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/resources/materiakv/provider_test_block.tf

This file was deleted.

11 changes: 4 additions & 7 deletions pkg/resources/materiakv/resource_materiakv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@ import (
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"go.clever-cloud.com/terraform-provider/pkg/helper"
"go.clever-cloud.com/terraform-provider/pkg/provider/impl"
"go.clever-cloud.com/terraform-provider/pkg/tmp"
"go.clever-cloud.dev/client"
)

//go:embed resource_materiakv_test_block.tf
var materiakvBlock string

//go:embed provider_test_block.tf
var providerBlock string

var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){
"clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()),
}
Expand All @@ -34,6 +29,8 @@ func TestAccMateriaKV_basic(t *testing.T) {
fullName := fmt.Sprintf("clevercloud_materiadb_kv.%s", rName)
cc := client.New(client.WithAutoOauthConfig())
org := os.Getenv("ORGANISATION")
providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String()
materiakvBlock := helper.NewRessource("clevercloud_materiadb_kv", rName, helper.SetKeyValues(map[string]any{"name": rName})).String()

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down Expand Up @@ -61,7 +58,7 @@ func TestAccMateriaKV_basic(t *testing.T) {
},
Steps: []resource.TestStep{{
ResourceName: rName,
Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(materiakvBlock, rName, rName),
Config: providerBlock + materiakvBlock,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^kv_.*`)),
resource.TestMatchResourceAttr(fullName, "host", regexp.MustCompile(`^.*clever-cloud.com$`)),
Expand Down
3 changes: 0 additions & 3 deletions pkg/resources/materiakv/resource_materiakv_test_block.tf

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/resources/nodejs/provider_test_block.tf

This file was deleted.

45 changes: 34 additions & 11 deletions pkg/resources/nodejs/resource_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,12 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"go.clever-cloud.com/terraform-provider/pkg"
"go.clever-cloud.com/terraform-provider/pkg/helper"
"go.clever-cloud.com/terraform-provider/pkg/provider/impl"
"go.clever-cloud.com/terraform-provider/pkg/tmp"
"go.clever-cloud.dev/client"
)

//go:embed resource_nodejs_test_block.tf
var nodejsBlock string

//go:embed resource_nodejs_test_block2.tf
var nodejsBlock2 string

//go:embed provider_test_block.tf
var providerBlock string

var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){
"clevercloud": providerserver.NewProtocol6WithError(impl.New("test")()),
}
Expand All @@ -41,6 +33,37 @@ func TestAccNodejs_basic(t *testing.T) {
fullName2 := fmt.Sprintf("clevercloud_nodejs.%s", rName2)
cc := client.New(client.WithAutoOauthConfig())
org := os.Getenv("ORGANISATION")
providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String()
nodejsBlock := helper.NewRessource(
"clevercloud_nodejs",
rName,
helper.SetKeyValues(map[string]any{
"name": rName,
"region": "par",
"min_instance_count": 1,
"max_instance_count": 2,
"smallest_flavor": "XS",
"biggest_flavor": "M",
"redirect_https": true,
"sticky_sessions": true,
"app_folder": "./app",
"environment": map[string]any{"MY_KEY": "myval"},
"dependencies": []string{},
}),
helper.SetBlockValues("hooks", map[string]any{"post_build": "echo \"build is OK!\""}),
).String()
nodejsBlock2 := helper.NewRessource(
"clevercloud_nodejs",
rName2,
helper.SetKeyValues(map[string]any{
"name": rName2,
"region": "par",
"min_instance_count": 1,
"max_instance_count": 2,
"smallest_flavor": "XS",
"biggest_flavor": "M",
}),
helper.SetBlockValues("deployment", map[string]any{"repository": "https://github.com/CleverCloud/nodejs-example.git"})).String()

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down Expand Up @@ -68,7 +91,7 @@ func TestAccNodejs_basic(t *testing.T) {
},
Steps: []resource.TestStep{{
ResourceName: rName,
Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(nodejsBlock, rName, rName),
Config: providerBlock + nodejsBlock,
Check: resource.ComposeAggregateTestCheckFunc(
// Test the state for provider's populated values
resource.TestMatchResourceAttr(fullName, "id", regexp.MustCompile(`^app_.*$`)),
Expand Down Expand Up @@ -143,7 +166,7 @@ func TestAccNodejs_basic(t *testing.T) {
),
}, {
ResourceName: rName2,
Config: fmt.Sprintf(providerBlock, org) + fmt.Sprintf(nodejsBlock2, rName2, rName2),
Config: providerBlock + nodejsBlock2,
Check: func(state *terraform.State) error {
id := state.RootModule().Resources[fullName2].Primary.ID

Expand Down
Loading

0 comments on commit 56b1972

Please sign in to comment.