Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(4893) YAML DSL route configuration support #5369

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions pkg/util/camel/camel_runtime_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,26 @@ func (c *RuntimeCatalog) VisitSchemes(visitor func(string, v1.CamelScheme) bool)

// DecodeComponent parses the given URI and return a camel artifact and a scheme.
func (c *RuntimeCatalog) DecodeComponent(uri string) (*v1.CamelArtifact, *v1.CamelScheme) {
uriSplit := strings.SplitN(uri, ":", 2)
if len(uriSplit) < 2 {
return nil, nil

var uriSplit []string

// Decode URI using formats http://my-site/test?param=value or log:info
if strings.Contains(uri, ":") {
uriSplit = strings.SplitN(uri, ":", 2)
if len(uriSplit) < 2 {
return nil, nil
}
} else {
if strings.Contains(uri, "?") {
uriSplit = strings.SplitN(uri, "?", 2)
if len(uriSplit) < 2 {
return nil, nil
}
} else {
uriSplit = append(uriSplit, uri)
}
}

uriStart := uriSplit[0]
var schemeRef *v1.CamelScheme
if scheme, ok := c.GetScheme(uriStart); ok {
Expand Down
26 changes: 25 additions & 1 deletion pkg/util/camel/camel_runtime_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ func TestIsResolvable(t *testing.T) {
expected bool
}{
// static dependencies
{desc: "Basic static dependency single component", uri: "log", expected: true},
{desc: "Basic static dependency", uri: "log:info", expected: true},
{desc: "Basic static dependency with path and param", uri: "http://my-site/test?param=value", expected: true},
{desc: "Basic static dependency with path and param placeholder", uri: "http://my-site/test?{{params}}", expected: true},
{desc: "Basic static dependency with path placeholder and param", uri: "http://my-site/{{path}}?key=val", expected: true},

{desc: "Basic static dependency with path placeholder and name", uri: "direct?name=val", expected: true},
// placeholders
{desc: "Basic", uri: "{{url}}", expected: false},
{desc: "With query param placeholder", uri: "{{url}}?authMethod={{authMethod}}", expected: false},
Expand All @@ -81,3 +82,26 @@ func TestIsResolvable(t *testing.T) {
})
}
}

func TestDecodeComponent(t *testing.T) {
catalog, err := DefaultCatalog()
require.NoError(t, err)

testCases := []struct {
desc string
uri string
expectedID string
}{
{desc: "Basic static dependency", uri: "direct", expectedID: "direct"},
{desc: "Basic static dependency", uri: "log:info", expectedID: "log"},
{desc: "Basic static dependency witch path and name", uri: "direct?name=route", expectedID: "direct"},
{desc: "Basic static dependency with path and param placeholder", uri: "http://my-site/test?{{params}}", expectedID: "http"},
}
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
if _, gotScheme := catalog.DecodeComponent(testCase.uri); gotScheme.ID != testCase.expectedID {
t.Errorf("DecodeComponent(%v) = %v, want %v", testCase.uri, gotScheme.ID, testCase.expectedID)
}
})
}
}