Skip to content

Commit

Permalink
test/e2e: multik8s: use SpecContext instead of context.Context when u…
Browse files Browse the repository at this point in the history
…sing Ginkgo

Signed-off-by: Ryotaro Banno <[email protected]>
  • Loading branch information
ushitora-anqou committed Jan 20, 2025
1 parent 11ec828 commit 4f5d64f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
5 changes: 2 additions & 3 deletions test/e2e/multik8s/changetoprimary/suite_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package changetoprimary

import (
"context"
"os"
"testing"
"time"
Expand Down Expand Up @@ -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-")
Expand All @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions test/e2e/multik8s/changetosecondary/suite_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package changetosecondary

import (
"context"
"os"
"testing"
"time"
Expand Down Expand Up @@ -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-")
Expand All @@ -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)
Expand All @@ -91,21 +90,21 @@ 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)
WaitMantleBackupReadyToUse(SecondaryK8sCluster, namespace, backupName10)
})

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)
})

Expand Down Expand Up @@ -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)
})
})
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/multik8s/changetostandalone/suite_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package changetostandalone

import (
"context"
"encoding/json"
"os"
"testing"
Expand Down Expand Up @@ -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-")
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/multik8s/testutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -536,7 +536,7 @@ func EnsureTemporaryResourcesDeleted(ctx context.Context) {

func EnsureCorrectRestoration(
clusterNo int,
ctx context.Context,
ctx SpecContext,
namespace, backupName, restoreName, writtenDataHash string,
) {
GinkgoHelper()
Expand Down

0 comments on commit 4f5d64f

Please sign in to comment.