From cd65373499d544cb969a191bf934eeb3bc3da3dd Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Tue, 10 Oct 2023 11:38:27 +0200 Subject: [PATCH] chore(e2e): kamelet trait test --- e2e/common/traits/files/webhook.yaml | 21 +++++++++ e2e/common/traits/kamelet_test.go | 67 ++++++++++++++++++++++++++++ e2e/support/test_support.go | 10 +++++ 3 files changed, 98 insertions(+) create mode 100644 e2e/common/traits/files/webhook.yaml create mode 100644 e2e/common/traits/kamelet_test.go diff --git a/e2e/common/traits/files/webhook.yaml b/e2e/common/traits/files/webhook.yaml new file mode 100644 index 0000000000..c6deb4c8ba --- /dev/null +++ b/e2e/common/traits/files/webhook.yaml @@ -0,0 +1,21 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- + +- from: + uri: "kamelet:capabilities-webhook-source" + steps: + - log: "${body}" diff --git a/e2e/common/traits/kamelet_test.go b/e2e/common/traits/kamelet_test.go new file mode 100644 index 0000000000..bd6ec96afc --- /dev/null +++ b/e2e/common/traits/kamelet_test.go @@ -0,0 +1,67 @@ +//go:build integration +// +build integration + +// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration" + +/* +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 traits + +import ( + "testing" + + . "github.com/onsi/gomega" + + corev1 "k8s.io/api/core/v1" + + . "github.com/apache/camel-k/v2/e2e/support" + v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" +) + +func TestKameletTrait(t *testing.T) { + RegisterTestingT(t) + + t.Run("discover kamelet capabilities", func(t *testing.T) { + template := map[string]interface{}{ + "from": map[string]interface{}{ + "uri": "platform-http:///webhook", + "steps": []map[string]interface{}{ + { + "to": "kamelet:sink", + }, + }, + }, + } + Expect(CreateKamelet(ns, "capabilities-webhook-source", template, nil, nil)()).To(Succeed()) + + name := "webhook" + Expect(KamelRunWithID(operatorID, ns, "files/webhook.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(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Started capabilities-webhook-source-1 (platform-http:///webhook)")) + // Verify Integration capabilities + Eventually(IntegrationStatusCapabilities(ns, name), TestTimeoutShort).Should(ContainElements("platform-http")) + // Verify expected resources from Kamelet (Service in this case) + service := Service(ns, name) + Eventually(service, TestTimeoutShort).ShouldNot(BeNil()) + }) + + // Clean-up + Expect(DeleteKamelet(ns, "capabilities-webhook-source")).To(Succeed()) + Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) +} diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index bbb10228fd..5ca577a216 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -998,6 +998,16 @@ func IntegrationSpecProfile(ns string, name string) func() v1.TraitProfile { } } +func IntegrationStatusCapabilities(ns string, name string) func() []string { + return func() []string { + it := Integration(ns, name)() + if it == nil || &it.Status == nil { + return nil + } + return it.Status.Capabilities + } +} + func IntegrationSpecSA(ns string, name string) func() string { return func() string { it := Integration(ns, name)()