Commit d1fe9083 authored by Axel's avatar Axel
Browse files

US-177: Correcting mgdb lib

parent 65c3cf1f
......@@ -33,12 +33,12 @@ type MongoManager struct {
Collections map[string]*MongoCollection
}
// NewManager a new Manager, the environment variable MONGOHQ_URL needs to be set
// NewManager a new Manager, the environment variable 'connection' needs to be set
// up with mongo uri, else it throws an error
func NewManager(database string) (*MongoManager, error) {
uri := os.Getenv("MGDB_URL")
func NewManager(database, connection string) (*MongoManager, error) {
uri := os.Getenv(connection)
if uri == "" {
err := newErrorConnection("No uri provided, please set the MONGOHG_URL to connect to mongo")
err := newErrorConnection("No uri provided, please set the " + connection + " environment variable to connect to mongo")
return nil, err
}
......
......@@ -19,20 +19,22 @@ type hand struct {
CardTwo card `key:"card_two" bson:"card_two"`
}
const defaultDBUrl = "MGDB_URL"
var collection *MongoCollection
var manager *MongoManager
var err error
func TestMain(m *testing.M) {
// Setup
fmt.Println("Try to connect to : " + os.Getenv("MGDB_URL"))
fmt.Println("Try to connect to : " + os.Getenv(defaultDBUrl))
db := os.Getenv("DFSS_TEST")
db := os.Getenv(defaultDBUrl)
if db == "" {
db = "demo"
}
manager, err = NewManager(db)
manager, err = NewManager(db, defaultDBUrl)
collection = manager.Get("demo")
......@@ -185,7 +187,7 @@ func ExampleMongoManager() {
}
//Initializes a MongoManager for the 'demo' database
manager, err := NewManager("demo")
manager, err := NewManager("demo", defaultDBUrl)
if err != nil { /* Handle error */
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment