From 25b138e2dac1872f103379fc89d5d8788b5e9067 Mon Sep 17 00:00:00 2001 From: Thomas Diesler Date: Wed, 24 Apr 2024 12:24:36 +0200 Subject: [PATCH] Add e2e traits test for cron --- e2e/common/misc/cron_test.go | 24 +++++++++++++------ .../files/{cron.yaml => cron-trait-yaml.yaml} | 3 ++- 2 files changed, 19 insertions(+), 8 deletions(-) rename e2e/common/misc/files/{cron.yaml => cron-trait-yaml.yaml} (96%) diff --git a/e2e/common/misc/cron_test.go b/e2e/common/misc/cron_test.go index 256ef653cf..5337988a45 100644 --- a/e2e/common/misc/cron_test.go +++ b/e2e/common/misc/cron_test.go @@ -32,6 +32,8 @@ import ( . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + + "github.com/stretchr/testify/assert" ) func TestRunCronExample(t *testing.T) { @@ -45,13 +47,6 @@ func TestRunCronExample(t *testing.T) { g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - t.Run("cron", func(t *testing.T) { - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/cron.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationCronJob(t, ctx, ns, "cron"), TestTimeoutLong).ShouldNot(BeNil()) - g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ctx, ns, "cron"), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) - }) - t.Run("cron-yaml", func(t *testing.T) { g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/cron-yaml.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-yaml"), TestTimeoutLong).ShouldNot(BeNil()) @@ -80,6 +75,21 @@ func TestRunCronExample(t *testing.T) { g.Eventually(IntegrationLogs(t, ctx, ns, "cron-quartz"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) + t.Run("cron-trait-yaml", func(t *testing.T) { + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/cron-trait-yaml.yaml", "-t", "cron.enabled=true", "-t", "cron.schedule=0/2 * * * *").Execute()).To(Succeed()) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-trait-yaml", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-trait-yaml"), TestTimeoutLong).ShouldNot(BeNil()) + + // Verify that `-t cron.schedule` overrides the schedule in the yaml + // + // kubectl get cronjobs -n test-de619ae2-eddc-4bac-86a6-53d80be030ea + // NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE + // cron-trait-yaml 0/2 * * * * False 0 38s + + cronJob := IntegrationCronJob(t, ctx, ns, "cron-trait-yaml")() + assert.Equal(t, "0/2 * * * *", cronJob.Spec.Schedule) + }) + g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/misc/files/cron.yaml b/e2e/common/misc/files/cron-trait-yaml.yaml similarity index 96% rename from e2e/common/misc/files/cron.yaml rename to e2e/common/misc/files/cron-trait-yaml.yaml index 9b67350532..464579ee70 100644 --- a/e2e/common/misc/files/cron.yaml +++ b/e2e/common/misc/files/cron-trait-yaml.yaml @@ -18,7 +18,8 @@ - from: uri: "cron:tab" parameters: - schedule: "* * * * ?" + # Every minute + schedule: "* * * * *" steps: - setHeader: name: "m"