Skip to content

Commit b73052f

Browse files
author
Ivan De Marino
authored
Revert "Extra TestCheckFuncs to check attribute's string length (#893)" (#896)
This reverts commit fe75bb1.
1 parent db02baa commit b73052f

File tree

3 files changed

+0
-114
lines changed

3 files changed

+0
-114
lines changed

.changelog/893.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

helper/resource/testing.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,36 +1033,6 @@ func testCheckResourceAttrPair(isFirst *terraform.InstanceState, nameFirst strin
10331033
return nil
10341034
}
10351035

1036-
// TestRangeLengthResourceAttr is a TestCheckFunc which checks that the length of the value
1037-
// in state for the given name/key is within an expected (closed) range.
1038-
func TestRangeLengthResourceAttr(name, key string, min, max int) TestCheckFunc {
1039-
return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error {
1040-
is, err := primaryInstanceState(s, name)
1041-
if err != nil {
1042-
return err
1043-
}
1044-
1045-
valLen := len(is.Attributes[key])
1046-
if valLen < min || valLen > max {
1047-
return fmt.Errorf(
1048-
"%s: Attribute '%s' length is %d, which is not within the expected closed range [%d, %d]",
1049-
name,
1050-
key,
1051-
valLen,
1052-
min,
1053-
max)
1054-
}
1055-
1056-
return nil
1057-
})
1058-
}
1059-
1060-
// TestMatchLengthResourceAttr is a TestCheckFunc which checks that the length of the value
1061-
// in state for the given name/key matches a specific length.
1062-
func TestMatchLengthResourceAttr(name, key string, length int) TestCheckFunc {
1063-
return TestRangeLengthResourceAttr(name, key, length, length)
1064-
}
1065-
10661036
// TestCheckOutput checks an output in the Terraform configuration
10671037
func TestCheckOutput(name, value string) TestCheckFunc {
10681038
return func(s *terraform.State) error {

helper/resource/testing_test.go

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -874,87 +874,6 @@ func TestCheckResourceAttr_empty(t *testing.T) {
874874
}
875875
}
876876

877-
func TestTestRangeLengthResourceAttr(t *testing.T) {
878-
resName := "test_resource"
879-
resKey := "test_key"
880-
resVal := "test_value"
881-
882-
s := terraform.NewState()
883-
s.AddModuleState(&terraform.ModuleState{
884-
Path: []string{"root"},
885-
Resources: map[string]*terraform.ResourceState{
886-
resName: {
887-
Primary: &terraform.InstanceState{
888-
Attributes: map[string]string{
889-
resKey: resVal,
890-
},
891-
},
892-
},
893-
},
894-
})
895-
896-
t.Run("in_range", func(t *testing.T) {
897-
check := TestRangeLengthResourceAttr(resName, resKey, 2, 20)
898-
if err := check(s); err != nil {
899-
t.Fatal(err)
900-
}
901-
})
902-
t.Run("out_of_range", func(t *testing.T) {
903-
check := TestRangeLengthResourceAttr(resName, resKey, 20, 40)
904-
if err := check(s); err == nil {
905-
t.Fatal(fmt.Errorf("failed to detect attribute '%s.%s' value '%s' length is out of range",
906-
resName,
907-
resKey,
908-
resVal))
909-
}
910-
})
911-
}
912-
913-
func TestTestMatchLengthResourceAttr(t *testing.T) {
914-
resName := "test_resource"
915-
resKey := "test_key"
916-
resVal := "test_value"
917-
918-
s := terraform.NewState()
919-
s.AddModuleState(&terraform.ModuleState{
920-
Path: []string{"root"},
921-
Resources: map[string]*terraform.ResourceState{
922-
resName: {
923-
Primary: &terraform.InstanceState{
924-
Attributes: map[string]string{
925-
resKey: resVal,
926-
},
927-
},
928-
},
929-
},
930-
})
931-
932-
t.Run("matches_length", func(t *testing.T) {
933-
check := TestMatchLengthResourceAttr(resName, resKey, 10)
934-
if err := check(s); err != nil {
935-
t.Fatal(err)
936-
}
937-
})
938-
t.Run("too_short", func(t *testing.T) {
939-
check := TestMatchLengthResourceAttr(resName, resKey, 11)
940-
if err := check(s); err == nil {
941-
t.Fatal(fmt.Errorf("failed to detect attribute '%s.%s' value '%s' is too short",
942-
resName,
943-
resKey,
944-
resVal))
945-
}
946-
})
947-
t.Run("too_long", func(t *testing.T) {
948-
check := TestMatchLengthResourceAttr(resName, resKey, 2)
949-
if err := check(s); err == nil {
950-
t.Fatal(fmt.Errorf("failed to detect attribute '%s.%s' value '%s' is too long",
951-
resName,
952-
resKey,
953-
resVal))
954-
}
955-
})
956-
}
957-
958877
func TestCheckNoResourceAttr_empty(t *testing.T) {
959878
s := terraform.NewState()
960879
s.AddModuleState(&terraform.ModuleState{

0 commit comments

Comments
 (0)