Skip to content
Merged
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
77 changes: 57 additions & 20 deletions db/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,61 @@ import (
)

func Test_ClientConnection(t *testing.T) {
config := &MongoConfig{
Host: "localhost",
Port: "27017",
Username: "root",
Password: "password",
}

client, err := NewMongoClient(config)

if err != nil {
t.Errorf("failed to connect to mongo DB Error: %s", err)
return
}

err = client.HealthCheck(context.Background())
if err != nil {
t.Errorf("failed to perform Health check with DB Error: %s", err)
}

_ = client.GetDataStore("test")
t.Run("Valid_Auth_Config", func(t *testing.T) {
config := &MongoConfig{
Host: "localhost",
Port: "27017",
Username: "root",
Password: "password",
}

client, err := NewMongoClient(config)

if err != nil {
t.Errorf("failed to connect to mongo DB Error: %s", err)
return
}

err = client.HealthCheck(context.Background())
if err != nil {
t.Errorf("failed to perform Health check with DB Error: %s", err)
}

_ = client.GetDataStore("test")
})

t.Run("InValid_Port", func(t *testing.T) {
config := &MongoConfig{
Host: "localhost",
Port: "abc",
Username: "root",
Password: "badPassword",
}
_, err := NewMongoClient(config)

if err == nil {
t.Errorf("Connection succeeded while using invalid port number")
return
}
})

t.Run("InValid_Auth_Config", func(t *testing.T) {
config := &MongoConfig{
Host: "localhost",
Port: "27017",
Username: "root",
Password: "badPassword",
}
client, err := NewMongoClient(config)

if err != nil {
t.Errorf("failed to connect to mongo DB Error: %s", err)
return
}

err = client.HealthCheck(context.Background())
if err == nil {
t.Errorf("Health Check for mongo DB passed while using wrong password")
}
})
}