From 4f5d64f02bc558a6c93406d77bb1f24a2c9f29de Mon Sep 17 00:00:00 2001 From: Ryotaro Banno Date: Thu, 9 Jan 2025 01:20:27 +0000 Subject: [PATCH] test/e2e: multik8s: use SpecContext instead of context.Context when using Ginkgo Signed-off-by: Ryotaro Banno --- test/e2e/multik8s/changetoprimary/suite_test.go | 5 ++--- test/e2e/multik8s/changetosecondary/suite_test.go | 13 ++++++------- test/e2e/multik8s/changetostandalone/suite_test.go | 3 +-- test/e2e/multik8s/testutil/util.go | 10 +++++----- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/test/e2e/multik8s/changetoprimary/suite_test.go b/test/e2e/multik8s/changetoprimary/suite_test.go index 0e44aebc..45447572 100644 --- a/test/e2e/multik8s/changetoprimary/suite_test.go +++ b/test/e2e/multik8s/changetoprimary/suite_test.go @@ -1,7 +1,6 @@ package changetoprimary import ( - "context" "os" "testing" "time" @@ -54,7 +53,7 @@ func changePrimaryToStandaloneTemporarily() { | MB01, PVC1, MB10 (synced) */ - It("should replicate a MantleBackup resource", func(ctx context.Context) { + It("should replicate a MantleBackup resource", func(ctx SpecContext) { namespace = util.GetUniqueName("ns-") pvcName0 = util.GetUniqueName("pvc-") backupName00 = util.GetUniqueName("mb-") @@ -72,7 +71,7 @@ func changePrimaryToStandaloneTemporarily() { Expect(err).NotTo(HaveOccurred()) }) - It("should restore the synced MantleBackup in the both clusters", func(ctx context.Context) { + It("should restore the synced MantleBackup in the both clusters", func(ctx SpecContext) { restoreName00 := util.GetUniqueName("mr-") EnsureCorrectRestoration(PrimaryK8sCluster, ctx, namespace, backupName00, restoreName00, writtenDataHash00) EnsureCorrectRestoration(SecondaryK8sCluster, ctx, namespace, backupName00, restoreName00, writtenDataHash00) diff --git a/test/e2e/multik8s/changetosecondary/suite_test.go b/test/e2e/multik8s/changetosecondary/suite_test.go index f8874954..7e61d12c 100644 --- a/test/e2e/multik8s/changetosecondary/suite_test.go +++ b/test/e2e/multik8s/changetosecondary/suite_test.go @@ -1,7 +1,6 @@ package changetosecondary import ( - "context" "os" "testing" "time" @@ -60,7 +59,7 @@ func changeSecondaryToStandaloneTemporarily() { (MB10 don't exist) | */ - It("should set up the environment", func(ctx context.Context) { + It("should set up the environment", func(ctx SpecContext) { namespace = util.GetUniqueName("ns-") pvcName0 = util.GetUniqueName("pvc-") backupName00 = util.GetUniqueName("mb-") @@ -73,7 +72,7 @@ func changeSecondaryToStandaloneTemporarily() { SetupEnvironment(namespace) }) - It("should create and restore a MantleBackup resource", func(ctx context.Context) { + It("should create and restore a MantleBackup resource", func(ctx SpecContext) { CreatePVC(ctx, PrimaryK8sCluster, namespace, pvcName0) writtenDataHash00 = WriteRandomDataToPV(ctx, PrimaryK8sCluster, namespace, pvcName0) @@ -91,13 +90,13 @@ func changeSecondaryToStandaloneTemporarily() { Expect(err).NotTo(HaveOccurred()) }) - It("should restore the synced MantleBackup in the both clusters", func(ctx context.Context) { + It("should restore the synced MantleBackup in the both clusters", func(ctx SpecContext) { restoreName00 := util.GetUniqueName("mr-") EnsureCorrectRestoration(PrimaryK8sCluster, ctx, namespace, backupName00, restoreName00, writtenDataHash00) EnsureCorrectRestoration(SecondaryK8sCluster, ctx, namespace, backupName00, restoreName00, writtenDataHash00) }) - It("should create a MantleBackup resource in the secondary k8s cluster", func(ctx context.Context) { + It("should create a MantleBackup resource in the secondary k8s cluster", func(ctx SpecContext) { CreatePVC(ctx, SecondaryK8sCluster, namespace, pvcName1) writtenDataHash10 = WriteRandomDataToPV(ctx, SecondaryK8sCluster, namespace, pvcName1) CreateMantleBackup(SecondaryK8sCluster, namespace, pvcName1, backupName10) @@ -105,7 +104,7 @@ func changeSecondaryToStandaloneTemporarily() { }) It("should ensure the MantleBackup created by standalone mantle doesn't exist in the primary k8s cluster", - func(ctx context.Context) { + func(ctx SpecContext) { EnsureMantleBackupNotExist(ctx, PrimaryK8sCluster, namespace, backupName10) }) @@ -145,7 +144,7 @@ func changeSecondaryToStandaloneTemporarily() { }) It("should ensure the MantleBackup created by standalone mantle doesn't exist in the primary k8s cluster", - func(ctx context.Context) { + func(ctx SpecContext) { EnsureMantleBackupNotExist(ctx, PrimaryK8sCluster, namespace, backupName10) }) }) diff --git a/test/e2e/multik8s/changetostandalone/suite_test.go b/test/e2e/multik8s/changetostandalone/suite_test.go index 5369971a..aca39eaa 100644 --- a/test/e2e/multik8s/changetostandalone/suite_test.go +++ b/test/e2e/multik8s/changetostandalone/suite_test.go @@ -1,7 +1,6 @@ package changetostandalone import ( - "context" "encoding/json" "os" "testing" @@ -38,7 +37,7 @@ func changeToStandalone() { Describe("change to standalone", func() { var namespace, pvcName, backupName string - It("should replicate a MantleBackup resource", func(ctx context.Context) { + It("should replicate a MantleBackup resource", func(ctx SpecContext) { namespace = util.GetUniqueName("ns-") pvcName = util.GetUniqueName("pvc-") backupName = util.GetUniqueName("mb-") diff --git a/test/e2e/multik8s/testutil/util.go b/test/e2e/multik8s/testutil/util.go index eb624297..0c7e1604 100644 --- a/test/e2e/multik8s/testutil/util.go +++ b/test/e2e/multik8s/testutil/util.go @@ -410,13 +410,13 @@ func SetupEnvironment(namespace string) { }).Should(Succeed()) } -func CreatePVC(ctx context.Context, cluster int, namespace, name string) { +func CreatePVC(ctx SpecContext, cluster int, namespace, name string) { Eventually(ctx, func() error { return applyPVCTemplate(cluster, namespace, name) }).Should(Succeed()) } -func WriteRandomDataToPV(ctx context.Context, cluster int, namespace, pvcName string) string { +func WriteRandomDataToPV(ctx SpecContext, cluster int, namespace, pvcName string) string { GinkgoHelper() By("writing some random data to PV(C)") writeJobName := util.GetUniqueName("job-") @@ -472,7 +472,7 @@ func WaitMantleBackupSynced(namespace, backupName string) { }, "10m", "1s").Should(Succeed()) } -func EnsureMantleBackupNotExist(ctx context.Context, cluster int, namespace, backupName string) { +func EnsureMantleBackupNotExist(ctx SpecContext, cluster int, namespace, backupName string) { By("checking MantleBackup doesn't exist") Consistently(ctx, func(g Gomega) { mbs, err := GetMBList(cluster, namespace) @@ -484,7 +484,7 @@ func EnsureMantleBackupNotExist(ctx context.Context, cluster int, namespace, bac }, "10s").Should(Succeed()) } -func EnsureTemporaryResourcesDeleted(ctx context.Context) { +func EnsureTemporaryResourcesDeleted(ctx SpecContext) { GinkgoHelper() By("checking all temporary Jobs related to export and import of RBD images are removed") primaryJobList, err := GetObjectList[batchv1.JobList](PrimaryK8sCluster, "job", CephClusterNamespace) @@ -536,7 +536,7 @@ func EnsureTemporaryResourcesDeleted(ctx context.Context) { func EnsureCorrectRestoration( clusterNo int, - ctx context.Context, + ctx SpecContext, namespace, backupName, restoreName, writtenDataHash string, ) { GinkgoHelper()