// 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("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() }
// 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 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 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 } 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 { // 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() }
// API returns a handler for a set of routes. func API() http.Handler { mongoURI := cfg.MustURL(cfgMongoURI) // The web framework middleware for Mongo is using the name of the // database as the name of the master session by convention. So use // cfg.DB as the second argument when creating the master session. if err := db.RegMasterSession("startup", mongoURI.Path, mongoURI.String(), 25*time.Second); err != nil { log.Error("startup", "Init", err, "Initializing MongoDB") os.Exit(1) } w := web.New(logm.Midware, errorm.Midware) publicKey, err := cfg.String(cfgAuthPublicKey) if err != nil || publicKey == "" { log.User("startup", "Init", "%s is missing, internal authentication is disabled", cfgAuthPublicKey) } // If the public key is provided then add the auth middleware or fail using // the provided public key. if publicKey != "" { log.Dev("startup", "Init", "Initializing Auth") authm, err := authm.Midware(publicKey, authm.MidwareOpts{}) if err != nil { log.Error("startup", "Init", err, "Initializing Auth") os.Exit(1) } // Apply the authentication middleware on top of the application as the // first middleware. w.Use(authm) } // Add the Mongo and Cayley middlewares possibly after the auth middleware. w.Use(mongo.Midware(mongoURI), cayley.Midware(mongoURI)) if cors, err := cfg.Bool(cfgEnableCORS); err == nil && cors { log.Dev("startup", "Init", "Initializing CORS : CORS Enabled") w.Use(w.CORS()) } else { log.Dev("startup", "Init", "CORS Disabled") } log.Dev("startup", "Init", "Initalizing routes") routes(w) return w }
// 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 } return m.Run() }
// API returns a handler for a set of routes. func API() http.Handler { mongoURI := cfg.MustURL(cfgMongoURI) // The web framework middleware for Mongo is using the name of the // database as the name of the master session by convention. So use // cfg.DB as the second argument when creating the master session. if err := db.RegMasterSession("startup", mongoURI.Path, mongoURI.String(), 25*time.Second); err != nil { log.Error("startup", "Init", err, "Initializing MongoDB") os.Exit(1) } // Ensure that the database indexes are setup on the underlying MongoDB // database. if err := ensureDBIndexes(mongoURI); err != nil { log.Error("startup", "Init", err, "Initializing DB Indexes") os.Exit(1) } w := web.New(logm.Midware, errorm.Midware, mongo.Midware(mongoURI)) // Load in the recaptcha secret from the config. if recaptcha, err := cfg.String(cfgRecaptchaSecret); err == nil && recaptcha != "" { w.Ctx["recaptcha"] = recaptcha log.Dev("startup", "Init", "Recaptcha Enabled") } else { log.Dev("startup", "Init", "%s is missing, recaptcha is disabled", cfgRecaptchaSecret) } if cors, err := cfg.Bool(cfgEnableCORS); err == nil && cors { log.Dev("startup", "Init", "Initializing CORS : CORS Enabled") w.Use(w.CORS()) } else { log.Dev("startup", "Init", "CORS Disabled") } log.Dev("startup", "Init", "Initalizing routes") routes(w) return w }
// 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() }
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() }
// 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() }