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

tsato pushed a commit to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit ce1b35d4948b12f707dfaa1e9975ab6c6c40bb3e
Author: Tadayoshi Sato <[email protected]>
AuthorDate: Tue Aug 2 20:52:21 2022 +0900

    fix(cli): run Integration from GitHub branch
    
    Fix #3475
---
 e2e/common/cli/delete_test.go |  2 +-
 e2e/common/cli/run_test.go    |  2 +-
 pkg/cmd/modeline.go           |  4 ++--
 pkg/cmd/util_sources.go       |  7 ++++++-
 pkg/util/util.go              |  9 +++++++++
 pkg/util/util_test.go         | 10 ++++++++++
 6 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/e2e/common/cli/delete_test.go b/e2e/common/cli/delete_test.go
index 679198629..35321352e 100644
--- a/e2e/common/cli/delete_test.go
+++ b/e2e/common/cli/delete_test.go
@@ -52,7 +52,7 @@ func TestKamelCLIDelete(t *testing.T) {
                })
 
                t.Run("delete integration from csv", func(t *testing.T) {
-                       Expect(Kamel("run", 
"github:apache/camel-k/release-1.9.x/e2e/common/cli/files/yaml.yaml", "-n", 
ns).Execute()).To(Succeed())
+                       Expect(Kamel("run", 
"github:apache/camel-k/e2e/common/cli/files/yaml.yaml?branch=release-1.9.x", 
"-n", ns).Execute()).To(Succeed())
                        Eventually(IntegrationPodPhase(ns, "yaml"), 
TestTimeoutMedium).Should(Equal(corev1.PodRunning))
                        Expect(Kamel("delete", "yaml", "-n", 
ns).Execute()).To(Succeed())
                        Eventually(Integration(ns, "yaml")).Should(BeNil())
diff --git a/e2e/common/cli/run_test.go b/e2e/common/cli/run_test.go
index 557d81bd7..84629584d 100644
--- a/e2e/common/cli/run_test.go
+++ b/e2e/common/cli/run_test.go
@@ -40,7 +40,7 @@ func TestRunExamplesFromGitHub(t *testing.T) {
                Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
 
                t.Run("run java from GitHub", func(t *testing.T) {
-                       Expect(Kamel("run", "-n", ns, 
"github:apache/camel-k/release-1.9.x/e2e/common/files/Java.java").Execute()).To(Succeed())
+                       Expect(Kamel("run", "-n", ns, 
"github:apache/camel-k/e2e/common/files/Java.java?branch=release-1.9.x").Execute()).To(Succeed())
                        Eventually(IntegrationPodPhase(ns, "java"), 
TestTimeoutMedium).Should(Equal(corev1.PodRunning))
                        Eventually(IntegrationConditionStatus(ns, "java", 
v1.IntegrationConditionReady), 
TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
                        Eventually(IntegrationLogs(ns, "java"), 
TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
diff --git a/pkg/cmd/modeline.go b/pkg/cmd/modeline.go
index 1b7ed9e1f..07e88155b 100644
--- a/pkg/cmd/modeline.go
+++ b/pkg/cmd/modeline.go
@@ -196,7 +196,7 @@ func extractModelineOptions(ctx context.Context, sources 
[]string, cmd *cobra.Co
 
        resolvedSources, err := ResolveSources(ctx, sources, false, cmd)
        if err != nil {
-               return opts, errors.Wrap(err, "cannot read sources")
+               return opts, errors.Wrap(err, "failed to resolve sources")
        }
 
        for _, resolvedSource := range resolvedSources {
@@ -217,7 +217,7 @@ func extractModelineOptions(ctx context.Context, sources 
[]string, cmd *cobra.Co
 }
 
 func extractModelineOptionsFromSource(resolvedSource Source) 
([]modeline.Option, error) {
-       ops, err := modeline.Parse(resolvedSource.Location, 
resolvedSource.Content)
+       ops, err := modeline.Parse(resolvedSource.Name, resolvedSource.Content)
        if err != nil {
                return ops, errors.Wrapf(err, "cannot process file %s", 
resolvedSource.Location)
        }
diff --git a/pkg/cmd/util_sources.go b/pkg/cmd/util_sources.go
index 1c6563886..b15e66912 100644
--- a/pkg/cmd/util_sources.go
+++ b/pkg/cmd/util_sources.go
@@ -191,8 +191,13 @@ func resolveLocalSource(location string, compress bool) 
(Source, error) {
 
 // resolveSource resolves a source using the content provider function.
 func resolveSource(location string, compress bool, loadContent func() ([]byte, 
error)) (Source, error) {
+       // strip query part from location if any
+       locPath := util.SubstringBefore(location, "?")
+       if locPath == "" {
+               locPath = location
+       }
        answer := Source{
-               Name:     path.Base(location),
+               Name:     path.Base(locPath),
                Origin:   location,
                Location: location,
                Compress: compress,
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 5143c6830..e0a343c57 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -199,6 +199,15 @@ func SubstringFrom(s string, substr string) string {
        return ""
 }
 
+func SubstringBefore(s string, substr string) string {
+       index := strings.LastIndex(s, substr)
+       if index != -1 {
+               return s[:index]
+       }
+
+       return ""
+}
+
 const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
 const (
diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go
index adc6beb09..597308d25 100644
--- a/pkg/util/util_test.go
+++ b/pkg/util/util_test.go
@@ -32,5 +32,15 @@ func TestStringContainsPrefix(t *testing.T) {
 func TestRandomString(t *testing.T) {
        assert.Equal(t, 10, len(RandomString(10)))
        assert.NotEqual(t, RandomString(10), RandomString(10))
+}
+
+func TestSubstringFrom(t *testing.T) {
+       assert.Equal(t, "/bbb/ccc", SubstringFrom("aaa/bbb/ccc", "/"))
+       assert.Empty(t, SubstringFrom("aaa/bbb/ccc", "?"))
+}
 
+func TestSubstringBefore(t *testing.T) {
+       assert.Equal(t, "aaa/bbb", SubstringBefore("aaa/bbb/ccc", "/"))
+       assert.Equal(t, "aaa/bbb", SubstringBefore("aaa/bbb?ccc=ddd", "?"))
+       assert.Empty(t, SubstringBefore("aaa/bbb/ccc", "?"))
 }

Reply via email to