From 1b0b0cb4a714983392e6bfe256a385bb971f3a94 Mon Sep 17 00:00:00 2001 From: Christoph Deppisch Date: Wed, 29 Jun 2022 08:58:06 +0200 Subject: [PATCH] fix(#3393): Disable cron job e2e test on OpenShift 3.x CronJob batch/v1 API is not available on OpenShift 3.x --- e2e/common/cli/install_test.go | 11 +++-------- e2e/common/cron_test.go | 6 ++++++ e2e/support/test_support.go | 6 ++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/e2e/common/cli/install_test.go b/e2e/common/cli/install_test.go index d1a76dc3c6..236b69652a 100644 --- a/e2e/common/cli/install_test.go +++ b/e2e/common/cli/install_test.go @@ -24,7 +24,6 @@ package common import ( "bytes" - "reflect" "strings" "testing" "text/template" @@ -36,9 +35,8 @@ import ( v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/install" "github.com/apache/camel-k/pkg/util/defaults" - "github.com/apache/camel-k/pkg/util/kubernetes" "github.com/apache/camel-k/pkg/util/openshift" - console "github.com/openshift/api/console/v1" + consolev1 "github.com/openshift/api/console/v1" corev1 "k8s.io/api/core/v1" ) @@ -98,11 +96,8 @@ func TestConsoleCliDownload(t *testing.T) { ocp, err := openshift.IsOpenShift(TestClient()) assert.Nil(t, err) - ok, err := kubernetes.IsAPIResourceInstalled(TestClient(), "console.openshift.io/v1", reflect.TypeOf(console.ConsoleCLIDownload{}).Name()) - assert.Nil(t, err) - - if !ocp || !ok { - t.Skip("This test requires ConsoleCliDownload object which is available on OpenShift 4 only.") + if !ocp || !IsAPIResourceInstalled(t, TestClient(), "console.openshift.io/v1", consolev1.ConsoleCLIDownload{}) { + t.Skip("This test requires ConsoleCliDownload object which is available on OpenShift 4+ only.") return } diff --git a/e2e/common/cron_test.go b/e2e/common/cron_test.go index dc26197db2..5ab80768d0 100644 --- a/e2e/common/cron_test.go +++ b/e2e/common/cron_test.go @@ -27,6 +27,7 @@ import ( . "github.com/onsi/gomega" + batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" . "github.com/apache/camel-k/e2e/support" @@ -34,6 +35,11 @@ import ( ) func TestRunCronExample(t *testing.T) { + if !IsAPIResourceInstalled(t, TestClient(), "batch/v1", batchv1.CronJob{}) { + t.Skip("This test requires CronJob batch/v1 API installed.") + return + } + WithNewTestNamespace(t, func(ns string) { Expect(Kamel("install", "-n", ns).Execute()).To(Succeed()) diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index 3fdd06077d..11e2d0ac1f 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -1933,3 +1933,9 @@ func GetOutputStringAsync(cmd *cobra.Command) func() string { return buffer.String() } } + +func IsAPIResourceInstalled(t *testing.T, client client.Client, groupVersion string, i any) bool { + ok, err := kubernetes.IsAPIResourceInstalled(client, groupVersion, reflect.TypeOf(i).Name()) + assert.Nil(t, err) + return ok +}