From 1391f1e9295852b0e1fcca413c0eda16fe274fe8 Mon Sep 17 00:00:00 2001 From: Rajdeep Das Date: Thu, 25 Jan 2024 15:45:10 +0000 Subject: [PATCH] add e2e test --- controllers/replica_set_controller.go | 7 ++++++- test/e2e/mongodbtests/mongodbtests.go | 7 +++++++ test/e2e/replica_set/replica_set_test.go | 11 ++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/controllers/replica_set_controller.go b/controllers/replica_set_controller.go index 3d6c9c9d4..e643fa942 100644 --- a/controllers/replica_set_controller.go +++ b/controllers/replica_set_controller.go @@ -539,6 +539,11 @@ func buildAutomationConfig(mdb mdbv1.MongoDBCommunity, auth automationconfig.Aut arbitersCount = mdb.Status.CurrentMongoDBArbiters } + var acOverrideSettings map[string]interface{} + if mdb.Spec.AutomationConfigOverride != nil { + acOverrideSettings = mdb.Spec.AutomationConfigOverride.ReplicaSet.Settings.Object + } + return automationconfig.NewBuilder(). IsEnterprise(guessEnterprise(mdb)). SetTopology(automationconfig.ReplicaSetTopology). @@ -553,7 +558,7 @@ func buildAutomationConfig(mdb mdbv1.MongoDBCommunity, auth automationconfig.Aut SetFCV(mdb.Spec.FeatureCompatibilityVersion). SetOptions(automationconfig.Options{DownloadBase: "/var/lib/mongodb-mms-automation"}). SetAuth(auth). - SetSettings(mdb.Spec.AutomationConfigOverride.ReplicaSet.Settings.Object). + SetSettings(acOverrideSettings). SetMemberOptions(mdb.Spec.MemberConfig). SetDataDir(mdb.GetMongodConfiguration().GetDBDataDir()). AddModifications(getMongodConfigModification(mdb)). diff --git a/test/e2e/mongodbtests/mongodbtests.go b/test/e2e/mongodbtests/mongodbtests.go index 2f33ab00a..f01396cd1 100644 --- a/test/e2e/mongodbtests/mongodbtests.go +++ b/test/e2e/mongodbtests/mongodbtests.go @@ -398,6 +398,13 @@ func AutomationConfigHasLogRotationConfig(mdb *mdbv1.MongoDBCommunity, lrc *auto } } +func AutomationConfigHasSettings(mdb *mdbv1.MongoDBCommunity, settings map[string]interface{}) func(t *testing.T) { + return func(t *testing.T) { + currentAc := getAutomationConfig(t, mdb) + assert.Equal(t, currentAc.ReplicaSets[0].Settings, settings) + } +} + // AutomationConfigReplicaSetsHaveExpectedArbiters verifies that the automation config has the expected version. func AutomationConfigReplicaSetsHaveExpectedArbiters(mdb *mdbv1.MongoDBCommunity, expectedArbiters int) func(t *testing.T) { return func(t *testing.T) { diff --git a/test/e2e/replica_set/replica_set_test.go b/test/e2e/replica_set/replica_set_test.go index cfee78364..c353a6a07 100644 --- a/test/e2e/replica_set/replica_set_test.go +++ b/test/e2e/replica_set/replica_set_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + v1 "github.com/mongodb/mongodb-kubernetes-operator/api/v1" "github.com/mongodb/mongodb-kubernetes-operator/pkg/automationconfig" e2eutil "github.com/mongodb/mongodb-kubernetes-operator/test/e2e" "github.com/mongodb/mongodb-kubernetes-operator/test/e2e/mongodbtests" @@ -77,6 +78,13 @@ func TestReplicaSet(t *testing.T) { } mdb.Spec.MemberConfig = memberOptions + settings := map[string]interface{}{ + "electionTimeoutMillis": float64(20), + } + mdb.Spec.AutomationConfigOverride = &v1.AutomationConfigOverride{ + ReplicaSet: v1.OverrideReplicaSet{Settings: v1.MapWrapper{Object: settings}}, + } + tester, err := FromResource(t, mdb) if err != nil { t.Fatal(err) @@ -94,5 +102,6 @@ func TestReplicaSet(t *testing.T) { tester.ConnectivitySucceeds(WithURI(mongodbtests.GetSrvConnectionStringForUser(mdb, scramUser)))) t.Run("Ensure Authentication", tester.EnsureAuthenticationIsConfigured(3)) t.Run("AutomationConfig has the correct version", mongodbtests.AutomationConfigVersionHasTheExpectedVersion(&mdb, 1)) - t.Run("AutomationCondig has correct member options", mongodbtests.AutomationConfigHasVoteTagPriorityConfigured(&mdb, memberOptions)) + t.Run("AutomationConfig has correct member options", mongodbtests.AutomationConfigHasVoteTagPriorityConfigured(&mdb, memberOptions)) + t.Run("AutomationConfig has correct settings", mongodbtests.AutomationConfigHasSettings(&mdb, settings)) }