// setupGraph initializes an in-memory Cayley graph and logging for an individual test. func setupGraph(t *testing.T) (*db.DB, *cayley.Handle, []map[string]interface{}) { tests.ResetLog() items, _, _, _, err := wirefix.Get() if err != nil { t.Fatalf("%s\tShould load item records from the fixture file : %v", tests.Failed, err) } t.Logf("%s\tShould load item records from the fixture file.", tests.Success) db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("%s\tShould be able to get a Mongo session : %v", tests.Failed, err) } store, err := cayley.NewMemoryGraph() if err != nil { t.Fatalf("\t%s\tShould be able to create a new Cayley graph : %v", tests.Failed, err) } t.Logf("\t%s\tShould be able to create a new Cayley graph.", tests.Success) // Convert the items to maps. var itemMaps []map[string]interface{} for _, itm := range items { itemMap := map[string]interface{}{ "type": itm.Type, "item_id": itm.ID, "version": itm.Version, "data": itm.Data, } itemMaps = append(itemMaps, itemMap) } return db, store, itemMaps }
func main() { app.Init(cfg.EnvProvider{Namespace: Namespace}) // Pull options from the config. var conn *db.DB if _, errHost := cfg.String(cfgWebHost); errHost != nil { xenia.Println("Configuring MongoDB") mongoURI := cfg.MustURL(cfgMongoURI) err := db.RegMasterSession("startup", mongoURI.Path, mongoURI.String(), 0) if err != nil { xenia.Println("Unable to initialize MongoDB") os.Exit(1) } conn, err = db.NewMGO("startup", mongoURI.Path) if err != nil { xenia.Println("Unable to get MongoDB session") os.Exit(1) } defer conn.CloseMGO("startup") } xenia.AddCommand( cmddb.GetCommands(conn), cmdquery.GetCommands(), cmdscript.GetCommands(), cmdregex.GetCommands(), cmdmask.GetCommands(), cmdrelationship.GetCommands(), cmdview.GetCommands(), ) xenia.Execute() }
// runTest initializes the environment for the tests and allows for // the proper return code if the test fails or succeeds. func runTest(m *testing.M) int { // Initialize MongoDB using the `tests.TestSession` as the name of the // master session. if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil { fmt.Println("Can't register master session: " + err.Error()) return 1 } // Setup the app for performing tests. a = routes.API() // Snatch the mongo session so we can create some test data. db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { fmt.Println("Unable to get Mongo session") return 1 } defer db.CloseMGO(tests.Context) // Generate the test data. tstdata.Generate(db) defer tstdata.Drop(db) // Load in the submissions from the fixture. if err = loadSubmissions(db); err != nil { fmt.Println("Unable to load submissions: ", err) } defer aggfix.Remove(tests.Context, db, "") return m.Run() }
// runTest initializes the environment for the tests and allows for // the proper return code if the test fails or succeeds. func runTest(m *testing.M) int { // Initialize the configuration and logging systems. Plus anything // else the web app layer needs. tests.Init("XENIA") // Initialize MongoDB using the `tests.TestSession` as the name of the // master session. if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil { fmt.Println("Can't register master session: " + err.Error()) return 1 } db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { fmt.Println("MongoDB is not configured") return 1 } defer db.CloseMGO(tests.Context) if err := loadTestData(tests.Context, db); err != nil { fmt.Println("test data is not loaded: " + err.Error()) return 1 } defer unloadTestData(tests.Context, db) return m.Run() }
// runTest initializes the environment for the tests and allows for // the proper return code if the test fails or succeeds. func runTest(m *testing.M) int { // Initialize the configuration and logging systems. Plus anything // else the web app layer needs. tests.Init("ASK") // Initialize MongoDB using the `tests.TestSession` as the name of the // master session. if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil { fmt.Println("Can't register master session: " + err.Error()) return 1 } db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { log.Fatalf("Should be able to get a Mongo session : %v", err) } defer db.CloseMGO(tests.Context) // We need the database indexes setup before we can call anything, so do this // first. This is fairly important, so we want to fail the entire test suite // if we can't setup the indexes. if err := submission.EnsureIndexes(tests.Context, db); err != nil { log.Fatal("Can't ensure the database indexes") } return m.Run() }
// Midware handles databse session management and manages a MongoDB session. func Midware(mongoURI *url.URL) web.Middleware { // Create the middleware that we can use to create MongoDB sessions with. m := func(next web.Handler) web.Handler { // Create the handler that will be attached in the middleware chain. h := func(c *web.Context) error { // Pull in the mongo session from the master session so we can load it // onto the request context. It is keyed by the path on the uri. db, err := kitdb.NewMGO(c.SessionID, mongoURI.Path) if err != nil { log.Error(c.SessionID, "mongo : Midware", err, "Method[%s] URL[%s] RADDR[%s]", c.Request.Method, c.Request.URL.Path, c.Request.RemoteAddr) return web.ErrDBNotConfigured } // Load the mongo database onto the request context. c.Ctx["DB"] = db log.Dev(c.SessionID, "mongo : Midware", "Capture Mongo Session") // Close the MongoDB session when the handler returns. defer func() { log.Dev(c.SessionID, "mongo : Midware", "Release Mongo Session") db.CloseMGO(c.SessionID) }() return next(c) } return h } return m }
// runTest initializes the environment for the tests and allows for // the proper return code if the test fails or succeeds. func runTest(m *testing.M) int { // Initialize MongoDB using the `tests.TestSession` as the name of the // master session. if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil { fmt.Println("Can't register master session: " + err.Error()) return 1 } // Setup the app for performing tests. a = routes.API() // Snatch the mongo session so we can create some test data. db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { fmt.Println("Unable to get Mongo session") return 1 } defer db.CloseMGO(tests.Context) if err := loadItems(tests.Context, db); err != nil { fmt.Println("Could not load items") return 1 } defer itemfix.Remove(tests.Context, db, itemPrefix) if err := loadPatterns(tests.Context, db); err != nil { fmt.Println("Could not load patterns") return 1 } defer patternfix.Remove(tests.Context, db, patternPrefix) return m.Run() }
func ensureDBIndexes(mongoURI *url.URL) error { mgoDB, err := db.NewMGO("startup", mongoURI.Path) if err != nil { return err } defer mgoDB.CloseMGO("startup") return submission.EnsureIndexes("startup", mgoDB) }
func setup(t *testing.T) *db.DB { tests.ResetLog() db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("Should be able to get a Mongo session : %v", err) } return db }
// TestGetByID tests if we can get a single item from the db. func TestGetByID(t *testing.T) { tests.ResetLog() defer tests.DisplayLog() db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("\t%s\tShould be able to get a Mongo session : %v", tests.Failed, err) } defer db.CloseMGO(tests.Context) defer func() { if err := itemfix.Remove(tests.Context, db, prefix); err != nil { t.Fatalf("\t%s\tShould be able to remove the items : %v", tests.Failed, err) } t.Logf("\t%s\tShould be able to remove the items.", tests.Success) }() t.Log("Given the need to get an item in the database by ID.") { t.Log("\tWhen starting from an empty items collection") { items, err := itemfix.Get() if err != nil { t.Fatalf("\t%s\tShould be able retrieve item fixture : %s", tests.Failed, err) } var itemIDs []string for _, it := range items { if err := item.Upsert(tests.Context, db, &it); err != nil { t.Fatalf("\t%s\tShould be able to upsert items : %s", tests.Failed, err) } itemIDs = append(itemIDs, it.ID) } t.Logf("\t%s\tShould be able to upsert items.", tests.Success) itmBack, err := item.GetByID(tests.Context, db, itemIDs[0]) if err != nil { t.Fatalf("\t%s\tShould be able to get an item by ID : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to get an item by ID.", tests.Success) // Check equality for all immutable fields: ID, Version, Data. Timestamps will change on Upsert. if !reflect.DeepEqual(items[0].Data, itmBack.Data) || (items[0].ID != itmBack.ID) || (items[0].Version != itmBack.Version) { t.Logf("\t%+v", items[0]) t.Logf("\t%+v", itmBack) t.Fatalf("\t%s\tShould be able to get back the same item.", tests.Failed) } t.Logf("\t%s\tShould be able to get back the same item.", tests.Success) } } }
// runTest initializes the environment for the tests and allows for // the proper return code if the test fails or succeeds. func runTest(m *testing.M) int { // Create stub server for Sponged. server := setup() cfg.SetString("SPONGED_URL", server) mongoURI := cfg.MustURL("MONGO_URI") // Initialize MongoDB using the `tests.TestSession` as the name of the // master session. if err := db.RegMasterSession(tests.Context, tests.TestSession, mongoURI.String(), 0); err != nil { fmt.Println("Can't register master session: " + err.Error()) return 1 } a = routes.API() // Snatch the mongo session so we can create some test data. db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { fmt.Println("Unable to get Mongo session") return 1 } defer db.CloseMGO(tests.Context) if err = db.NewCayley(tests.Context, tests.TestSession); err != nil { fmt.Println("Unable to get Cayley support") } store, err := db.GraphHandle(tests.Context) if err != nil { fmt.Println("Unable to get Cayley handle") return 1 } defer store.Close() if err := tstdata.Generate(db); err != nil { fmt.Println("Could not generate test data.") return 1 } defer tstdata.Drop(db) if err := loadItems("context", db, store); err != nil { fmt.Println("Could not import items") return 1 } defer unloadItems("context", db, store) return m.Run() }
// TestGetByIDs tests if we can get items from the db. func TestGetByIDs(t *testing.T) { tests.ResetLog() defer tests.DisplayLog() db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("\t%s\tShould be able to get a Mongo session : %v", tests.Failed, err) } defer db.CloseMGO(tests.Context) defer func() { if err := itemfix.Remove(tests.Context, db, prefix); err != nil { t.Fatalf("\t%s\tShould be able to remove the items : %v", tests.Failed, err) } t.Logf("\t%s\tShould be able to remove the items.", tests.Success) }() t.Log("Given the need to get items in the database by IDs.") { t.Log("\tWhen starting from an empty items collection") { items1, err := itemfix.Get() if err != nil { t.Fatalf("\t%s\tShould be able retrieve item fixture : %s", tests.Failed, err) } var itemIDs []string for _, it := range items1 { if err := item.Upsert(tests.Context, db, &it); err != nil { t.Fatalf("\t%s\tShould be able to upsert items : %s", tests.Failed, err) } itemIDs = append(itemIDs, it.ID) } t.Logf("\t%s\tShould be able to upsert items.", tests.Success) items2, err := item.GetByIDs(tests.Context, db, itemIDs) if err != nil { t.Fatalf("\t%s\tShould be able to get items by IDs : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to get items by IDs.", tests.Success) if len(items1) != len(items2) { t.Logf("\t%+v", items1) t.Logf("\t%+v", items2) t.Fatalf("\t%s\tShould be able to get back the same items.", tests.Failed) } t.Logf("\t%s\tShould be able to get back the same items.", tests.Success) } } }
func setup(t *testing.T, fixture string) ([]submission.Submission, *db.DB) { tests.ResetLog() subs, err := submissionfix.GetMany("submission.json") if err != nil { t.Fatalf("%s\tShould be able retrieve submission fixture : %s", tests.Failed, err) } t.Logf("%s\tShould be able retrieve submission fixture.", tests.Success) db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("Should be able to get a Mongo session : %v", err) } return subs, db }
// setup initializes for each indivdual test. func setup(t *testing.T) ([]relationship.Relationship, *db.DB) { tests.ResetLog() rels, err := relationshipfix.Get() if err != nil { t.Fatalf("%s\tShould load relationship records from file : %v", tests.Failed, err) } t.Logf("%s\tShould load relationship records from file.", tests.Success) db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("%s\tShould be able to get a Mongo session : %v", tests.Failed, err) } return rels, db }
// setup initializes for each indivdual test. func setup(t *testing.T) ([]view.View, *db.DB) { tests.ResetLog() views, err := viewfix.Get() if err != nil { t.Fatalf("%s\tShould load view records from file : %v", tests.Failed, err) } t.Logf("%s\tShould load view records from file.", tests.Success) db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("%s\tShould be able to get a Mongo session : %v", tests.Failed, err) } return views, db }
func setupForms(t *testing.T, fixture string) ([]form.Form, *db.DB) { tests.ResetLog() fms, err := formfix.Get("form") if err != nil { t.Fatalf("%s\tShould be able retrieve form fixture : %s", tests.Failed, err) } t.Logf("%s\tShould be able retrieve form fixture.", tests.Success) db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("Should be able to get a Mongo session : %v", err) } return fms, db }
func setup(t *testing.T, fixture string) ([]gallery.Gallery, *db.DB) { tests.ResetLog() gs, err := galleryfix.Get(fixture) if err != nil { t.Fatalf("%s\tShould be able retrieve gallery fixture : %s", tests.Failed, err) } t.Logf("%s\tShould be able retrieve gallery fixture.", tests.Success) db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("Should be able to get a Mongo session : %v", err) } return gs, db }
// setup initializes for each indivdual test. func setup(t *testing.T, fixture string) (*query.Set, *db.DB) { tests.ResetLog() set, err := qfix.Get(fixture) if err != nil { t.Fatalf("%s\tShould load query mask record from file : %v", tests.Failed, err) } t.Logf("%s\tShould load query mask record from file.", tests.Success) db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("%s\tShould be able to get a Mongo session : %v", tests.Failed, err) } return set, db }
// setup initializes for each indivdual test. func setup(t *testing.T) ([]pattern.Pattern, *db.DB) { tests.ResetLog() patterns, _, err := patternfix.Get() if err != nil { t.Fatalf("%s\tShould load pattern records from the fixture file : %v", tests.Failed, err) } t.Logf("%s\tShould load pattern records from the fixture file.", tests.Success) db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("%s\tShould be able to get a Mongo session : %v", tests.Failed, err) } return patterns, db }
// setup initializes for each indivdual test. func setup(t *testing.T) (*db.DB, *cayley.Handle) { tests.ResetLog() db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("%s\tShould be able to get a Mongo session : %v", tests.Failed, err) } if err := db.NewCayley(tests.Context, tests.TestSession); err != nil { t.Fatalf("%s\tShould be able to get Cayley support : %v", tests.Failed, err) } store, err := db.GraphHandle(tests.Context) if err != nil { t.Fatalf("\t%s\tShould be able to get a Cayley handle : %v", tests.Failed, err) } return db, store }
func setupAgg(t *testing.T) (*form.Form, []submission.Submission, *db.DB) { tests.ResetLog() fm, subs, err := aggfix.Get() if err != nil { t.Fatalf("%s\tShould be able retrieve form and submission fixture : %s", tests.Failed, err) } db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("Should be able to get a Mongo session : %v", err) } if err := aggfix.Add(tests.Context, db, fm, subs); err != nil { t.Fatalf("Should be able to add forms and submissions to the database : %v", err) } return fm, subs, db }
// setup initializes for each indivdual test. func setup(t *testing.T) *db.DB { tests.ResetLog() db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("%s\tShould be able to get a Mongo session : %v", tests.Failed, err) } if err := db.NewCayley(tests.Context, tests.TestSession); err != nil { t.Fatalf("%s\tShould be able to get a Cayley connection : %v", tests.Failed, err) } loadTestData(t, db) if err := loadRegex(db, "number.json"); err != nil { t.Fatalf("\t%s\tShould be able to load regex fixture : %v", tests.Failed, err) } if err := loadRegex(db, "email.json"); err != nil { t.Fatalf("\t%s\tShould be able to load regex fixture : %v", tests.Failed, err) } if err := loadRelationships("context", db); err != nil { t.Fatalf("\t%s\tShould be able to load relationship fixture : %v", tests.Failed, err) } if err := loadPatterns("context", db); err != nil { t.Fatalf("\t%s\tShould be able to load pattern fixture : %v", tests.Failed, err) } if err := loadViews("context", db); err != nil { t.Fatalf("\t%s\tShould be able to load view fixture : %v", tests.Failed, err) } if err := loadItems("context", db); err != nil { t.Fatalf("\t%s\tShould be able to load items : %v", tests.Failed, err) } return db }
// runTest initializes the environment for the tests and allows for // the proper return code if the test fails or succeeds. func runTest(m *testing.M) int { // Initialize MongoDB using the `tests.TestSession` as the name of the // master session. if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil { fmt.Println("Can't register master session: " + err.Error()) return 1 } db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { fmt.Println("Can't get mongo session: " + err.Error()) return 1 } defer db.CloseMGO(tests.Context) loadPatterns("context", db) defer patternfix.Remove("context", db, patternPrefix) defer itemfix.Remove("context", db, itemPrefix) return m.Run() }
// TestUpsertDelete tests if we can add/remove an item to/from the db. func TestUpsertDelete(t *testing.T) { tests.ResetLog() defer tests.DisplayLog() db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { t.Fatalf("\t%s\tShould be able to get a Mongo session : %v", tests.Failed, err) } defer db.CloseMGO(tests.Context) defer func() { if err := itemfix.Remove(tests.Context, db, prefix); err != nil { t.Fatalf("\t%s\tShould be able to remove the items : %v", tests.Failed, err) } t.Logf("\t%s\tShould be able to remove the items.", tests.Success) }() t.Log("Given the need to upsert and delete items.") { t.Log("\tWhen starting from an empty items collection") { //---------------------------------------------------------------------- // Get the fixture. items, err := itemfix.Get() if err != nil { t.Fatalf("\t%s\tShould be able retrieve item fixture : %s", tests.Failed, err) } //---------------------------------------------------------------------- // Upsert the item. if err := item.Upsert(tests.Context, db, &items[0]); err != nil { t.Fatalf("\t%s\tShould be able to upsert a item : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to upsert a item.", tests.Success) //---------------------------------------------------------------------- // Get the item. itemsBack, err := item.GetByIDs(tests.Context, db, []string{items[0].ID}) if err != nil { t.Fatalf("\t%s\tShould be able to get the item by ID : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to get the item by ID.", tests.Success) //---------------------------------------------------------------------- // Check that we got the item we expected. if items[0].ID != itemsBack[0].ID { t.Logf("\t%+v", items[0]) t.Logf("\t%+v", itemsBack[0]) t.Fatalf("\t%s\tShould be able to get back the same item.", tests.Failed) } t.Logf("\t%s\tShould be able to get back the same item.", tests.Success) //---------------------------------------------------------------------- // Check that CreatedAt and UpdatedAt were set. if itemsBack[0].CreatedAt.IsZero() || itemsBack[0].UpdatedAt.IsZero() { t.Fatalf("\t%s\tShould set CreatedAt and UpdatedAt on upsert.", tests.Failed) } t.Logf("\t%s\tShould set CreatedAt and UpdatedAt on upsert.", tests.Success) //---------------------------------------------------------------------- // Delete the item. if err := item.Delete(tests.Context, db, items[0].ID); err != nil { t.Fatalf("\t%s\tShould be able to delete the item : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to delete the item.", tests.Success) //---------------------------------------------------------------------- // Get the item. itemsBack, err = item.GetByIDs(tests.Context, db, []string{items[0].ID}) if len(itemsBack) != 0 { t.Fatalf("\t%s\tShould generate an error when getting an item with the deleted ID : %s", tests.Failed, err) } t.Logf("\t%s\tShould generate an error when getting an item with the deleted ID.", tests.Success) } } }
// runTest initializes the environment for the tests and allows for // the proper return code if the test fails or succeeds. func runTest(m *testing.M) int { mongoURI := cfg.MustURL("MONGO_URI") // Initialize MongoDB using the `tests.TestSession` as the name of the // master session. if err := db.RegMasterSession(tests.Context, tests.TestSession, mongoURI.String(), 0); err != nil { fmt.Println("Can't register master session: " + err.Error()) return 1 } // Setup the app for performing tests. a = routes.API() // Snatch the mongo session so we can create some test data. db, err := db.NewMGO(tests.Context, tests.TestSession) if err != nil { fmt.Println("Unable to get Mongo session") return 1 } defer db.CloseMGO(tests.Context) if err := db.NewCayley(tests.Context, tests.TestSession); err != nil { fmt.Println("Unable to get Cayley support") } store, err := db.GraphHandle(tests.Context) if err != nil { fmt.Println("Unable to get Cayley handle") return 1 } defer store.Close() if err := tstdata.Generate(db); err != nil { fmt.Println("Could not generate test data.") return 1 } defer tstdata.Drop(db) // Load the queries. if err := loadQuery(db, "basic.json"); err != nil { fmt.Println("Could not load queries in basic.json") return 1 } if err := loadQuery(db, "basic_view.json"); err != nil { fmt.Println("Could not load queries in basic.json") return 1 } if err := loadQuery(db, "basic_var.json"); err != nil { fmt.Println("Could not load queries in basic_var.json") return 1 } defer qfix.Remove(db, "QTEST_O") if err := loadScript(db, "basic_script_pre.json"); err != nil { fmt.Println("Could not load scripts in basic_script_pre.json") return 1 } if err := loadScript(db, "basic_script_pst.json"); err != nil { fmt.Println("Could not load scripts in basic_script_pst.json") return 1 } defer sfix.Remove(db, "STEST_O") if err := loadMasks(db, "basic.json"); err != nil { fmt.Println("Could not load masks.") return 1 } defer mfix.Remove(db, "test_xenia_data") if err := loadRelationships("context", db); err != nil { fmt.Println("Could not load relationships.") return 1 } defer relationshipfix.Remove("context", db, relPrefix) if err := loadViews("context", db); err != nil { fmt.Println("Could not load views.") return 1 } defer viewfix.Remove("context", db, viewPrefix) if err := loadPatterns("context", db); err != nil { fmt.Println("Could not load patterns") return 1 } defer patternfix.Remove("context", db, "PTEST_") if err := loadItems("context", db, store); err != nil { fmt.Println("Could not import items") return 1 } defer unloadItems("context", db, store) return m.Run() }
func main() { // Initialize the configuration if err := cfg.Init(cfg.EnvProvider{Namespace: "WIRE"}); err != nil { wire.Println("Unable to initialize configuration") os.Exit(1) } // Initialize the logging logLevel := func() int { ll, err := cfg.Int(cfgLoggingLevel) if err != nil { return log.NONE } return ll } log.Init(os.Stderr, logLevel, log.Ldefault) wire.Println("Using log level", logLevel()) // Pull options from the config. var mgoDB *db.DB var graphDB *cayley.Handle // Configure MongoDB. wire.Println("Configuring MongoDB") mongoURI := cfg.MustURL(cfgMongoURI) err := db.RegMasterSession("startup", mongoURI.Path, mongoURI.String(), 0) if err != nil { wire.Println("Unable to initialize MongoDB") os.Exit(1) } mgoDB, err = db.NewMGO("startup", mongoURI.Path) if err != nil { wire.Println("Unable to get MongoDB session") os.Exit(1) } defer mgoDB.CloseMGO("") // Configure Cayley. wire.Println("Configuring Cayley") if err := mgoDB.NewCayley("startup", mongoURI.Path); err != nil { wire.Println("Unable to get Cayley support") } graphDB, err = mgoDB.GraphHandle("startup") if err != nil { wire.Println("Unable to get Cayley handle") os.Exit(1) } // Add the graph and view commands to the CLI tool. wire.AddCommand( cmdview.GetCommands(mgoDB, graphDB), ) // Execute the command. wire.Execute() }