github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/eventing_test.go (about) 1 package model_test 2 3 import ( 4 "errors" 5 "net/url" 6 "testing" 7 8 "github.com/kyma-incubator/compass/components/director/internal/model" 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestNewRuntimeEventingConfiguration(t *testing.T) { 14 testCases := []struct { 15 Name string 16 RawURL string 17 ExpectedError error 18 }{ 19 { 20 Name: "Valid RuntimeEventing", 21 RawURL: "https://eventing.runtime", 22 }, 23 { 24 Name: "Valid RuntimeEventing - empty rawURL", 25 RawURL: "", 26 }, 27 { 28 Name: "Invalid rawURL", 29 RawURL: "::", 30 ExpectedError: errors.New("parse \"::\": missing protocol scheme"), 31 }, 32 } 33 34 for _, testCase := range testCases { 35 t.Run(testCase.Name, func(t *testing.T) { 36 // WHEN 37 config, err := model.NewRuntimeEventingConfiguration(testCase.RawURL) 38 39 // THEN 40 if testCase.ExpectedError == nil { 41 require.NotNil(t, config) 42 require.Equal(t, testCase.RawURL, config.DefaultURL.String()) 43 } else { 44 require.Error(t, err) 45 assert.EqualError(t, err, testCase.ExpectedError.Error()) 46 } 47 }) 48 } 49 } 50 51 func TestNewApplicationEventingConfiguration(t *testing.T) { 52 validURL, err := url.Parse("https://eventing.runtime") 53 require.NoError(t, err) 54 require.NotNil(t, validURL) 55 56 t.Run("Valid", func(t *testing.T) { 57 // GIVEN 58 expectedEventURL := "https://eventing.runtime/app.name-super/v1/events" 59 60 // WHEN 61 config, err := model.NewApplicationEventingConfiguration(*validURL, "app.name-super") 62 63 // THEN 64 require.NoError(t, err) 65 require.NotNil(t, config) 66 67 assert.Equal(t, expectedEventURL, config.DefaultURL.String()) 68 }) 69 70 t.Run("Valid - empty runtimeEventURL", func(t *testing.T) { 71 // GIVEN 72 emptyURL, err := url.Parse("") 73 require.NoError(t, err) 74 require.NotNil(t, emptyURL) 75 76 // WHEN 77 config, err := model.NewApplicationEventingConfiguration(*emptyURL, "") 78 79 // THEN 80 require.NoError(t, err) 81 require.NotNil(t, config) 82 assert.Equal(t, "", config.DefaultURL.String()) 83 }) 84 } 85 86 func TestNewEmptyApplicationEventingConfig(t *testing.T) { 87 // WHEN 88 config, err := model.NewEmptyApplicationEventingConfig() 89 // THEN 90 require.NoError(t, err) 91 assert.Equal(t, "", config.DefaultURL.String()) 92 }