Skip to content

Instantly share code, notes, and snippets.

@mvmaasakkers
Last active November 8, 2016 06:50
Show Gist options
  • Save mvmaasakkers/e7d8b725ffde0a5fffa6b0c8708ae1fc to your computer and use it in GitHub Desktop.
Save mvmaasakkers/e7d8b725ffde0a5fffa6b0c8708ae1fc to your computer and use it in GitHub Desktop.
init_test.go Fixtures
// This file is part of https://github.com/mvmaasakkers/gohttptestmongodb/
// Pages fixtures are intentionally setup as map[string]Page so I can easily select them from within the tests
var pages = map[string]Page{
"ding": Page{Slug: "ding", Name: "Ding!", Content: "<i>HTML Awesomeness</i>"},
"dong-ding": Page{Slug: "dong-ding", Name: "Dong! Ding!", Content: "<b>HTML Awesomeness</b>"},
}
// insertFixtures just inserts all pages (and other types) I've defined above.
func insertFixtures() {
for _, page := range pages {
if err := Session.DB(MongoDBDatabase).C("pages").Insert(page); err != nil {
log.Println(err)
}
}
}
// reInsertFixtures drops database and re-inserts all fixtures so we can
// make sure every test can start fresh.
func reInsertFixtures() {
Session.DB(MongoDBDatabase).DropDatabase()
insertFixtures()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment