This is an automated email from the ASF dual-hosted git repository. pcongiusti pushed a commit to branch release-1.12.x in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 3120c407077d25b054e83e9b81f7a218193adffc Author: Pasquale Congiusti <[email protected]> AuthorDate: Thu Mar 23 13:05:59 2023 +0100 chore(test): improve testing --- e2e/namespace/native/native_with_sources_test.go | 59 ++++++++++++------------ pkg/controller/integration/kits.go | 6 ++- pkg/controller/integration/kits_test.go | 50 +++++++++++++++++++- 3 files changed, 82 insertions(+), 33 deletions(-) diff --git a/e2e/namespace/native/native_with_sources_test.go b/e2e/namespace/native/native_with_sources_test.go index fc3c73242..055f23bab 100644 --- a/e2e/namespace/native/native_with_sources_test.go +++ b/e2e/namespace/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 4dfc4c74d..ad48350c6 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 3abc0ef47..312e69b7a 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) {
