From 15a17843383b52b277694a560d3e6827935e5406 Mon Sep 17 00:00:00 2001 From: realMartinez Date: Wed, 26 Jun 2024 14:42:41 +0200 Subject: [PATCH] knative service URL test knative service URL test knative service URL test knative service URL test Fix knative service url e2e test --- e2e/knative/files/knativeurl1.yaml | 23 +++++++++++ e2e/knative/files/knativeurl2.yaml | 29 ++++++++++++++ e2e/knative/knative_service_test.go | 60 +++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 e2e/knative/files/knativeurl1.yaml create mode 100644 e2e/knative/files/knativeurl2.yaml create mode 100644 e2e/knative/knative_service_test.go diff --git a/e2e/knative/files/knativeurl1.yaml b/e2e/knative/files/knativeurl1.yaml new file mode 100644 index 0000000000..236cfacc9c --- /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/knative" + 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..c196025d0d --- /dev/null +++ b/e2e/knative/files/knativeurl2.yaml @@ -0,0 +1,29 @@ +# 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/knative1" + steps: + - setBody: + constant: "knative1" + +- from: + uri: "knative:endpoint/knative2" + steps: + - setBody: + constant: "knative2" diff --git a/e2e/knative/knative_service_test.go b/e2e/knative/knative_service_test.go new file mode 100644 index 0000000000..79cf674205 --- /dev/null +++ b/e2e/knative/knative_service_test.go @@ -0,0 +1,60 @@ +//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 knative + +import ( + "context" + "testing" + + . "github.com/onsi/gomega" + + . "github.com/apache/camel-k/v2/e2e/support" + camelv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + v1 "k8s.io/api/core/v1" +) + +func TestKnativeServiceURL(t *testing.T) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + + 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)) + }) + + 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()) + }) +}