This is an automated email from the ASF dual-hosted git repository. tsato pushed a commit to branch release-1.8.x in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/release-1.8.x by this push: new 39708f8c6 fix(cli): run Integration from GitHub branch 39708f8c6 is described below commit 39708f8c635297295118d67bd99acdf3f1e5f13b Author: Tadayoshi Sato <sato.tadayo...@gmail.com> AuthorDate: Tue Aug 2 20:54:25 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 | 8 ++++++++ pkg/util/util_test.go | 11 +++++++++++ 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/e2e/common/cli/delete_test.go b/e2e/common/cli/delete_test.go index edd83c9e3..c564cbdac 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.8.x/e2e/common/files/yaml.yaml", "-n", ns).Execute()).To(Succeed()) + Expect(Kamel("run", "github:apache/camel-k/e2e/common/files/yaml.yaml?branch=release-1.8.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 9d1784caf..e07d0ec84 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.8.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.8.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 e32d289f5..e048c4ebd 100644 --- a/pkg/cmd/modeline.go +++ b/pkg/cmd/modeline.go @@ -196,7 +196,7 @@ func extractModelineOptions(ctx context.Context, sources []string) ([]modeline.O resolvedSources, err := ResolveSources(ctx, sources, false) 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) ([]modeline.O } 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 2ab6d7624..a53671f43 100644 --- a/pkg/cmd/util_sources.go +++ b/pkg/cmd/util_sources.go @@ -133,8 +133,13 @@ func ResolveSources(ctx context.Context, locations []string, compress bool) ([]S sources = append(sources, answer) } case u.Scheme == githubScheme: + // 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 05cdb80fa..4cab6be1a 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -197,6 +197,14 @@ 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 "" +} func EncodeXML(content interface{}) ([]byte, error) { w := &bytes.Buffer{} w.WriteString(xml.Header) diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index 2bb20add3..c2acf0fd5 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -28,3 +28,14 @@ func TestStringContainsPrefix(t *testing.T) { assert.True(t, StringContainsPrefix(args, "--operator-image=")) assert.False(t, StringContainsPrefix(args, "--olm")) } + +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", "?")) +}