|
| 1 | +package replica_set_custom_persistentvolumclaimretentionpolicy_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "os" |
| 7 | + "testing" |
| 8 | + |
| 9 | + e2eutil "github.com/mongodb/mongodb-kubernetes-operator/test/e2e" |
| 10 | + "github.com/mongodb/mongodb-kubernetes-operator/test/e2e/mongodbtests" |
| 11 | + "github.com/mongodb/mongodb-kubernetes-operator/test/e2e/setup" |
| 12 | + . "github.com/mongodb/mongodb-kubernetes-operator/test/e2e/util/mongotester" |
| 13 | + appsv1 "k8s.io/api/apps/v1" |
| 14 | +) |
| 15 | + |
| 16 | +func TestMain(m *testing.M) { |
| 17 | + code, err := e2eutil.RunTest(m) |
| 18 | + if err != nil { |
| 19 | + fmt.Println(err) |
| 20 | + } |
| 21 | + os.Exit(code) |
| 22 | +} |
| 23 | + |
| 24 | +func TestReplicaSetCustomPersistentVolumeClaimRetentionPolicy(t *testing.T) { |
| 25 | + ctx := context.Background() |
| 26 | + testCtx := setup.Setup(ctx, t) |
| 27 | + defer testCtx.Teardown() |
| 28 | + |
| 29 | + 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 |
| 34 | + scramUser := mdb.GetAuthUsers()[0] |
| 35 | + |
| 36 | + _, err := setup.GeneratePasswordForUser(testCtx, user, "") |
| 37 | + if err != nil { |
| 38 | + t.Fatal(err) |
| 39 | + } |
| 40 | + |
| 41 | + tester, err := FromResource(ctx, t, mdb) |
| 42 | + if err != nil { |
| 43 | + t.Fatal(err) |
| 44 | + } |
| 45 | + |
| 46 | + t.Run("Create MongoDB Resource", mongodbtests.CreateMongoDBResource(&mdb, testCtx)) |
| 47 | + t.Run("Basic tests", mongodbtests.BasicFunctionality(ctx, &mdb)) |
| 48 | + t.Run("Keyfile authentication is configured", tester.HasKeyfileAuth(3)) |
| 49 | + t.Run("Test Basic Connectivity", tester.ConnectivitySucceeds()) |
| 50 | + t.Run("Test SRV Connectivity", tester.ConnectivitySucceeds(WithURI(mdb.MongoSRVURI("")), WithoutTls(), WithReplicaSet((mdb.Name)))) |
| 51 | + t.Run("Test Basic Connectivity with generated connection string secret", |
| 52 | + tester.ConnectivitySucceeds(WithURI(mongodbtests.GetConnectionStringForUser(ctx, mdb, scramUser)))) |
| 53 | + t.Run("Test SRV Connectivity with generated connection string secret", |
| 54 | + tester.ConnectivitySucceeds(WithURI(mongodbtests.GetSrvConnectionStringForUser(ctx, mdb, scramUser)))) |
| 55 | + t.Run("Ensure Authentication", tester.EnsureAuthenticationIsConfigured(3)) |
| 56 | + 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())) |
| 59 | +} |
0 commit comments