Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit d442b05

Browse files
committed
feat: add e2e test for persistentVolumeClaimRetentionPolicy
1 parent ba6a98b commit d442b05

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

config/samples/mongodb.com_v1_mongodbcommunity_persistent_volume_claim_retention_policy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
apiVersion: mongodbcommunity.mongodb.com/v1
33
kind: MongoDBCommunity
44
metadata:
5-
name: mongodb-specify-readiness-probe-values
5+
name: mongodb-specify-volumeclaimretention-values
66
spec:
77
members: 3
88
type: ReplicaSet

test/e2e/replica_set_custom_persistentvolumclaimretentionpolicy_test/replica_set_custom_persistentvolumeclaimretentionpolicy_test.go renamed to test/e2e/replica_set_custom_persistentvolumeclaimretentionpolicy_test/replica_set_custom_persistentvolumeclaimretentionpolicy_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ func TestReplicaSetCustomPersistentVolumeClaimRetentionPolicy(t *testing.T) {
2727
defer testCtx.Teardown()
2828

2929
mdb, user := e2eutil.NewTestMongoDB(testCtx, "mdb0", "")
30-
var test appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy
31-
test.WhenDeleted = "Deleted"
32-
test.WhenScaled = "Deleted"
33-
mdb.Spec.StatefulSetConfiguration.SpecWrapper.Spec.PersistentVolumeClaimRetentionPolicy = &test
30+
overridePersistentVolumeClaim := appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{WhenDeleted: "Delete", WhenScaled: "Delete"}
31+
mdb.Spec.StatefulSetConfiguration.SpecWrapper.Spec.PersistentVolumeClaimRetentionPolicy = &overridePersistentVolumeClaim
3432
scramUser := mdb.GetAuthUsers()[0]
3533

3634
_, err := setup.GeneratePasswordForUser(testCtx, user, "")
@@ -54,6 +52,5 @@ func TestReplicaSetCustomPersistentVolumeClaimRetentionPolicy(t *testing.T) {
5452
tester.ConnectivitySucceeds(WithURI(mongodbtests.GetSrvConnectionStringForUser(ctx, mdb, scramUser))))
5553
t.Run("Ensure Authentication", tester.EnsureAuthenticationIsConfigured(3))
5654
t.Run("AutomationConfig has the correct version", mongodbtests.AutomationConfigVersionHasTheExpectedVersion(ctx, &mdb, 1))
57-
t.Run("Statefulset has the expectd PersistentVolumeClaimRetentionPolicy", mongodbtests.StatefulSetHasPersistentVolumeClaimRetentionPolicy(ctx, &mdb, test))
58-
t.Run("Cluster has the expected labels and annotations", mongodbtests.HasExpectedMetadata(ctx, &mdb, e2eutil.TestLabels(), e2eutil.TestAnnotations()))
55+
t.Run("Statefulset has the expected PersistentVolumeClaimRetentionPolicy", mongodbtests.StatefulSetHasPersistentVolumeClaimRetentionPolicy(ctx, &mdb, overridePersistentVolumeClaim))
5956
}

test/e2e/util/wait/wait.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ func ForStatefulSetToHaveUpdateStrategy(ctx context.Context, t *testing.T, mdb *
102102
func ForStatefulSetToHavePersistentVolumeClaimRetentionPolicy(ctx context.Context, t *testing.T, mdb *mdbv1.MongoDBCommunity, persistentVolumeClaimRetentionPolicy appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy, opts ...Configuration) error {
103103
options := newOptions(opts...)
104104
return waitForStatefulSetCondition(ctx, t, mdb, options, func(sts appsv1.StatefulSet) bool {
105-
return sts.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled == persistentVolumeClaimRetentionPolicy.WhenScaled
105+
if sts.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled == persistentVolumeClaimRetentionPolicy.WhenScaled && sts.Spec.PersistentVolumeClaimRetentionPolicy.WhenDeleted == persistentVolumeClaimRetentionPolicy.WhenDeleted {
106+
return true
107+
}
108+
return false
106109
})
107110
}
108111

0 commit comments

Comments
 (0)