This is an automated email from the ASF dual-hosted git repository. cdeppisch pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 8793fa3e7c883d515574ead5601d6fd721ceb5ed Author: Christoph Deppisch <cdeppi...@redhat.com> AuthorDate: Wed Mar 13 15:38:19 2024 +0100 chore(e2e): Use a shared context in E2E tests --- e2e/advanced/main_test.go | 3 +-- e2e/common/cli/duplicate_parameters_test.go | 2 +- e2e/common/cli/help_test.go | 3 +-- e2e/common/cli/main_test.go | 3 +-- e2e/common/cli/offline_commands_test.go | 12 ++++-------- e2e/common/cli/version_test.go | 4 +--- e2e/common/main_test.go | 3 +-- e2e/install/kustomize/operator_test.go | 6 +++--- e2e/install/kustomize/setup_test.go | 4 ++-- e2e/install/kustomize/uninstall_test.go | 4 ++-- e2e/install/upgrade/helm_upgrade_test.go | 2 +- e2e/knative/kamelet_test.go | 3 +-- e2e/knative/knative_test.go | 2 +- e2e/knative/openapi_test.go | 3 +-- e2e/knative/pod_test.go | 3 +-- e2e/support/test_nexus_hooks.go | 3 +-- e2e/support/test_support.go | 25 ++++++++++++++----------- 17 files changed, 37 insertions(+), 48 deletions(-) diff --git a/e2e/advanced/main_test.go b/e2e/advanced/main_test.go index ca701cf4f..65dbc5afc 100644 --- a/e2e/advanced/main_test.go +++ b/e2e/advanced/main_test.go @@ -23,7 +23,6 @@ limitations under the License. package advanced import ( - "context" "fmt" "os" "testing" @@ -55,9 +54,9 @@ func TestMain(m *testing.M) { fmt.Printf("Test fast setup failed! - %s\n", message) }) - ctx := context.TODO() var t *testing.T g.Expect(TestClient(t)).ShouldNot(BeNil()) + ctx := TestContext() g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) diff --git a/e2e/common/cli/duplicate_parameters_test.go b/e2e/common/cli/duplicate_parameters_test.go index 44f6de40d..4882d96aa 100644 --- a/e2e/common/cli/duplicate_parameters_test.go +++ b/e2e/common/cli/duplicate_parameters_test.go @@ -35,7 +35,7 @@ import ( func TestDuplicateParameters(t *testing.T) { g := NewWithT(t) - ctx, cancel := context.WithCancel(context.TODO()) + ctx, cancel := context.WithCancel(TestContext()) defer cancel() // run kamel to output the traits/configuration structure in json format to check the processed values diff --git a/e2e/common/cli/help_test.go b/e2e/common/cli/help_test.go index 968d2efac..c51dd91e4 100644 --- a/e2e/common/cli/help_test.go +++ b/e2e/common/cli/help_test.go @@ -23,7 +23,6 @@ limitations under the License. package cli import ( - "context" "testing" . "github.com/onsi/gomega" @@ -32,7 +31,7 @@ import ( ) func TestKamelCLIHelp(t *testing.T) { - ctx := context.TODO() + ctx := TestContext() g := NewWithT(t) t.Run("default help message", func(t *testing.T) { diff --git a/e2e/common/cli/main_test.go b/e2e/common/cli/main_test.go index 4a2ae1916..fafad4f13 100644 --- a/e2e/common/cli/main_test.go +++ b/e2e/common/cli/main_test.go @@ -23,7 +23,6 @@ limitations under the License. package cli import ( - "context" "fmt" "os" "testing" @@ -44,10 +43,10 @@ func TestMain(m *testing.M) { fmt.Printf("Test setup failed! - %s\n", message) }) - ctx := context.TODO() var t *testing.T g.Expect(TestClient(t)).ShouldNot(BeNil()) + ctx := TestContext() // Install global operator for tests in this package, all tests must use this operatorID g.Expect(NewNamedTestNamespace(t, ctx, operatorNS, false)).ShouldNot(BeNil()) diff --git a/e2e/common/cli/offline_commands_test.go b/e2e/common/cli/offline_commands_test.go index f482a6d8e..a6d506e40 100644 --- a/e2e/common/cli/offline_commands_test.go +++ b/e2e/common/cli/offline_commands_test.go @@ -23,7 +23,6 @@ limitations under the License. package cli import ( - "context" "io" "testing" @@ -32,27 +31,24 @@ import ( ) func TestKamelVersionWorksOffline(t *testing.T) { - ctx := context.TODO() g := NewWithT(t) - g.Expect(Kamel(t, ctx, "version", "--kube-config", "non-existent-kubeconfig-file").Execute()).To(Succeed()) + g.Expect(Kamel(t, TestContext(), "version", "--kube-config", "non-existent-kubeconfig-file").Execute()).To(Succeed()) } func TestKamelHelpOptionWorksOffline(t *testing.T) { - ctx := context.TODO() g := NewWithT(t) - traitCmd := Kamel(t, ctx, "run", "Xxx.java", "--help") + traitCmd := Kamel(t, TestContext(), "run", "Xxx.java", "--help") traitCmd.SetOut(io.Discard) g.Expect(traitCmd.Execute()).To(Succeed()) } func TestKamelCompletionWorksOffline(t *testing.T) { - ctx := context.TODO() g := NewWithT(t) - bashCmd := Kamel(t, ctx, "completion", "bash", "--kube-config", "non-existent-kubeconfig-file") + bashCmd := Kamel(t, TestContext(), "completion", "bash", "--kube-config", "non-existent-kubeconfig-file") bashCmd.SetOut(io.Discard) - zshCmd := Kamel(t, ctx, "completion", "zsh", "--kube-config", "non-existent-kubeconfig-file") + zshCmd := Kamel(t, TestContext(), "completion", "zsh", "--kube-config", "non-existent-kubeconfig-file") zshCmd.SetOut(io.Discard) g.Expect(bashCmd.Execute()).To(Succeed()) g.Expect(zshCmd.Execute()).To(Succeed()) diff --git a/e2e/common/cli/version_test.go b/e2e/common/cli/version_test.go index 9e9399495..ee9bad90d 100644 --- a/e2e/common/cli/version_test.go +++ b/e2e/common/cli/version_test.go @@ -23,7 +23,6 @@ limitations under the License. package cli import ( - "context" "testing" . "github.com/onsi/gomega" @@ -33,11 +32,10 @@ import ( ) func TestKamelCLIVersion(t *testing.T) { - ctx := context.TODO() g := NewWithT(t) t.Run("check version correctness", func(t *testing.T) { - version := GetOutputString(Kamel(t, ctx, "version")) + version := GetOutputString(Kamel(t, TestContext(), "version")) g.Expect(version).To(ContainSubstring(defaults.Version)) }) } diff --git a/e2e/common/main_test.go b/e2e/common/main_test.go index f71348506..cd68bce9c 100644 --- a/e2e/common/main_test.go +++ b/e2e/common/main_test.go @@ -23,7 +23,6 @@ limitations under the License. package common import ( - "context" "fmt" "os" "testing" @@ -49,10 +48,10 @@ func TestMain(m *testing.M) { fmt.Printf("Test setup failed! - %s\n", message) }) - ctx := context.TODO() var t *testing.T g.Expect(TestClient(t)).ShouldNot(BeNil()) + ctx := TestContext() g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "languages/files/Java.java").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) diff --git a/e2e/install/kustomize/operator_test.go b/e2e/install/kustomize/operator_test.go index 820f60b05..20997cf74 100644 --- a/e2e/install/kustomize/operator_test.go +++ b/e2e/install/kustomize/operator_test.go @@ -41,7 +41,7 @@ func TestOperatorBasic(t *testing.T) { makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) - ctx := context.TODO() + ctx := TestContext() // Ensure no CRDs are already installed g := NewWithT(t) @@ -87,7 +87,7 @@ func TestOperatorKustomizeAlternativeImage(t *testing.T) { makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) - ctx := context.TODO() + ctx := TestContext() // Ensure no CRDs are already installed g := NewWithT(t) @@ -121,7 +121,7 @@ func TestOperatorKustomizeGlobal(t *testing.T) { makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) - ctx := context.TODO() + ctx := TestContext() // Ensure no CRDs are already installed g := NewWithT(t) diff --git a/e2e/install/kustomize/setup_test.go b/e2e/install/kustomize/setup_test.go index dac29d2e3..79a2d1b72 100644 --- a/e2e/install/kustomize/setup_test.go +++ b/e2e/install/kustomize/setup_test.go @@ -35,7 +35,7 @@ import ( ) func TestSetupKustomizeBasic(t *testing.T) { - ctx := context.TODO() + ctx := TestContext() g := NewWithT(t) makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) @@ -72,7 +72,7 @@ func TestSetupKustomizeGlobal(t *testing.T) { makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) - ctx := context.TODO() + ctx := TestContext() // Ensure no CRDs are already installed g := NewWithT(t) diff --git a/e2e/install/kustomize/uninstall_test.go b/e2e/install/kustomize/uninstall_test.go index a70971348..305fa7512 100644 --- a/e2e/install/kustomize/uninstall_test.go +++ b/e2e/install/kustomize/uninstall_test.go @@ -37,7 +37,7 @@ import ( ) func TestKustomizeUninstallBasic(t *testing.T) { - ctx := context.TODO() + ctx := TestContext() g := NewWithT(t) makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) @@ -83,7 +83,7 @@ func TestKustomizeUninstallBasic(t *testing.T) { } func TestUninstallGlobal(t *testing.T) { - ctx := context.TODO() + ctx := TestContext() g := NewWithT(t) makeDir := testutil.MakeTempCopyDir(t, "../../../install") os.Setenv("CAMEL_K_TEST_MAKE_DIR", makeDir) diff --git a/e2e/install/upgrade/helm_upgrade_test.go b/e2e/install/upgrade/helm_upgrade_test.go index 4e945a21b..4b95bc59a 100644 --- a/e2e/install/upgrade/helm_upgrade_test.go +++ b/e2e/install/upgrade/helm_upgrade_test.go @@ -41,7 +41,7 @@ import ( // WARNING: this test is not OLM specific but needs certain setting we provide in OLM installation scenario func TestHelmOperatorUpgrade(t *testing.T) { - ctx := context.TODO() + ctx := TestContext() g := NewWithT(t) KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY") diff --git a/e2e/knative/kamelet_test.go b/e2e/knative/kamelet_test.go index c7a8c3b26..5a495f733 100644 --- a/e2e/knative/kamelet_test.go +++ b/e2e/knative/kamelet_test.go @@ -23,7 +23,6 @@ limitations under the License. package knative import ( - "context" "fmt" "testing" @@ -39,7 +38,7 @@ import ( // Test that a Pipe can be changed and the changes are propagated to the Integration func TestKameletChange(t *testing.T) { - ctx := context.TODO() + ctx := TestContext() g := NewWithT(t) timerPipe := "timer-binding" diff --git a/e2e/knative/knative_test.go b/e2e/knative/knative_test.go index 9022f33cc..8cb1e624f 100644 --- a/e2e/knative/knative_test.go +++ b/e2e/knative/knative_test.go @@ -37,7 +37,7 @@ import ( ) func TestKnative(t *testing.T) { - ctx := context.TODO() + ctx := TestContext() g := NewWithT(t) knChannelMessages := "messages" diff --git a/e2e/knative/openapi_test.go b/e2e/knative/openapi_test.go index 8dd671265..a8f845718 100644 --- a/e2e/knative/openapi_test.go +++ b/e2e/knative/openapi_test.go @@ -23,7 +23,6 @@ limitations under the License. package knative import ( - "context" "testing" . "github.com/apache/camel-k/v2/e2e/support" @@ -33,7 +32,7 @@ import ( ) func TestOpenAPIService(t *testing.T) { - ctx := context.TODO() + ctx := TestContext() g := NewWithT(t) openapiContent, err := ioutil.ReadFile("./files/petstore-api.yaml") diff --git a/e2e/knative/pod_test.go b/e2e/knative/pod_test.go index 70c0ec851..de84434d4 100644 --- a/e2e/knative/pod_test.go +++ b/e2e/knative/pod_test.go @@ -23,7 +23,6 @@ limitations under the License. package knative import ( - "context" "testing" . "github.com/onsi/gomega" @@ -35,7 +34,7 @@ import ( ) func TestPodTraitWithKnative(t *testing.T) { - ctx := context.TODO() + ctx := TestContext() g := NewWithT(t) g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/podtest-knative2.groovy", "--pod-template", "files/template-knative.yaml").Execute()).To(Succeed()) diff --git a/e2e/support/test_nexus_hooks.go b/e2e/support/test_nexus_hooks.go index 7e671f394..83dbde575 100644 --- a/e2e/support/test_nexus_hooks.go +++ b/e2e/support/test_nexus_hooks.go @@ -23,7 +23,6 @@ limitations under the License. package support import ( - "context" "fmt" "os" @@ -54,7 +53,7 @@ func init() { Name: nexusService, } - if err := TestClient(nil).Get(context.TODO(), key, &svc); err != nil { + if err := TestClient(nil).Get(TestContext(), key, &svc); err != nil { svcExists = false } svcChecked = true diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index ddda64af5..4f527a3ee 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -136,6 +136,7 @@ var TestTimeoutVeryLong = 60 * time.Minute var NoOlmOperatorImage string +var testContext = context.TODO() var testClient client.Client var clientMutex = sync.Mutex{} @@ -155,6 +156,10 @@ func failTest(t *testing.T, err error) { } } +func TestContext() context.Context { + return testContext +} + func TestClient(t *testing.T) client.Client { clientMutex.Lock() defer clientMutex.Unlock() @@ -180,6 +185,7 @@ func RefreshClient(t *testing.T) client.Client { if err != nil { failTest(t, err) } + testContext = context.TODO() return testClient } @@ -2781,21 +2787,19 @@ func Pods(t *testing.T, ctx context.Context, ns string) func() []corev1.Pod { } func WithNewTestNamespace(t *testing.T, doRun func(context.Context, *gomega.WithT, string)) { - ctx := context.TODO() - ns := NewTestNamespace(t, ctx, false) - defer deleteTestNamespace(t, ctx, ns) + ns := NewTestNamespace(t, testContext, false) + defer deleteTestNamespace(t, testContext, ns) defer userCleanup(t) - invokeUserTestCode(t, ctx, ns.GetName(), doRun) + invokeUserTestCode(t, testContext, ns.GetName(), doRun) } func WithGlobalOperatorNamespace(t *testing.T, test func(context.Context, *gomega.WithT, string)) { - ctx := context.TODO() ocp, err := openshift.IsOpenShift(TestClient(t)) require.NoError(t, err) if ocp { // global operators are always installed in the openshift-operators namespace - invokeUserTestCode(t, ctx, "openshift-operators", test) + invokeUserTestCode(t, testContext, "openshift-operators", test) } else { // create new namespace for the global operator WithNewTestNamespace(t, test) @@ -2803,13 +2807,12 @@ func WithGlobalOperatorNamespace(t *testing.T, test func(context.Context, *gomeg } func WithNewTestNamespaceWithKnativeBroker(t *testing.T, doRun func(context.Context, *gomega.WithT, string)) { - ctx := context.TODO() - ns := NewTestNamespace(t, ctx, true) - defer deleteTestNamespace(t, ctx, ns) - defer deleteKnativeBroker(t, ctx, ns) + ns := NewTestNamespace(t, testContext, true) + defer deleteTestNamespace(t, testContext, ns) + defer deleteKnativeBroker(t, testContext, ns) defer userCleanup(t) - invokeUserTestCode(t, ctx, ns.GetName(), doRun) + invokeUserTestCode(t, testContext, ns.GetName(), doRun) } func userCleanup(t *testing.T) {