From b6934336a3e07b6957dddbac326b07e5191fa15f Mon Sep 17 00:00:00 2001 From: Oleg Zhurakivskyy Date: Thu, 14 Jul 2022 19:28:26 +0300 Subject: [PATCH] envtest: Fix upgrade test fail when the tests for CRUD operations fail Closes #912 Signed-off-by: Oleg Zhurakivskyy --- test/envtest/dlbdeviceplugin_controller_test.go | 4 ++++ test/envtest/dsadeviceplugin_controller_test.go | 4 ++++ test/envtest/fpgadeviceplugin_controller_test.go | 4 ++++ test/envtest/gpudeviceplugin_controller_test.go | 4 ++++ test/envtest/iaadeviceplugin_controller_test.go | 4 ++++ test/envtest/qatdeviceplugin_controller_test.go | 4 ++++ test/envtest/sgxdeviceplugin_controller_test.go | 4 ++++ test/envtest/suite_test.go | 8 ++++++++ 8 files changed, 36 insertions(+) diff --git a/test/envtest/dlbdeviceplugin_controller_test.go b/test/envtest/dlbdeviceplugin_controller_test.go index 96f322ab..af5eebbe 100644 --- a/test/envtest/dlbdeviceplugin_controller_test.go +++ b/test/envtest/dlbdeviceplugin_controller_test.go @@ -128,4 +128,8 @@ var _ = Describe("DlbDevicePlugin Controller", func() { Expect(dp.Spec.Image == image).To(BeTrue()) }) + + var _ = AfterEach(func() { + CleanupAfter("dlb", &devicepluginv1.DlbDevicePlugin{}) + }) }) diff --git a/test/envtest/dsadeviceplugin_controller_test.go b/test/envtest/dsadeviceplugin_controller_test.go index ddb062eb..93ab191a 100644 --- a/test/envtest/dsadeviceplugin_controller_test.go +++ b/test/envtest/dsadeviceplugin_controller_test.go @@ -162,4 +162,8 @@ var _ = Describe("DsaDevicePlugin Controller", func() { Expect(dp.Spec.Image == image).To(BeTrue()) Expect(dp.Spec.InitImage == initimage).To(BeTrue()) }) + + var _ = AfterEach(func() { + CleanupAfter("dsa", &devicepluginv1.DsaDevicePlugin{}) + }) }) diff --git a/test/envtest/fpgadeviceplugin_controller_test.go b/test/envtest/fpgadeviceplugin_controller_test.go index 142f24b3..a22d6873 100644 --- a/test/envtest/fpgadeviceplugin_controller_test.go +++ b/test/envtest/fpgadeviceplugin_controller_test.go @@ -143,4 +143,8 @@ var _ = Describe("FpgaDevicePlugin Controller", func() { Expect(dp.Spec.Image == image).To(BeTrue()) Expect(dp.Spec.InitImage == initimage).To(BeTrue()) }) + + var _ = AfterEach(func() { + CleanupAfter("fpga", &devicepluginv1.FpgaDevicePlugin{}) + }) }) diff --git a/test/envtest/gpudeviceplugin_controller_test.go b/test/envtest/gpudeviceplugin_controller_test.go index 1f68dc6c..24b0bb52 100644 --- a/test/envtest/gpudeviceplugin_controller_test.go +++ b/test/envtest/gpudeviceplugin_controller_test.go @@ -147,4 +147,8 @@ var _ = Describe("GpuDevicePlugin Controller", func() { Expect(dp.Spec.Image == image).To(BeTrue()) Expect(dp.Spec.InitImage == initimage).To(BeTrue()) }) + + var _ = AfterEach(func() { + CleanupAfter("gpu", &devicepluginv1.GpuDevicePlugin{}) + }) }) diff --git a/test/envtest/iaadeviceplugin_controller_test.go b/test/envtest/iaadeviceplugin_controller_test.go index 4c7d44ec..caa8e69a 100644 --- a/test/envtest/iaadeviceplugin_controller_test.go +++ b/test/envtest/iaadeviceplugin_controller_test.go @@ -166,4 +166,8 @@ var _ = Describe("IaaDevicePlugin Controller", func() { Expect(dp.Spec.Image == image).To(BeTrue()) }) + + var _ = AfterEach(func() { + CleanupAfter("iaa", &devicepluginv1.IaaDevicePlugin{}) + }) }) diff --git a/test/envtest/qatdeviceplugin_controller_test.go b/test/envtest/qatdeviceplugin_controller_test.go index 293655e3..62600458 100644 --- a/test/envtest/qatdeviceplugin_controller_test.go +++ b/test/envtest/qatdeviceplugin_controller_test.go @@ -177,4 +177,8 @@ var _ = Describe("QatDevicePlugin Controller", func() { Expect(dp.Spec.Image == image).To(BeTrue()) Expect(dp.Spec.InitImage == initimage).To(BeTrue()) }) + + var _ = AfterEach(func() { + CleanupAfter("qat", &devicepluginv1.QatDevicePlugin{}) + }) }) diff --git a/test/envtest/sgxdeviceplugin_controller_test.go b/test/envtest/sgxdeviceplugin_controller_test.go index 0a964520..3f186caa 100644 --- a/test/envtest/sgxdeviceplugin_controller_test.go +++ b/test/envtest/sgxdeviceplugin_controller_test.go @@ -149,4 +149,8 @@ var _ = Describe("SgxDevicePlugin Controller", func() { Expect(dp.Spec.Image == image).To(BeTrue()) Expect(dp.Spec.InitImage == initimage).To(BeTrue()) }) + + var _ = AfterEach(func() { + CleanupAfter("sgx", &devicepluginv1.SgxDevicePlugin{}) + }) }) diff --git a/test/envtest/suite_test.go b/test/envtest/suite_test.go index dbc402db..a51483df 100644 --- a/test/envtest/suite_test.go +++ b/test/envtest/suite_test.go @@ -135,6 +135,14 @@ func up() { time.Sleep(time.Second) } +func CleanupAfter(name string, cr client.Object) { + namespacedName := types.NamespacedName{Namespace: ns, Name: name + "deviceplugin-test"} + + if err := k8sClient.Get(ctx, namespacedName, cr); err == nil { + Expect(k8sClient.Delete(ctx, cr)).Should(Succeed()) + } +} + func down() { time.Sleep(time.Second)