github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/graphql/asa_selector_validation_test.go (about) 1 package graphql_test 2 3 import ( 4 "testing" 5 6 "github.com/kyma-incubator/compass/components/director/pkg/graphql" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestLabelSelectorInput_Validate_Key(t *testing.T) { 11 testCases := []struct { 12 Name string 13 Key string 14 ExpectedValid bool 15 }{ 16 { 17 Name: "Valid", 18 Key: "global_subaccount_id", 19 ExpectedValid: true, 20 }, 21 { 22 Name: "Invalid", 23 Key: "key", 24 ExpectedValid: false, 25 }, 26 } 27 28 for _, testCase := range testCases { 29 t.Run(testCase.Name, func(t *testing.T) { 30 //GIVEN 31 fr := fixValidLabelSelector() 32 fr.Key = testCase.Key 33 // WHEN 34 err := fr.Validate() 35 // THEN 36 if testCase.ExpectedValid { 37 require.NoError(t, err) 38 } else { 39 require.Error(t, err) 40 } 41 }) 42 } 43 } 44 45 func fixValidLabelSelector() graphql.LabelSelectorInput { 46 return graphql.LabelSelectorInput{ 47 Key: "global_subaccount_id", 48 Value: "value", 49 } 50 }