Skip to content

Commit

Permalink
Handle new rules for disallowing secret -> non-secret changes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewcummings committed Sep 22, 2023
1 parent 0d11a3d commit a4eba0b
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions cloudtruth/resource_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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"
min, max := 1, 10
minVal, maxVal := 1, 10
createRegEx := ".*"
updateMin, updateMax := 0, 11
updateRegEx := `123.*`
Expand All @@ -23,39 +23,39 @@ func TestAccResourceParameterWithRules(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccResourceParameterCreateStringWithRules(accTestProject, stringResourceName, createStringParamName, paramDesc,
false, min, max, createRegEx),
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(min)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "max", fmt.Sprint(max)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "minVal", fmt.Sprint(minVal)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "maxVal", fmt.Sprint(maxVal)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex", createRegEx),
),
},
{
Config: testAccResourceParameterCreateStringWithRules(accTestProject, stringResourceName, createStringParamName, updateParamDesc,
true, updateMin, updateMax, updateRegEx),
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(true)),
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), "secret", fmt.Sprint(false)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "minVal", fmt.Sprint(updateMin)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "maxVal", fmt.Sprint(updateMax)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", stringResourceName), "regex", updateRegEx),
),
},
{
Config: testAccResourceParameterCreateIntegerWithRules(accTestProject, intResourceName, createIntegerParamName, paramDesc,
false, min, max),
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(min)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max", fmt.Sprint(max)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "minVal", fmt.Sprint(minVal)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "maxVal", fmt.Sprint(maxVal)),
),
},
{
Expand All @@ -66,8 +66,8 @@ func TestAccResourceParameterWithRules(t *testing.T) {
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)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "minVal", fmt.Sprint(updateMin)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "maxVal", fmt.Sprint(updateMax)),
),
},
},
Expand Down Expand Up @@ -112,33 +112,33 @@ func TestAccResourceStringParameterAddRemoveRule(t *testing.T) {
func TestAccResourceIntParameterAddRemoveRule(t *testing.T) {
createIntParamName := fmt.Sprintf("Test-Int-%s", uuid.New().String())
intResourceName := "int_with_rule"
min, max := 0, 1000
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, min, max),
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(min)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max", fmt.Sprint(max)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "minVal", fmt.Sprint(minVal)),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "maxVal", fmt.Sprint(maxVal)),
),
},
{ // Remove the max and min rules, their corresponding properties should be set to ""
{ // Remove the maxVal and minVal 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), "minVal", ""),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "maxVal", ""),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "min_id", ""),
resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_parameter.%s", intResourceName), "max_id", ""),
),
Expand Down

0 comments on commit a4eba0b

Please sign in to comment.