From 6867541c5d2bb839bf30ef7cf6a3461eabe84fa2 Mon Sep 17 00:00:00 2001 From: adrianc Date: Mon, 29 Jan 2024 15:15:34 +0200 Subject: [PATCH] e2e tests enhancements - remove deprecated use of async node - fail if creating client returned nil - use ptr pkg instead of pointer package as its deprecated Signed-off-by: adrianc --- test/conformance/tests/init.go | 3 +++ test/e2e/e2e_tests_suite_test.go | 8 +++----- test/e2e/sriovoperatornodepolicy_test.go | 2 ++ test/util/clean/clean.go | 4 ++++ test/validation/tests/test_validation.go | 19 ++++++++++--------- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/test/conformance/tests/init.go b/test/conformance/tests/init.go index 56b836dd9..99458e8dc 100644 --- a/test/conformance/tests/init.go +++ b/test/conformance/tests/init.go @@ -18,4 +18,7 @@ func init() { } clients = testclient.New("") + if clients == nil { + panic("failed package init, failed to create ClientSet") + } } diff --git a/test/e2e/e2e_tests_suite_test.go b/test/e2e/e2e_tests_suite_test.go index d6c132d14..920def35a 100644 --- a/test/e2e/e2e_tests_suite_test.go +++ b/test/e2e/e2e_tests_suite_test.go @@ -13,7 +13,7 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -55,7 +55,7 @@ func TestSriovTests(t *testing.T) { var sriovIface *sriovnetworkv1.InterfaceExt -var _ = BeforeSuite(func(done Done) { +var _ = BeforeSuite(func() { logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) // Go to project root directory @@ -64,7 +64,7 @@ var _ = BeforeSuite(func(done Done) { By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("config", "crd", "bases"), filepath.Join("test", "util", "crds")}, - UseExistingCluster: pointer.BoolPtr(true), + UseExistingCluster: ptr.To[bool](true), } var err error @@ -102,8 +102,6 @@ var _ = BeforeSuite(func(done Done) { doneNetNsSet = make(chan error, 1) go netns.SetPfVfLinkNetNs(testPciDev, testNsPath, devPollInterval, quitNetNsSet, doneNetNsSet) } - - close(done) }) var _ = AfterSuite(func() { diff --git a/test/e2e/sriovoperatornodepolicy_test.go b/test/e2e/sriovoperatornodepolicy_test.go index 891c06d12..ba2ec5e64 100644 --- a/test/e2e/sriovoperatornodepolicy_test.go +++ b/test/e2e/sriovoperatornodepolicy_test.go @@ -28,6 +28,8 @@ var _ = Describe("Operator", func() { execute.BeforeAll(func() { clients := testclient.New("") + Expect(clients).ToNot(BeNil()) + Eventually(func() *cluster.EnabledNodes { sriovInfos, _ = cluster.DiscoverSriov(clients, testNamespace) return sriovInfos diff --git a/test/util/clean/clean.go b/test/util/clean/clean.go index 74e6b13d3..fbc1ae1c4 100644 --- a/test/util/clean/clean.go +++ b/test/util/clean/clean.go @@ -20,6 +20,10 @@ func All() error { operatorNamespace = "openshift-sriov-network-operator" } clients := client.New("") + if clients == nil { + return fmt.Errorf("failed to create ClientSet") + } + if RestoreNodeDrainState { err := cluster.SetDisableNodeDrainState(clients, operatorNamespace, false) if err != nil { diff --git a/test/validation/tests/test_validation.go b/test/validation/tests/test_validation.go index 0df4fefb9..4c7980389 100644 --- a/test/validation/tests/test_validation.go +++ b/test/validation/tests/test_validation.go @@ -24,15 +24,6 @@ var ( operatorNamespace string ) -func init() { - operatorNamespace = os.Getenv("OPERATOR_NAMESPACE") - if operatorNamespace == "" { - operatorNamespace = "openshift-sriov-network-operator" - } - - clients = testclient.New("") -} - const ( sriovOperatorDeploymentName = "sriov-network-operator" // SriovNetworkNodePolicies contains the name of the sriov network node policies CRD @@ -45,6 +36,16 @@ const ( sriovOperatorConfigs = "sriovoperatorconfigs.sriovnetwork.openshift.io" ) +var _ = BeforeSuite(func() { + operatorNamespace = os.Getenv("OPERATOR_NAMESPACE") + if operatorNamespace == "" { + operatorNamespace = "openshift-sriov-network-operator" + } + + clients = testclient.New("") + Expect(clients).ToNot(BeNil()) +}) + var _ = Describe("validation", func() { Context("sriov", func() {