Skip to content

Commit

Permalink
add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
irajdeep committed Jan 25, 2024
1 parent 27d85d4 commit 1391f1e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion controllers/replica_set_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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)).
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/mongodbtests/mongodbtests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion test/e2e/replica_set/replica_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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))
}

0 comments on commit 1391f1e

Please sign in to comment.