github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/graphql/integrationsys_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/kyma-incubator/compass/components/director/pkg/inputvalidation/inputvalidationtest" 8 "github.com/kyma-incubator/compass/components/director/pkg/str" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestIntegrationSystemInput_Validate_Name(t *testing.T) { 13 testCases := []struct { 14 Name string 15 Value string 16 ExpectedValid bool 17 }{ 18 { 19 Name: "ExpectedValid", 20 Value: "name-123.com", 21 ExpectedValid: true, 22 }, 23 { 24 Name: "Empty string", 25 Value: inputvalidationtest.EmptyString, 26 ExpectedValid: false, 27 }, 28 { 29 Name: "Invalid Upper Case Letters", 30 Value: "Invalid", 31 ExpectedValid: false, 32 }, 33 { 34 Name: "String longer than 37 chars", 35 Value: inputvalidationtest.String37Long, 36 ExpectedValid: false, 37 }, 38 } 39 40 for _, testCase := range testCases { 41 t.Run(testCase.Name, func(t *testing.T) { 42 //GIVEN 43 is := fixValidIntegrationSystem() 44 is.Name = testCase.Value 45 // WHEN 46 err := is.Validate() 47 // THEN 48 if testCase.ExpectedValid { 49 require.NoError(t, err) 50 } else { 51 require.Error(t, err) 52 } 53 }) 54 } 55 } 56 57 func TestIntegrationSystemInput_Validate_Description(t *testing.T) { 58 testCases := []struct { 59 Name string 60 Value *string 61 ExpectedValid bool 62 }{ 63 { 64 Name: "ExpectedValid", 65 Value: str.Ptr("ExpectedValid Value"), 66 ExpectedValid: true, 67 }, 68 { 69 Name: "ExpectedValid nil pointer", 70 Value: nil, 71 ExpectedValid: true, 72 }, 73 { 74 Name: "Empty string", 75 Value: str.Ptr(inputvalidationtest.EmptyString), 76 ExpectedValid: true, 77 }, 78 { 79 Name: "String longer than 2000 chars", 80 Value: str.Ptr(inputvalidationtest.String2001Long), 81 ExpectedValid: false, 82 }, 83 } 84 85 for _, testCase := range testCases { 86 t.Run(testCase.Name, func(t *testing.T) { 87 //GIVEN 88 is := fixValidIntegrationSystem() 89 is.Description = testCase.Value 90 // WHEN 91 err := is.Validate() 92 // THEN 93 if testCase.ExpectedValid { 94 require.NoError(t, err) 95 } else { 96 require.Error(t, err) 97 } 98 }) 99 } 100 } 101 102 func fixValidIntegrationSystem() graphql.IntegrationSystemInput { 103 return graphql.IntegrationSystemInput{ 104 Name: "valid.name", 105 } 106 }