github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/eventing/converter_test.go (about) 1 package eventing 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/kyma-incubator/compass/components/director/internal/model" 8 "github.com/kyma-incubator/compass/components/director/pkg/graphql" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func Test_RuntimeEventingConfigurationToGraphQL(t *testing.T) { 13 testCases := []struct { 14 Name string 15 Input *model.RuntimeEventingConfiguration 16 Expected *graphql.RuntimeEventingConfiguration 17 }{ 18 { 19 Name: "Valid input model", 20 Input: fixRuntimeEventngCfgWithURL(t, runtimeEventURL), 21 Expected: &graphql.RuntimeEventingConfiguration{ 22 DefaultURL: runtimeEventURL, 23 }, 24 }, { 25 Name: "Nil input model", 26 Input: nil, 27 Expected: nil, 28 }, 29 } 30 31 for _, testCase := range testCases { 32 t.Run(testCase.Name, func(t *testing.T) { 33 eventingCfgGQL := RuntimeEventingConfigurationToGraphQL(testCase.Input) 34 35 require.Equal(t, testCase.Expected, eventingCfgGQL) 36 }) 37 } 38 } 39 40 func Test_ApplicationEventingConfigurationToGraphQL(t *testing.T) { 41 validURL := fixValidURL(t, fmt.Sprintf(eventURLSchema, "test-app")) 42 43 testCases := []struct { 44 Name string 45 Input *model.ApplicationEventingConfiguration 46 Expected *graphql.ApplicationEventingConfiguration 47 }{ 48 { 49 Name: "Valid input model", 50 Input: &model.ApplicationEventingConfiguration{ 51 EventingConfiguration: model.EventingConfiguration{ 52 DefaultURL: validURL, 53 }, 54 }, 55 Expected: &graphql.ApplicationEventingConfiguration{ 56 DefaultURL: validURL.String(), 57 }, 58 }, { 59 Name: "Nil input model", 60 Input: nil, 61 Expected: nil, 62 }, 63 } 64 65 for _, testCase := range testCases { 66 t.Run(testCase.Name, func(t *testing.T) { 67 eventingCfgGQL := ApplicationEventingConfigurationToGraphQL(testCase.Input) 68 69 require.Equal(t, testCase.Expected, eventingCfgGQL) 70 }) 71 } 72 }