aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorenyinna1234 <enyinna.ochulor@intel.com>2020-03-02 09:09:46 -0800
committerenyinna1234 <enyinna.ochulor@intel.com>2020-03-05 04:58:16 -0800
commit59ead086a9fbd61cad2187f196b1176c20f98691 (patch)
treee658558be83f56792b6071b1c520460d11371a32
parent7b566f2875230e15f79a6549b17240e767cc98f1 (diff)
Change DB Name to accept variable
This enables the initialization of the mongo database name with a variable. Issue-ID: MULTICLOUD-996 Signed-off-by: Enyinna Ochulor <enyinna.ochulor@intel.com> Change-Id: Id3f07b47cedde16235ee7078e1e6f4d287106d29
-rw-r--r--src/orchestrator/cmd/main.go2
-rw-r--r--src/orchestrator/pkg/infra/db/store.go8
-rw-r--r--src/orchestrator/pkg/infra/db/store_test.go4
3 files changed, 7 insertions, 7 deletions
diff --git a/src/orchestrator/cmd/main.go b/src/orchestrator/cmd/main.go
index 179cf975..a4c46fe7 100644
--- a/src/orchestrator/cmd/main.go
+++ b/src/orchestrator/cmd/main.go
@@ -34,7 +34,7 @@ func main() {
rand.Seed(time.Now().UnixNano())
- err := db.InitializeDatabaseConnection()
+ err := db.InitializeDatabaseConnection("mco")
if err != nil {
log.Println("Unable to initialize database connection...")
log.Println(err)
diff --git a/src/orchestrator/pkg/infra/db/store.go b/src/orchestrator/pkg/infra/db/store.go
index 0cf3ef65..f8cb4466 100644
--- a/src/orchestrator/pkg/infra/db/store.go
+++ b/src/orchestrator/pkg/infra/db/store.go
@@ -64,12 +64,12 @@ type Store interface {
}
// CreateDBClient creates the DB client
-func createDBClient(dbType string) error {
+func createDBClient(dbType string, dbName string) error {
var err error
switch dbType {
case "mongo":
// create a mongodb database with orchestrator as the name
- DBconn, err = NewMongoStore("orchestrator", nil)
+ DBconn, err = NewMongoStore(dbName, nil)
default:
return pkgerrors.New(dbType + "DB not supported")
}
@@ -96,8 +96,8 @@ func DeSerialize(str string, v interface{}) error {
// InitializeDatabaseConnection sets up the connection to the
// configured database to allow the application to talk to it.
-func InitializeDatabaseConnection() error {
- err := createDBClient(config.GetConfiguration().DatabaseType)
+func InitializeDatabaseConnection(dbName string) error {
+ err := createDBClient(config.GetConfiguration().DatabaseType, dbName)
if err != nil {
return pkgerrors.Cause(err)
}
diff --git a/src/orchestrator/pkg/infra/db/store_test.go b/src/orchestrator/pkg/infra/db/store_test.go
index 42a41787..fb23e232 100644
--- a/src/orchestrator/pkg/infra/db/store_test.go
+++ b/src/orchestrator/pkg/infra/db/store_test.go
@@ -23,7 +23,7 @@ func TestCreateDBClient(t *testing.T) {
t.Run("Successfully create DB client", func(t *testing.T) {
expected := &MongoStore{}
- err := createDBClient("mongo")
+ err := createDBClient("mongo", "testdb")
if err != nil {
t.Fatalf("CreateDBClient returned an error (%s)", err)
}
@@ -32,7 +32,7 @@ func TestCreateDBClient(t *testing.T) {
}
})
t.Run("Fail to create client for unsupported DB", func(t *testing.T) {
- err := createDBClient("fakeDB")
+ err := createDBClient("fakeDB", "testdb2")
if err == nil {
t.Fatal("CreateDBClient didn't return an error")
}