Esempio 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 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()
}
Esempio n. 2
0
func teardownAgg(t *testing.T, db *db.DB) {
	if err := aggfix.Remove(tests.Context, db, aggPrefix); err != nil {
		t.Fatalf("%s\tShould be able to remove the forms and submissions : %v", tests.Failed, err)
	}
	t.Logf("%s\tShould be able to remove the forms and submissions.", tests.Success)

	db.CloseMGO(tests.Context)
	tests.DisplayLog()
}