From 536c173690f9f157b5d74edc4b260296392e69ad Mon Sep 17 00:00:00 2001 From: Claudio Miranda Date: Wed, 28 Aug 2024 17:49:17 +0100 Subject: [PATCH] Fix knative service url e2e test --- e2e/knative/files/knativeurl1.yaml | 23 +++++++++++++++ e2e/knative/files/knativeurl2.yaml | 31 ++++++++++++++++++++ e2e/knative/knative_service_test.go | 44 +++++++++++++---------------- 3 files changed, 74 insertions(+), 24 deletions(-) create mode 100644 e2e/knative/files/knativeurl1.yaml create mode 100644 e2e/knative/files/knativeurl2.yaml diff --git a/e2e/knative/files/knativeurl1.yaml b/e2e/knative/files/knativeurl1.yaml new file mode 100644 index 0000000000..628091eb00 --- /dev/null +++ b/e2e/knative/files/knativeurl1.yaml @@ -0,0 +1,23 @@ +# camel-k: language=yaml +# --------------------------------------------------------------------------- +# 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: "knative:endpoint/knativeurl" + steps: + - setBody: + constant: "Hello from knative" diff --git a/e2e/knative/files/knativeurl2.yaml b/e2e/knative/files/knativeurl2.yaml new file mode 100644 index 0000000000..78206859cc --- /dev/null +++ b/e2e/knative/files/knativeurl2.yaml @@ -0,0 +1,31 @@ +# camel-k: language=yaml +# --------------------------------------------------------------------------- +# 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: "timer:tick" + steps: + - setBody: + constant: "message" + - to: "knative:channel/messages" + +- from: + uri: "timer:tick" + steps: + - setBody: + constant: "word" + - to: "knative:channel/words" diff --git a/e2e/knative/knative_service_test.go b/e2e/knative/knative_service_test.go index 7e19b5c8e4..bbb683ce03 100644 --- a/e2e/knative/knative_service_test.go +++ b/e2e/knative/knative_service_test.go @@ -27,37 +27,33 @@ 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" - "github.com/apache/camel-k/v2/pkg/util/knative" + camelv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + v1 "k8s.io/api/core/v1" ) func TestKnativeServiceURL(t *testing.T) { - g := NewWithT(t) - - installed, err := knative.IsServingInstalled(TestClient(t)) - g.Expect(err).NotTo(HaveOccurred()) - if !installed { - t.Error("Knative not installed in the cluster") - t.FailNow() - } WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-knative-service" - // Install without profile (should automatically detect the presence of Knative) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Eventually(PlatformProfile(t, ctx, ns), TestTimeoutShort).Should(Equal(v1.TraitProfile(""))) - cluster := Platform(t, ctx, ns)().Status.Cluster - - t.Run("run yaml on cluster profile", func(t *testing.T) { - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knative2.yaml", "--profile", string(cluster)).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ctx, ns, "knative2"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationTraitProfile(t, ctx, ns, "knative2"), TestTimeoutShort).Should(Equal(v1.TraitProfile(string(cluster)))) - - g.Eventually(KnativeService(t, ctx, ns, "knative2")().Status.RouteStatusFields.URL.String(), TestTimeoutLong).Should(Equal("http://knative2.ns.domain")) + t.Run("Service endpoint url check", func(t *testing.T) { + g.Expect(KamelRun(t, ctx, ns, "files/knativeurl1.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativeurl1"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "knativeurl1", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue)) + ks := KnativeService(t, ctx, ns, "knativeurl1") + g.Eventually(ks, TestTimeoutShort).ShouldNot(BeNil()) + url := "http://knativeurl1." + ns + ".svc.cluster.local" + g.Eventually(ks().Status.RouteStatusFields.URL.String(), TestTimeoutShort).Should(Equal(url)) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) + }) + t.Run("Service multiple endpoint url check", func(t *testing.T) { + g.Expect(KamelRun(t, ctx, ns, "files/knativeurl2.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativeurl2"), TestTimeoutLong).Should(Equal(v1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "knativeurl2", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue)) + ks := KnativeService(t, ctx, ns, "knativeurl2") + g.Eventually(ks, TestTimeoutShort).ShouldNot(BeNil()) + url := "http://knativeurl2." + ns + ".svc.cluster.local" + g.Eventually(ks().Status.RouteStatusFields.URL.String(), TestTimeoutShort).Should(Equal(url)) g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) })