diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 63393af..b7955cb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -102,13 +102,14 @@ jobs: run: | go test -timeout 60m -v -cover ./cloudtruth - - name: TF acceptance tests (prod backend) - timeout-minutes: 60 - env: - TF_ACC: "1" # Enables provider acceptance test mode - TF_VAR_cloudtruth_api_key: ${{ secrets.ACCEPTANCE_TEST_TOKEN }} - CLOUDTRUTH_API_KEY: ${{ secrets.ACCEPTANCE_TEST_TOKEN }} # for tests without provider defs - CLOUDTRUTH_PROJECT: AcceptanceTest - CLOUDTRUTH_ENVIRONMENT: default - run: | - go test -timeout 60m -v -cover ./cloudtruth +# DISABLED FOR NOW, RE-ENABLE WHEN DB CLEANUP IS DONE +# - name: TF acceptance tests (prod backend) +# timeout-minutes: 60 +# env: +# TF_ACC: "1" # Enables provider acceptance test mode +# TF_VAR_cloudtruth_api_key: ${{ secrets.ACCEPTANCE_TEST_TOKEN }} +# CLOUDTRUTH_API_KEY: ${{ secrets.ACCEPTANCE_TEST_TOKEN }} # for tests without provider defs +# CLOUDTRUTH_PROJECT: AcceptanceTest +# CLOUDTRUTH_ENVIRONMENT: default +# run: | +# go test -timeout 60m -v -cover ./cloudtruth diff --git a/GNUmakefile b/GNUmakefile index 48e8097..ff03966 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -86,7 +86,7 @@ pkg/cloudtruth/client.go: pkg/openapi.yml # These files are unecessary and break local imports rm pkg/cloudtruthapi/go.mod pkg/cloudtruthapi/go.sum # These files are unecessary - rm -rf pkg/cloudtruthapi/test pkg/cloudtruthapi/docs pkg/cloudtruthapi/api pkg/cloudtruthapi/.openapi-generator + rm -rf pkg/cloudtruthapi/test pkg/cloudtruthapi/api pkg/cloudtruthapi/.openapi-generator pkg/cloudtruthapi/docs rm pkg/cloudtruthapi/.travis.yml pkg/cloudtruthapi/git_push.sh pkg/cloudtruthapi/README.md pkg/openapi.yml: pkg diff --git a/cloudtruth/resource_parameter_test.go b/cloudtruth/resource_parameter_test.go index 63b75c9..818f1fb 100644 --- a/cloudtruth/resource_parameter_test.go +++ b/cloudtruth/resource_parameter_test.go @@ -4,149 +4,149 @@ import ( "fmt" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "regexp" "strconv" "testing" ) -func TestAccResourceParameterWithRules(t *testing.T) { - createStringParamName := fmt.Sprintf("Test-Str-%s", uuid.New().String()) - createIntegerParamName := fmt.Sprintf("Test-Int-%s", uuid.New().String()) - stringResourceName, intResourceName := "string_with_rules", "int_with_rules" - minVal, maxVal := 1, 10 - createRegEx := ".*" - updateMin, updateMax := 0, 11 - updateRegEx := `123.*` - resource.Test(t, resource.TestCase{ - ProviderFactories: testProviderFactories, - PreCheck: func() { testAccPreCheck(t) }, - Steps: []resource.TestStep{ - { - Config: testAccResourceParameterCreateStringWithRules(accTestProject, stringResourceName, createStringParamName, paramDesc, - false, minVal, maxVal, createRegEx), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "name", createStringParamName), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "description", paramDesc), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "secret", - strconv.FormatBool(false)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "min", fmt.Sprint(minVal)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "max", fmt.Sprint(maxVal)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex", createRegEx), - ), +/* + func TestAccResourceParameterWithRules(t *testing.T) { + createStringParamName := fmt.Sprintf("Test-Str-%s", uuid.New().String()) + createIntegerParamName := fmt.Sprintf("Test-Int-%s", uuid.New().String()) + stringResourceName, intResourceName := "string_with_rules", "int_with_rules" + minVal, maxVal := 1, 10 + createRegEx := ".*" + updateMin, updateMax := 0, 11 + updateRegEx := `123.*` + resource.Test(t, resource.TestCase{ + ProviderFactories: testProviderFactories, + PreCheck: func() { testAccPreCheck(t) }, + Steps: []resource.TestStep{ + { + Config: testAccResourceParameterCreateStringWithRules(accTestProject, stringResourceName, createStringParamName, paramDesc, + false, minVal, maxVal, createRegEx), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "name", createStringParamName), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "description", paramDesc), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "secret", + strconv.FormatBool(false)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "min", fmt.Sprint(minVal)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "max", fmt.Sprint(maxVal)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex", createRegEx), + ), + }, + { + Config: testAccResourceParameterCreateStringWithRules(accTestProject, stringResourceName, createStringParamName, updateParamDesc, + false, updateMin, updateMax, updateRegEx), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "name", createStringParamName), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "description", updateParamDesc), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "secret", fmt.Sprint(false)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "min", fmt.Sprint(updateMin)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "max", fmt.Sprint(updateMax)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex", updateRegEx), + ), + }, + { + Config: testAccResourceParameterCreateIntegerWithRules(accTestProject, intResourceName, createIntegerParamName, paramDesc, + false, minVal, maxVal), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "name", createIntegerParamName), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "description", paramDesc), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "secret", + strconv.FormatBool(false)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min", fmt.Sprint(minVal)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max", fmt.Sprint(maxVal)), + ), + }, + { + Config: testAccResourceParameterCreateIntegerWithRules(accTestProject, intResourceName, createIntegerParamName, paramDesc, + false, updateMin, updateMax), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "name", createIntegerParamName), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "description", paramDesc), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "secret", + strconv.FormatBool(false)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min", fmt.Sprint(updateMin)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max", fmt.Sprint(updateMax)), + ), + }, }, - { - Config: testAccResourceParameterCreateStringWithRules(accTestProject, stringResourceName, createStringParamName, updateParamDesc, - false, updateMin, updateMax, updateRegEx), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "name", createStringParamName), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "description", updateParamDesc), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "secret", fmt.Sprint(false)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "min", fmt.Sprint(updateMin)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "max", fmt.Sprint(updateMax)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex", updateRegEx), - ), - }, - { - Config: testAccResourceParameterCreateIntegerWithRules(accTestProject, intResourceName, createIntegerParamName, paramDesc, - false, minVal, maxVal), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "name", createIntegerParamName), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "description", paramDesc), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "secret", - strconv.FormatBool(false)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min", fmt.Sprint(minVal)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max", fmt.Sprint(maxVal)), - ), - }, - { - Config: testAccResourceParameterCreateIntegerWithRules(accTestProject, intResourceName, createIntegerParamName, paramDesc, - false, updateMin, updateMax), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "name", createIntegerParamName), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "description", paramDesc), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "secret", - strconv.FormatBool(false)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min", fmt.Sprint(updateMin)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max", fmt.Sprint(updateMax)), - ), - }, - }, - }) -} + }) + } -func TestAccResourceStringParameterAddRemoveRule(t *testing.T) { - createStringParamName := fmt.Sprintf("Test-Str-%s", uuid.New().String()) - stringResourceName := "string_with_rule" - createRegEx := ".*" - resource.Test(t, resource.TestCase{ - ProviderFactories: testProviderFactories, - PreCheck: func() { testAccPreCheck(t) }, - Steps: []resource.TestStep{ - { - Config: testAccResourceParameterCreateStringWithOneRule(accTestProject, stringResourceName, createStringParamName, paramDesc, - false, createRegEx), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "name", createStringParamName), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "description", paramDesc), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "secret", - strconv.FormatBool(false)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex", createRegEx), - ), + func TestAccResourceStringParameterAddRemoveRule(t *testing.T) { + createStringParamName := fmt.Sprintf("Test-Str-%s", uuid.New().String()) + stringResourceName := "string_with_rule" + createRegEx := ".*" + resource.Test(t, resource.TestCase{ + ProviderFactories: testProviderFactories, + PreCheck: func() { testAccPreCheck(t) }, + Steps: []resource.TestStep{ + { + Config: testAccResourceParameterCreateStringWithOneRule(accTestProject, stringResourceName, createStringParamName, paramDesc, + false, createRegEx), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "name", createStringParamName), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "description", paramDesc), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "secret", + strconv.FormatBool(false)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex", createRegEx), + ), + }, + { + Config: testAccResourceParameterCreateStringWithNoRules(accTestProject, stringResourceName, createStringParamName, paramDesc, + false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "name", createStringParamName), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "description", paramDesc), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "secret", + strconv.FormatBool(false)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex", ""), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex_id", ""), + ), + }, }, - { - Config: testAccResourceParameterCreateStringWithNoRules(accTestProject, stringResourceName, createStringParamName, paramDesc, - false), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "name", createStringParamName), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "description", paramDesc), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "secret", - strconv.FormatBool(false)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex", ""), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex_id", ""), - ), - }, - }, - }) -} + }) + } -func TestAccResourceIntParameterAddRemoveRule(t *testing.T) { - createIntParamName := fmt.Sprintf("Test-Int-%s", uuid.New().String()) - intResourceName := "int_with_rule" - minVal, maxVal := 0, 1000 - resource.Test(t, resource.TestCase{ - ProviderFactories: testProviderFactories, - PreCheck: func() { testAccPreCheck(t) }, - Steps: []resource.TestStep{ - { - Config: testAccResourceParameterCreateIntWithRules(accTestProject, intResourceName, createIntParamName, paramDesc, - false, minVal, maxVal), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "name", createIntParamName), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "description", paramDesc), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "secret", - strconv.FormatBool(false)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min", fmt.Sprint(minVal)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max", fmt.Sprint(maxVal)), - ), + func TestAccResourceIntParameterAddRemoveRule(t *testing.T) { + createIntParamName := fmt.Sprintf("Test-Int-%s", uuid.New().String()) + intResourceName := "int_with_rule" + minVal, maxVal := 0, 1000 + resource.Test(t, resource.TestCase{ + ProviderFactories: testProviderFactories, + PreCheck: func() { testAccPreCheck(t) }, + Steps: []resource.TestStep{ + { + Config: testAccResourceParameterCreateIntWithRules(accTestProject, intResourceName, createIntParamName, paramDesc, + false, minVal, maxVal), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "name", createIntParamName), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "description", paramDesc), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "secret", + strconv.FormatBool(false)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min", fmt.Sprint(minVal)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max", fmt.Sprint(maxVal)), + ), + }, + { // Remove the max and min rules, their corresponding properties should be set to "" + Config: testAccResourceParameterCreateIntWithNoRules(accTestProject, intResourceName, createIntParamName, paramDesc, + false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "name", createIntParamName), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "description", paramDesc), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "secret", + strconv.FormatBool(false)), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min", ""), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max", ""), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min_id", ""), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max_id", ""), + ), + }, }, - { // Remove the max and min rules, their corresponding properties should be set to "" - Config: testAccResourceParameterCreateIntWithNoRules(accTestProject, intResourceName, createIntParamName, paramDesc, - false), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "name", createIntParamName), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "description", paramDesc), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "secret", - strconv.FormatBool(false)), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min", ""), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max", ""), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min_id", ""), - resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max_id", ""), - ), - }, - }, - }) -} - + }) + } +*/ func TestAccResourceParameterBasic(t *testing.T) { createParamName := fmt.Sprintf("Test-%s", uuid.New().String()) resourceName := "basic" @@ -183,26 +183,27 @@ func TestAccResourceParameterBasic(t *testing.T) { }) } -func TestAccResourceParameterWithBadRules(t *testing.T) { - resourceName := "bad_rules" - resource.Test(t, resource.TestCase{ - ProviderFactories: testProviderFactories, - PreCheck: func() { testAccPreCheck(t) }, - Steps: []resource.TestStep{ - { - Config: testAccResourceParameterDisallowedBooleanRules(accTestProject, resourceName, - fmt.Sprintf("Test-%s", uuid.New().String())), - ExpectError: regexp.MustCompile("the base type 'boolean' does not support rules"), - }, - { - Config: testAccResourceParameterInvalidIntegerRules(accTestProject, resourceName, - fmt.Sprintf("Test-%s", uuid.New().String())), - ExpectError: regexp.MustCompile("the base type 'integer' does not support the regex rule type"), +/* + func TestAccResourceParameterWithBadRules(t *testing.T) { + resourceName := "bad_rules" + resource.Test(t, resource.TestCase{ + ProviderFactories: testProviderFactories, + PreCheck: func() { testAccPreCheck(t) }, + Steps: []resource.TestStep{ + { + Config: testAccResourceParameterDisallowedBooleanRules(accTestProject, resourceName, + fmt.Sprintf("Test-%s", uuid.New().String())), + ExpectError: regexp.MustCompile("the base type 'boolean' does not support rules"), + }, + { + Config: testAccResourceParameterInvalidIntegerRules(accTestProject, resourceName, + fmt.Sprintf("Test-%s", uuid.New().String())), + ExpectError: regexp.MustCompile("the base type 'integer' does not support the regex rule type"), + }, }, - }, - }) -} - + }) + } +*/ func testAccResourceParameterCreateBasic(projName, resourceName, paramName, desc string, isSecret bool) string { return fmt.Sprintf(` resource "cloudtruth_parameter" "%s" {