Skip to content

Commit

Permalink
fix(cli): run Integration from GitHub branch
Browse files Browse the repository at this point in the history
Fix #3475
  • Loading branch information
tadayosi committed Jul 27, 2022
1 parent 5c00337 commit 8434df6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 18 deletions.
53 changes: 38 additions & 15 deletions e2e/namespace/install/cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,55 @@ 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())
})

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())
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/modeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/util_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "?"))
}

0 comments on commit 8434df6

Please sign in to comment.