You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/07/22 09:05:39 UTC
[camel-k] branch main updated: Add classpath kamelet loading test
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new dc2d566 Add classpath kamelet loading test
dc2d566 is described below
commit dc2d566ce703b7e601bebfdbd8a1aa58e7fe549d
Author: Jan <jb...@redhat.com>
AuthorDate: Tue Jul 20 12:19:47 2021 +0200
Add classpath kamelet loading test
---
e2e/common/cli/uninstall_test.go | 6 ++--
e2e/common/files/ChuckNorrisKamelet.java | 29 +++++++++++++++
e2e/common/kamelet_test.go | 61 ++++++++++++++++++++++++++++++++
e2e/support/test_support.go | 21 ++++++++---
4 files changed, 110 insertions(+), 7 deletions(-)
diff --git a/e2e/common/cli/uninstall_test.go b/e2e/common/cli/uninstall_test.go
index e866446..fb3933c 100644
--- a/e2e/common/cli/uninstall_test.go
+++ b/e2e/common/cli/uninstall_test.go
@@ -42,7 +42,7 @@ func TestBasicUninstall(t *testing.T) {
Eventually(Configmap(ns, "camel-k-maven-settings")).Should(BeNil())
Eventually(ServiceAccount(ns, "camel-k-operator")).Should(BeNil())
Eventually(OperatorPod(ns)).Should(BeNil())
- Eventually(Kamelet(ns)).Should(BeNil())
+ Eventually(KameletList(ns)).Should(BeEmpty())
})
}
@@ -107,9 +107,9 @@ func TestUninstallSkipKamelets(t *testing.T) {
// a successful new installation
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
Eventually(OperatorPod(ns)).ShouldNot(BeNil())
- Eventually(Kamelet(ns)).ShouldNot(BeNil())
+ Eventually(KameletList(ns)).ShouldNot(BeEmpty())
// on uninstall it should remove everything except kamelets
Expect(Kamel("uninstall", "-n", ns, "--skip-crd", "--skip-cluster-roles", "--skip-kamelets").Execute()).To(Succeed())
- Eventually(Kamelet(ns)).ShouldNot(BeNil())
+ Eventually(KameletList(ns)).ShouldNot(BeEmpty())
})
}
diff --git a/e2e/common/files/ChuckNorrisKamelet.java b/e2e/common/files/ChuckNorrisKamelet.java
new file mode 100644
index 0000000..3410307
--- /dev/null
+++ b/e2e/common/files/ChuckNorrisKamelet.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.lang.Exception;
+import java.lang.Override;
+import org.apache.camel.builder.RouteBuilder;
+
+public class ChuckNorrisKamelet extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ from("kamelet:chuck-norris-source")
+ .setBody(simple("Received another joke: ${body}"))
+ .to("log:info");
+ }
+}
diff --git a/e2e/common/kamelet_test.go b/e2e/common/kamelet_test.go
new file mode 100644
index 0000000..13dd19f
--- /dev/null
+++ b/e2e/common/kamelet_test.go
@@ -0,0 +1,61 @@
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "knative"
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package common
+
+import (
+ "testing"
+
+ . "github.com/onsi/gomega"
+ v1 "k8s.io/api/core/v1"
+
+ . "github.com/apache/camel-k/e2e/support"
+)
+
+func TestKameletClasspathLoading(t *testing.T) {
+ WithNewTestNamespace(t, func(ns string) {
+ Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
+
+ kameletName := "chuck-norris-source"
+ removeKamelet(kameletName , ns)
+
+ Eventually(Kamelet(kameletName, ns)).Should(BeNil())
+
+ Expect(Kamel("run", "files/ChuckNorrisKamelet.java", "-n", ns, "-t", "kamelets.enabled=false",
+ "-d", "github:apache.camel-kamelets:camel-kamelets-catalog:main-SNAPSHOT",
+ "-d", "camel:yaml-dsl",
+ // kamelet dependencies
+ "-d", "camel:timer",
+ "-d", "camel:jsonpath",
+ "-d", "camel:http").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "chuck-norris-kamelet"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+
+ Eventually(IntegrationLogs(ns, "chuck-norris-kamelet")).Should(ContainSubstring("Received another joke:"))
+
+ // Cleanup
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
+ })
+}
+
+func removeKamelet(name string, ns string) {
+ kamelet := Kamelet(name, ns)()
+ TestClient().Delete(TestContext, kamelet)
+}
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 20bc701..01a4536 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -956,17 +956,30 @@ func ServiceAccount(ns, name string) func() *corev1.ServiceAccount {
}
}
-func Kamelet(ns string) func() *v1alpha1.Kamelet {
- return func() *v1alpha1.Kamelet {
+func KameletList(ns string) func() []v1alpha1.Kamelet {
+ return func() []v1alpha1.Kamelet {
lst := v1alpha1.NewKameletList()
err := TestClient().List(TestContext, &lst, ctrl.InNamespace(ns))
if err != nil {
panic(err)
}
- if len(lst.Items) == 0 {
+ return lst.Items
+ }
+}
+
+func Kamelet(name string, ns string) func() *v1alpha1.Kamelet {
+ return func() *v1alpha1.Kamelet {
+ it := v1alpha1.NewKamelet(ns, name)
+ key := ctrl.ObjectKey{
+ Namespace: ns,
+ Name: name,
+ }
+ if err := TestClient().Get(TestContext, key, &it); err != nil && !k8serrors.IsNotFound(err) {
+ panic(err)
+ } else if err != nil && k8serrors.IsNotFound(err) {
return nil
}
- return &lst.Items[0]
+ return &it
}
}