Skip to content

Commit

Permalink
unindent a test file
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewcummings committed Dec 11, 2023
1 parent e89039a commit 4bf4073
Showing 1 changed file with 153 additions and 154 deletions.
307 changes: 153 additions & 154 deletions cloudtruth/resource_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
},
{
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 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)),
),
},
},
})
}

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", ""),
),
},
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", ""),
),
},
},
})
}

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", ""),
),
},
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", ""),
),
},
},
})
}

func TestAccResourceParameterBasic(t *testing.T) {
createParamName := fmt.Sprintf("Test-%s", uuid.New().String())
resourceName := "basic"
Expand Down Expand Up @@ -183,27 +183,26 @@ 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" {
Expand Down

0 comments on commit 4bf4073

Please sign in to comment.