This is an automated email from the ASF dual-hosted git repository.

claudio4j pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 1d81b0376 feat/expanded route parsing capabilities (#5369)
1d81b0376 is described below

commit 1d81b0376c405cf336927b687874b72ac7e738cc
Author: Martin Olšiak <56640450+realmarti...@users.noreply.github.com>
AuthorDate: Tue May 14 12:20:33 2024 +0200

    feat/expanded route parsing capabilities (#5369)
---
 pkg/util/camel/camel_runtime_catalog.go      | 22 +++++++++++++++++++---
 pkg/util/camel/camel_runtime_catalog_test.go | 26 +++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/pkg/util/camel/camel_runtime_catalog.go 
b/pkg/util/camel/camel_runtime_catalog.go
index 00ed0101e..37255f971 100644
--- a/pkg/util/camel/camel_runtime_catalog.go
+++ b/pkg/util/camel/camel_runtime_catalog.go
@@ -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 {
diff --git a/pkg/util/camel/camel_runtime_catalog_test.go 
b/pkg/util/camel/camel_runtime_catalog_test.go
index 02639a293..fef51fd0d 100644
--- a/pkg/util/camel/camel_runtime_catalog_test.go
+++ b/pkg/util/camel/camel_runtime_catalog_test.go
@@ -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},
@@ -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)
+                       }
+               })
+       }
+}

Reply via email to