Skip to content

Commit

Permalink
Merge pull request #31 from cybozu-go/stabilize-e2e-tests
Browse files Browse the repository at this point in the history
test/e2e: check ReadyToUse before checking it remains
  • Loading branch information
satoru-takeuchi authored Jul 12, 2024
2 parents 1cf3c5c + 6776079 commit 5710628
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
25 changes: 15 additions & 10 deletions test/e2e/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import (
"github.com/cybozu-go/mantle/test/util"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
)

const (
Expand Down Expand Up @@ -154,6 +151,18 @@ func (test *backupTest) testCase1() {

return checkSnapshotExist(cephCluster1Namespace, test.poolName, imageName, test.mantleBackupName3)
}).Should(Succeed())

By("Checking that the status.conditions of the MantleBackup resource becomes \"ReadyToUse\"")
Eventually(func() error {
ready, err := isMantleBackupReady(test.tenantNamespace, test.mantleBackupName3)
if err != nil {
return err
}
if !ready {
return fmt.Errorf("not ready")
}
return nil
}).Should(Succeed())
})

It("should not delete MantleBackup resource when delete backup target PVC", func() {
Expand All @@ -173,14 +182,10 @@ func (test *backupTest) testCase1() {
return fmt.Errorf("PVC %s still exists. stdout: %s", test.pvcName2, stdout)
}).Should(Succeed())

By("Checking that the status.conditions of the MantleBackup resource remain \"Bound\"")
stdout, _, err := kubectl("-n", test.tenantNamespace, "get", "mantlebackup", test.mantleBackupName3, "-o", "json")
Expect(err).NotTo(HaveOccurred())
var backup mantlev1.MantleBackup
err = yaml.Unmarshal(stdout, &backup)
By("Checking that the status.conditions of the MantleBackup resource remain \"ReadyToUse\"")
ready, err := isMantleBackupReady(test.tenantNamespace, test.mantleBackupName3)
Expect(err).NotTo(HaveOccurred())
Expect(meta.FindStatusCondition(backup.Status.Conditions, mantlev1.BackupConditionReadyToUse).Status).
To(Equal(metav1.ConditionTrue))
Expect(ready).To(Equal(true))
})

It("should delete MantleBackup resource", func() {
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
mantlev1 "github.com/cybozu-go/mantle/api/v1"
"github.com/cybozu-go/mantle/internal/controller"
testutil "github.com/cybozu-go/mantle/test/util"
"gopkg.in/yaml.v2"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -401,6 +402,20 @@ func getRBDInfo(clusterNS, pool, image string) (*rbdInfo, error) {
return &info, nil
}

func isMantleBackupReady(namespace, name string) (bool, error) {
stdout, _, err := kubectl("-n", namespace, "get", "mantlebackup", name, "-o", "json")
if err != nil {
return false, err
}
var backup mantlev1.MantleBackup
err = yaml.Unmarshal(stdout, &backup)
if err != nil {
return false, err
}
cond := meta.FindStatusCondition(backup.Status.Conditions, mantlev1.BackupConditionReadyToUse).Status
return cond == metav1.ConditionTrue, nil
}

func isMantleRestoreReady(namespace, name string) bool {
stdout, stderr, err := kubectl("get", "mantlerestore", "-n", namespace, name, "-o", "json")
if err != nil {
Expand Down

0 comments on commit 5710628

Please sign in to comment.