You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2023/03/24 08:13:15 UTC

[camel-k] 03/04: chore(test): improve testing

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 a98002e97de2648c4252a1147faa20e2c6454f34
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Mar 23 13:05:59 2023 +0100

    chore(test): improve testing
---
 e2e/native/native_test.go               | 31 ++++++++---------
 e2e/native/native_with_sources_test.go  | 59 +++++++++++++++++----------------
 pkg/controller/integration/kits.go      |  6 ++--
 pkg/controller/integration/kits_test.go | 50 ++++++++++++++++++++++++++--
 4 files changed, 98 insertions(+), 48 deletions(-)

diff --git a/e2e/native/native_test.go b/e2e/native/native_test.go
index 703956955..e523067fe 100644
--- a/e2e/native/native_test.go
+++ b/e2e/native/native_test.go
@@ -127,24 +127,25 @@ func TestNativeIntegrations(t *testing.T) {
 
 			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
 
+			t.Run("yaml native should not rebuild", func(t *testing.T) {
+				name := "yaml-native-2"
+				Expect(KamelRunWithID(operatorID, ns, "files/yaml2.yaml", "--name", name,
+					"-t", "quarkus.package-type=native",
+				).Execute()).To(Succeed())
+
+				// This one should run quickly as it suppose to reuse an IntegrationKit
+				Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning))
+				Eventually(IntegrationPod(ns, name), TestTimeoutShort).
+					Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
+				Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
+					Should(Equal(corev1.ConditionTrue))
+				Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!2"))
+				Expect(IntegrationKit(ns, "yaml-native")).Should(Equal(IntegrationKit(ns, "yaml-native-2")))
+			})
+
 			// Clean up
 			Expect(Kamel("delete", name, "-n", ns).Execute()).To(Succeed())
 		})
 
-		t.Run("yaml native should not rebuild", func(t *testing.T) {
-			name := "yaml-native-2"
-			Expect(KamelRunWithID(operatorID, ns, "files/yaml2.yaml", "--name", name,
-				"-t", "quarkus.package-type=native",
-			).Execute()).To(Succeed())
-
-			// This one should run quickly as it suppose to reuse an IntegrationKit
-			Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning))
-			Eventually(IntegrationPod(ns, name), TestTimeoutShort).
-				Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
-			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
-				Should(Equal(corev1.ConditionTrue))
-			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!2"))
-			Expect(IntegrationKit(ns, "yaml-native")).Should(Equal(IntegrationKit(ns, "yaml-native-2")))
-		})
 	})
 }
diff --git a/e2e/native/native_with_sources_test.go b/e2e/native/native_with_sources_test.go
index f59f6cdbc..fd7c58276 100644
--- a/e2e/native/native_with_sources_test.go
+++ b/e2e/native/native_with_sources_test.go
@@ -55,37 +55,38 @@ func TestNativeHighMemoryIntegrations(t *testing.T) {
 			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
 				Should(Equal(corev1.ConditionTrue))
 			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!"))
-		})
 
-		t.Run("java native same should not rebuild", func(t *testing.T) {
-			name := "java-native-clone"
-			Expect(KamelRunWithID(operatorID, ns, "files/Java.java", "--name", name,
-				"-t", "quarkus.package-type=native",
-			).Execute()).To(Succeed())
+			t.Run("java native same should not rebuild", func(t *testing.T) {
+				name := "java-native-clone"
+				Expect(KamelRunWithID(operatorID, ns, "files/Java.java", "--name", name,
+					"-t", "quarkus.package-type=native",
+				).Execute()).To(Succeed())
+
+				// This one should run quickly as it suppose to reuse an IntegrationKit
+				Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning))
+				Eventually(IntegrationPod(ns, name), TestTimeoutShort).
+					Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
+				Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
+					Should(Equal(corev1.ConditionTrue))
+				Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!"))
+				Expect(IntegrationKit(ns, "java-native")).Should(Equal(IntegrationKit(ns, "java-native-clone")))
+			})
+
+			t.Run("java native should rebuild", func(t *testing.T) {
+				name := "java-native-2"
+				Expect(KamelRunWithID(operatorID, ns, "files/Java2.java", "--name", name,
+					"-t", "quarkus.package-type=native",
+				).Execute()).To(Succeed())
+
+				Eventually(IntegrationPodPhase(ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning))
+				Eventually(IntegrationPod(ns, name), TestTimeoutShort).
+					Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
+				Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
+					Should(Equal(corev1.ConditionTrue))
+				Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magic2string!"))
+				Expect(IntegrationKit(ns, "java-native-2")).ShouldNot(Equal(IntegrationKit(ns, "java-native")))
+			})
 
-			// This one should run quickly as it suppose to reuse an IntegrationKit
-			Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning))
-			Eventually(IntegrationPod(ns, name), TestTimeoutShort).
-				Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
-			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
-				Should(Equal(corev1.ConditionTrue))
-			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!"))
-			Expect(IntegrationKit(ns, "java-native")).Should(Equal(IntegrationKit(ns, "java-native-clone")))
-		})
-
-		t.Run("java native should rebuild", func(t *testing.T) {
-			name := "java-native-2"
-			Expect(KamelRunWithID(operatorID, ns, "files/Java2.java", "--name", name,
-				"-t", "quarkus.package-type=native",
-			).Execute()).To(Succeed())
-
-			Eventually(IntegrationPodPhase(ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning))
-			Eventually(IntegrationPod(ns, name), TestTimeoutShort).
-				Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
-			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
-				Should(Equal(corev1.ConditionTrue))
-			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magic2string!"))
-			Expect(IntegrationKit(ns, "java-native-2")).ShouldNot(Equal(IntegrationKit(ns, "java-native")))
 			// Clean up
 			Expect(Kamel("delete", name, "-n", ns).Execute()).To(Succeed())
 		})
diff --git a/pkg/controller/integration/kits.go b/pkg/controller/integration/kits.go
index ee3b8550e..f96ea10e0 100644
--- a/pkg/controller/integration/kits.go
+++ b/pkg/controller/integration/kits.go
@@ -259,14 +259,16 @@ func matchesTrait(it map[string]interface{}, kt map[string]interface{}) bool {
 
 func hasMatchingSources(it *v1.Integration, kit *v1.IntegrationKit) bool {
 	for _, itSource := range it.Sources() {
+		found := false
 		for _, ikSource := range kit.Spec.Sources {
 			if itSource.Content == ikSource.Content {
-				// found, let's move to the next one
+				found = true
 				break
 			}
+		}
+		if !found {
 			return false
 		}
-
 	}
 	return true
 }
diff --git a/pkg/controller/integration/kits_test.go b/pkg/controller/integration/kits_test.go
index 08113e27e..c4b017c5c 100644
--- a/pkg/controller/integration/kits_test.go
+++ b/pkg/controller/integration/kits_test.go
@@ -356,8 +356,54 @@ func TestHasMatchingSources(t *testing.T) {
 		},
 	}
 
-	hasMatchingSources := hasMatchingSources(integration, kit)
-	assert.True(t, hasMatchingSources)
+	hms := hasMatchingSources(integration, kit)
+	assert.True(t, hms)
+
+	kit2 := &v1.IntegrationKit{
+		Spec: v1.IntegrationKitSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content 2", v1.LanguageJavaShell),
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	hms2 := hasMatchingSources(integration, kit2)
+	assert.True(t, hms2)
+}
+
+func TestHasMatchingMultipleSources(t *testing.T) {
+	integration := &v1.Integration{
+		Spec: v1.IntegrationSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+				v1.NewSourceSpec("test", "some content 2", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	kit := &v1.IntegrationKit{
+		Spec: v1.IntegrationKitSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content 2", v1.LanguageJavaShell),
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	hms := hasMatchingSources(integration, kit)
+	assert.True(t, hms)
+
+	integration2 := &v1.Integration{
+		Spec: v1.IntegrationSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	hms2 := hasMatchingSources(integration2, kit)
+	assert.True(t, hms2)
 }
 
 func TestHasNotMatchingSources(t *testing.T) {