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

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

commit 4ed20573d0cefab1756cd760ea3e04485c1ee4fe
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Thu Feb 23 09:48:51 2023 +0100

    chore: knative tests
---
 .github/actions/e2e-common/action.yml              |  3 +-
 .github/actions/e2e-common/exec-tests.sh           |  4 +-
 .github/workflows/common.yml                       |  2 +-
 .../cli/{kamelet_test.go => kamelet_repo_test.go}  |  4 +-
 e2e/common/misc/kamelet_test.go                    | 19 ------
 ...{display.groovy => test-kamelet-display.groovy} |  2 +-
 e2e/knative/kamelet_test.go                        |  7 +-
 e2e/knative/knative_platform_test.go               | 78 ++++++++++++----------
 e2e/knative/knative_test.go                        |  6 +-
 9 files changed, 57 insertions(+), 68 deletions(-)

diff --git a/.github/actions/e2e-common/action.yml 
b/.github/actions/e2e-common/action.yml
index ba9052873..b9771b105 100644
--- a/.github/actions/e2e-common/action.yml
+++ b/.github/actions/e2e-common/action.yml
@@ -26,7 +26,8 @@ inputs:
     description: 'Base16 encoded kube config - required for custom cluster 
type only'
     required: false
   with-custom-install:
-    description: 'Special type of common tests which require customized 
installation procedure'
+    description: 'Indicates whether the advanced common integration tests 
should be launched (default false)'
+    default: 'false'
     required: false
 
 runs:
diff --git a/.github/actions/e2e-common/exec-tests.sh 
b/.github/actions/e2e-common/exec-tests.sh
index c38482719..69fff0375 100755
--- a/.github/actions/e2e-common/exec-tests.sh
+++ b/.github/actions/e2e-common/exec-tests.sh
@@ -58,7 +58,7 @@ while getopts ":b:c:g:i:l:n:q:s:v:x:z:" opt; do
       SAVE_FAILED_TEST_NS=${OPTARG}
       ;;
     z)
-      CUSTOM_INSTALL_TEST="${OPTARG}"
+      CUSTOM_INSTALL_TEST=${OPTARG}
       ;;
     :)
       echo "ERROR: Option -$OPTARG requires an argument"
@@ -137,7 +137,7 @@ fi
 # Then run all integration tests rather than ending on first failure
 set -e
 exit_code=0
-if [ ! -z "${CUSTOM_INSTALL_TEST}" ] && [ "${CUSTOM_INSTALL_TEST}" == "true" 
]; then
+if [ "${CUSTOM_INSTALL_TEST}" == "true" ]; then
   DO_TEST_PREBUILD=false GOTESTFMT="-json 2>&1 | gotestfmt" make 
test-common-with-custom-install || exit_code=1
 else
   DO_TEST_PREBUILD=false GOTESTFMT="-json 2>&1 | gotestfmt" make test-common 
|| exit_code=1
diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml
index 5502bebda..ef9931143 100644
--- a/.github/workflows/common.yml
+++ b/.github/workflows/common.yml
@@ -116,4 +116,4 @@ jobs:
       with:
         cluster-config-data: ${{ secrets.E2E_CLUSTER_CONFIG }}
         cluster-kube-config-data: ${{ secrets.E2E_KUBE_CONFIG }}
-        with-custom-install: true
+        with-custom-install: 'true'
diff --git a/e2e/common/cli/kamelet_test.go 
b/e2e/common/cli/kamelet_repo_test.go
similarity index 94%
rename from e2e/common/cli/kamelet_test.go
rename to e2e/common/cli/kamelet_repo_test.go
index aad161b90..c1e87fe4e 100644
--- a/e2e/common/cli/kamelet_test.go
+++ b/e2e/common/cli/kamelet_repo_test.go
@@ -43,7 +43,7 @@ func TestKameletFromCustomRepository(t *testing.T) {
        Eventually(Kamelet(kameletName, ns)).Should(BeNil())
        // Add the custom repository
        Expect(Kamel("kamelet", "add-repo",
-               "github:apache/camel-k/e2e/global/common/files/kamelets",
+               "github:squakez/ck-kamelet-test-repo/kamelets",
                "-n", ns,
                "-x", operatorID).Execute()).To(Succeed())
 
@@ -54,7 +54,7 @@ func TestKameletFromCustomRepository(t *testing.T) {
 
        // Remove the custom repository
        Expect(Kamel("kamelet", "remove-repo",
-               "github:apache/camel-k/e2e/global/common/files/kamelets",
+               "github:squakez/ck-kamelet-test-repo/kamelets",
                "-n", ns,
                "-x", operatorID).Execute()).To(Succeed())
 }
diff --git a/e2e/common/misc/kamelet_test.go b/e2e/common/misc/kamelet_test.go
index 2975c7801..8ceb2abec 100644
--- a/e2e/common/misc/kamelet_test.go
+++ b/e2e/common/misc/kamelet_test.go
@@ -46,24 +46,5 @@ func TestKameletClasspathLoading(t *testing.T) {
                Eventually(IntegrationLogs(ns, 
"timer-kamelet-integration")).Should(ContainSubstring("important message"))
        })
 
-       // Custom repo without operator ID
-       t.Run("test custom Kamelet repository without operator ID", func(t 
*testing.T) {
-               kameletName := "timer-custom-source"
-               removeKamelet(kameletName, ns)
-               Eventually(Kamelet(kameletName, ns)).Should(BeNil())
-               // Add the custom repository
-               Expect(Kamel("kamelet", "add-repo", 
"github:apache/camel-k/e2e/global/common/files/kamelets", "-n", 
ns).Execute()).To(Succeed())
-               Expect(KamelRunWithID(operatorID, ns, 
"files/TimerCustomKameletIntegration.java").Execute()).To(Succeed())
-               Eventually(IntegrationPodPhase(ns, 
"timer-custom-kamelet-integration"), 
TestTimeoutLong).Should(Equal(corev1.PodRunning))
-               Eventually(IntegrationLogs(ns, 
"timer-custom-kamelet-integration")).Should(ContainSubstring("great message"))
-               // Remove the custom repository
-               Expect(Kamel("kamelet", "remove-repo", 
"github:apache/camel-k/e2e/global/common/files/kamelets", "-n", 
ns).Execute()).To(Succeed())
-       })
-
        Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
 }
-
-func removeKamelet(name string, ns string) {
-       kamelet := Kamelet(name, ns)()
-       TestClient().Delete(TestContext, kamelet)
-}
diff --git a/e2e/knative/files/display.groovy 
b/e2e/knative/files/test-kamelet-display.groovy
similarity index 94%
rename from e2e/knative/files/display.groovy
rename to e2e/knative/files/test-kamelet-display.groovy
index 43a595f6c..fcde17d22 100644
--- a/e2e/knative/files/display.groovy
+++ b/e2e/knative/files/test-kamelet-display.groovy
@@ -15,6 +15,6 @@
  * limitations under the License.
  */
 
-from('knative:channel/messages')
+from('knative:channel/test-kamelet-messages')
     .convertBodyTo(String.class)
     .to('log:info?showAll=false')
diff --git a/e2e/knative/kamelet_test.go b/e2e/knative/kamelet_test.go
index 6d9a6d583..8e48a8710 100644
--- a/e2e/knative/kamelet_test.go
+++ b/e2e/knative/kamelet_test.go
@@ -41,10 +41,11 @@ import (
 func TestKameletChange(t *testing.T) {
        RegisterTestingT(t)
 
+       knChannel := "test-kamelet-messages"
        timerSource := "my-timer-source"
        Expect(CreateTimerKamelet(ns, timerSource)()).To(Succeed())
-       Expect(CreateKnativeChannel(ns, "messages")()).To(Succeed())
-       Expect(KamelRunWithID(operatorID, ns, "files/display.groovy", 
"-w").Execute()).To(Succeed())
+       Expect(CreateKnativeChannel(ns, knChannel)()).To(Succeed())
+       Expect(KamelRunWithID(operatorID, ns, 
"files/test-kamelet-display.groovy", "-w").Execute()).To(Succeed())
 
        from := corev1.ObjectReference{
                Kind:       "Kamelet",
@@ -54,7 +55,7 @@ func TestKameletChange(t *testing.T) {
 
        to := corev1.ObjectReference{
                Kind:       "InMemoryChannel",
-               Name:       "messages",
+               Name:       knChannel,
                APIVersion: messaging.SchemeGroupVersion.String(),
        }
 
diff --git a/e2e/knative/knative_platform_test.go 
b/e2e/knative/knative_platform_test.go
index 594718b51..fc39544c0 100644
--- a/e2e/knative/knative_platform_test.go
+++ b/e2e/knative/knative_platform_test.go
@@ -38,7 +38,7 @@ import (
        "github.com/apache/camel-k/pkg/util/knative"
 )
 
-func TestKnativePlatform(t *testing.T) {
+func TestKnativePlatformDetection(t *testing.T) {
        RegisterTestingT(t)
 
        installed, err := knative.IsInstalled(TestClient())
@@ -48,41 +48,45 @@ func TestKnativePlatform(t *testing.T) {
                t.FailNow()
        }
 
-       operatorID := "camel-k-knative"
-       Eventually(PlatformPhase(ns), 
TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
-       Eventually(PlatformProfile(ns), 
TestTimeoutShort).Should(Equal(v1.TraitProfile("")))
-       cluster := Platform(ns)().Status.Cluster
-
-       t.Run("run yaml on cluster profile", func(t *testing.T) {
-               Expect(KamelRunWithID(operatorID, ns, "files/yaml.yaml", 
"--profile", string(cluster)).Execute()).To(Succeed())
-               Eventually(IntegrationPodPhase(ns, "yaml"), 
TestTimeoutLong).Should(Equal(corev1.PodRunning))
-               Eventually(IntegrationLogs(ns, "yaml"), 
TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
-               Eventually(IntegrationProfile(ns, "yaml"), 
TestTimeoutShort).Should(Equal(v1.TraitProfile(string(cluster))))
-               // Change something in the integration to produce a redeploy
-               Expect(UpdateIntegration(ns, "yaml", func(it *v1.Integration) {
-                       it.Spec.Profile = ""
-                       content, err := dsl.ToYamlDSL(it.Spec.Flows)
-                       assert.NoError(t, err)
-                       newData := strings.ReplaceAll(string(content), 
"string!", "string!!!")
-                       newFlows, err := dsl.FromYamlDSLString(newData)
-                       assert.NoError(t, err)
-                       it.Spec.Flows = newFlows
-               })).To(Succeed())
-               // Spec profile should be reset by "kamel run"
-               Eventually(IntegrationSpecProfile(ns, 
"yaml")).Should(Equal(v1.TraitProfile("")))
-               // When integration is running again ...
-               Eventually(IntegrationPhase(ns, 
"yaml")).Should(Equal(v1.IntegrationPhaseRunning))
-               Eventually(IntegrationLogs(ns, "yaml"), 
TestTimeoutShort).Should(ContainSubstring("Magicstring!!!"))
-               // It should keep the old profile saved in status
-               Eventually(IntegrationProfile(ns, "yaml"), 
TestTimeoutMedium).Should(Equal(v1.TraitProfile(cluster)))
-
-               Expect(Kamel("delete", "--all", "-n", 
ns).Execute()).To(Succeed())
-       })
-
-       t.Run("run yaml on automatic profile", func(t *testing.T) {
-               Expect(KamelRunWithID(operatorID, ns, 
"files/yaml.yaml").Execute()).To(Succeed())
-               Eventually(IntegrationPodPhase(ns, "yaml"), 
TestTimeoutLong).Should(Equal(corev1.PodRunning))
-               Eventually(IntegrationProfile(ns, "yaml"), 
TestTimeoutShort).Should(Equal(v1.TraitProfileKnative))
-               Expect(Kamel("delete", "--all", "-n", 
ns).Execute()).To(Succeed())
+       WithNewTestNamespace(t, func(ns string) {
+               operatorID := "camel-k-knative"
+               // Install withouth profile (should automatically detect the 
presence of KNative)
+               Expect(KamelInstallWithID(operatorID, 
ns).Execute()).To(Succeed())
+               Eventually(PlatformPhase(ns), 
TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
+               Eventually(PlatformProfile(ns), 
TestTimeoutShort).Should(Equal(v1.TraitProfile("")))
+               cluster := Platform(ns)().Status.Cluster
+
+               t.Run("run yaml on cluster profile", func(t *testing.T) {
+                       Expect(KamelRunWithID(operatorID, ns, 
"files/yaml.yaml", "--profile", string(cluster)).Execute()).To(Succeed())
+                       Eventually(IntegrationPodPhase(ns, "yaml"), 
TestTimeoutLong).Should(Equal(corev1.PodRunning))
+                       Eventually(IntegrationLogs(ns, "yaml"), 
TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+                       Eventually(IntegrationProfile(ns, "yaml"), 
TestTimeoutShort).Should(Equal(v1.TraitProfile(string(cluster))))
+                       // Change something in the integration to produce a 
redeploy
+                       Expect(UpdateIntegration(ns, "yaml", func(it 
*v1.Integration) {
+                               it.Spec.Profile = ""
+                               content, err := dsl.ToYamlDSL(it.Spec.Flows)
+                               assert.NoError(t, err)
+                               newData := strings.ReplaceAll(string(content), 
"string!", "string!!!")
+                               newFlows, err := dsl.FromYamlDSLString(newData)
+                               assert.NoError(t, err)
+                               it.Spec.Flows = newFlows
+                       })).To(Succeed())
+                       // Spec profile should be reset by "kamel run"
+                       Eventually(IntegrationSpecProfile(ns, 
"yaml")).Should(Equal(v1.TraitProfile("")))
+                       // When integration is running again ...
+                       Eventually(IntegrationPhase(ns, 
"yaml")).Should(Equal(v1.IntegrationPhaseRunning))
+                       Eventually(IntegrationLogs(ns, "yaml"), 
TestTimeoutShort).Should(ContainSubstring("Magicstring!!!"))
+                       // It should keep the old profile saved in status
+                       Eventually(IntegrationProfile(ns, "yaml"), 
TestTimeoutMedium).Should(Equal(v1.TraitProfile(cluster)))
+
+                       Expect(Kamel("delete", "--all", "-n", 
ns).Execute()).To(Succeed())
+               })
+
+               t.Run("run yaml on automatic profile", func(t *testing.T) {
+                       Expect(KamelRunWithID(operatorID, ns, 
"files/yaml.yaml").Execute()).To(Succeed())
+                       Eventually(IntegrationPodPhase(ns, "yaml"), 
TestTimeoutLong).Should(Equal(corev1.PodRunning))
+                       Eventually(IntegrationProfile(ns, "yaml"), 
TestTimeoutShort).Should(Equal(v1.TraitProfileKnative))
+                       Expect(Kamel("delete", "--all", "-n", 
ns).Execute()).To(Succeed())
+               })
        })
 }
diff --git a/e2e/knative/knative_test.go b/e2e/knative/knative_test.go
index 6c69a05de..a9810564a 100644
--- a/e2e/knative/knative_test.go
+++ b/e2e/knative/knative_test.go
@@ -38,8 +38,10 @@ import (
 func TestKnative(t *testing.T) {
        RegisterTestingT(t)
 
-       Expect(CreateKnativeChannel(ns, "messages")()).To(Succeed())
-       Expect(CreateKnativeChannel(ns, "words")()).To(Succeed())
+       knChannelMessages := "messages"
+       knChannelWords := "words"
+       Expect(CreateKnativeChannel(ns, knChannelMessages)()).To(Succeed())
+       Expect(CreateKnativeChannel(ns, knChannelWords)()).To(Succeed())
        operatorID := fmt.Sprintf("camel-k-%s", ns)
        Expect(KamelInstallWithID(operatorID, ns, "--trait-profile", 
"knative").Execute()).To(Succeed())
 

Reply via email to