diff --git a/e2e/namespace/install/cli/run_test.go b/e2e/namespace/install/cli/run_test.go index 14922aef06..4bca39e8a8 100644 --- a/e2e/namespace/install/cli/run_test.go +++ b/e2e/namespace/install/cli/run_test.go @@ -43,26 +43,43 @@ func TestKamelCLIRun(t *testing.T) { t.Run("Examples from GitHub", func(t *testing.T) { t.Run("Java", func(t *testing.T) { - Expect(KamelRunWithID(operatorID, ns, "github:apache/camel-k/e2e/namespace/install/files/Java.java").Execute()).To(Succeed()) + Expect(KamelRunWithID(operatorID, ns, + "github:apache/camel-k/e2e/namespace/install/files/Java.java").Execute()).To(Succeed()) Eventually(IntegrationPodPhase(ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort). + Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Java (RAW)", func(t *testing.T) { - Expect(KamelRunWithID(operatorID, ns, "https://raw.githubusercontent.com/apache/camel-k/main/e2e/namespace/install/files/Java.java").Execute()).To(Succeed()) + Expect(KamelRunWithID(operatorID, ns, + "https://raw.githubusercontent.com/apache/camel-k/main/e2e/namespace/install/files/Java.java").Execute()). + To(Succeed()) Eventually(IntegrationPodPhase(ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort). + Should(Equal(corev1.ConditionTrue)) + Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) + }) + + t.Run("Java (branch)", func(t *testing.T) { + Expect(KamelRunWithID(operatorID, ns, + "github:apache/camel-k/e2e/namespace/install/files/Java.java?branch=main").Execute()).To(Succeed()) + Eventually(IntegrationPodPhase(ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort). + Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) }) t.Run("Gist (ID)", func(t *testing.T) { name := "github-gist-id" - Expect(KamelRunWithID(operatorID, ns, "--name", name, "gist:e2c3f9a5fd0d9e79b21b04809786f17a").Execute()).To(Succeed()) + Expect(KamelRunWithID(operatorID, ns, "--name", name, + "gist:e2c3f9a5fd0d9e79b21b04809786f17a").Execute()).To(Succeed()) Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Tick!")) Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) @@ -70,9 +87,11 @@ func TestKamelCLIRun(t *testing.T) { t.Run("Gist (URL)", func(t *testing.T) { name := "github-gist-url" - Expect(KamelRunWithID(operatorID, ns, "--name", name, "https://gist.github.com/lburgazzoli/e2c3f9a5fd0d9e79b21b04809786f17a").Execute()).To(Succeed()) + Expect(KamelRunWithID(operatorID, ns, "--name", name, + "https://gist.github.com/lburgazzoli/e2c3f9a5fd0d9e79b21b04809786f17a").Execute()).To(Succeed()) Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Tick!")) Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) @@ -86,21 +105,25 @@ func TestKamelCLIRun(t *testing.T) { name := "run" Expect(KamelRunWithID(operatorID, ns, "files/run.yaml", "--name", name).Execute()).To(Succeed()) Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magic default")) // Re-run the Integration with an updated configuration - Expect(KamelRunWithID(operatorID, ns, "files/run.yaml", "--name", name, "-p", "property=value").Execute()).To(Succeed()) + Expect(KamelRunWithID(operatorID, ns, "files/run.yaml", "--name", name, "-p", "property=value").Execute()). + To(Succeed()) // Check the Deployment has progressed successfully - Eventually(DeploymentCondition(ns, name, appsv1.DeploymentProgressing), TestTimeoutShort).Should(MatchFields(IgnoreExtras, Fields{ - "Status": Equal(corev1.ConditionTrue), - "Reason": Equal("NewReplicaSetAvailable"), - })) + Eventually(DeploymentCondition(ns, name, appsv1.DeploymentProgressing), TestTimeoutShort). + Should(MatchFields(IgnoreExtras, Fields{ + "Status": Equal(corev1.ConditionTrue), + "Reason": Equal("NewReplicaSetAvailable"), + })) // Check the new configuration is taken into account Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning)) - Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort). + Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magic value")) // Clean up diff --git a/pkg/cmd/modeline.go b/pkg/cmd/modeline.go index 1b7ed9e1ff..07e88155bb 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 1c6563886e..b15e66912c 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 55e688fd78..c68f277179 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 adc6beb09d..597308d251 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", "?")) }