Exemplo n.º 1
0
// 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()
}
Exemplo n.º 2
0
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)
}