github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/validation/list_test.go (about) 1 package validation 2 3 import ( 4 "testing" 5 ) 6 7 func TestValidationListOfUniqueStrings(t *testing.T) { 8 cases := map[string]struct { 9 Value interface{} 10 Error bool 11 }{ 12 "NotList": { 13 Value: "the list is a lie", 14 Error: true, 15 }, 16 "NotListOfString": { 17 Value: []interface{}{"seven", 7}, 18 Error: true, 19 }, 20 "NonUniqueStrings": { 21 Value: []interface{}{"kt", "is", "kt"}, 22 Error: true, 23 }, 24 "UniqueStrings": { 25 Value: []interface{}{"thanks", "for", "all", "the", "fish"}, 26 Error: false, 27 }, 28 } 29 30 for tn, tc := range cases { 31 t.Run(tn, func(t *testing.T) { 32 _, errors := ListOfUniqueStrings(tc.Value, tn) 33 34 if len(errors) > 0 && !tc.Error { 35 t.Errorf("ListOfUniqueStrings(%s) produced an unexpected error", tc.Value) 36 } else if len(errors) == 0 && tc.Error { 37 t.Errorf("ListOfUniqueStrings(%s) did not error", tc.Value) 38 } 39 }) 40 } 41 }