Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/cluster/is_master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
"github.com/percona/mongodb-backup/mdbstructs"
)

func TestGetIsMaster(t *testing.T) {
func TestIsMaster(t *testing.T) {
session, err := mgo.DialWithInfo(testutils.PrimaryDialInfo())
if err != nil {
t.Fatalf("Could not connect to primary: %v", err.Error())
}
defer session.Close()

isMaster, err := GetIsMaster(session)
isMaster, err := IsMaster(session)
if err != nil {
t.Fatalf("Could not run 'isMaster' command: %v", err.Error())
}
Expand All @@ -40,7 +40,7 @@ func TestIsReplset(t *testing.T) {
}
defer session.Close()

isMaster, err := GetIsMaster(session)
isMaster, err := IsMaster(session)
if err != nil {
session.Close()
t.Fatalf("Could not run 'isMaster' command: %v", err.Error())
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestIsMongos(t *testing.T) {
}
defer session.Close()

isMaster, err := GetIsMaster(session)
isMaster, err := IsMaster(session)
if err != nil {
session.Close()
t.Fatalf("Could not run 'isMaster' command: %v", err.Error())
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestIsConfigServer(t *testing.T) {
}
defer session.Close()

isMaster, err := GetIsMaster(session)
isMaster, err := IsMaster(session)
if err != nil {
session.Close()
t.Fatalf("Could not run 'isMaster' command: %v", err.Error())
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestIsShardedCluster(t *testing.T) {
}
defer session.Close()

isMaster, err := GetIsMaster(session)
isMaster, err := IsMaster(session)
if err != nil {
session.Close()
t.Fatalf("Could not run 'isMaster' command: %v", err.Error())
Expand Down
7 changes: 6 additions & 1 deletion internal/cluster/replset.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func GetStatus(session *mgo.Session) (*mdbstructs.ReplsetStatus, error) {
return &status, err
}

// GetReplsetID returns the replica set ID
// GetReplsetName returns the replica set name as a string
func GetReplsetName(config *mdbstructs.ReplsetConfig) string {
return config.Name
}

// GetReplsetID returns the replica set ID as a bson.ObjectId
func GetReplsetID(config *mdbstructs.ReplsetConfig) *bson.ObjectId {
return &config.Settings.ReplicaSetId
}
Expand Down
15 changes: 15 additions & 0 deletions internal/cluster/replset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ func TestGetStatus(t *testing.T) {
}
}

func TestGetReplsetName(t *testing.T) {
session, err := mgo.DialWithInfo(testutils.PrimaryDialInfo())
if err != nil {
t.Fatalf("Could not connect to replset: %v", err.Error())
}
defer session.Close()

config, err := GetConfig(session)
if err != nil {
t.Fatalf("Failed to run .GetConfig() on Replset struct: %v", err.Error())
} else if GetReplsetName(config) != testutils.MongoDBReplsetName {
t.Fatal("Got unexpected output from .GetReplsetName()")
}
}

func TestGetReplsetID(t *testing.T) {
session, err := mgo.DialWithInfo(testutils.PrimaryDialInfo())
if err != nil {
Expand Down