Last active
November 8, 2016 06:50
-
-
Save mvmaasakkers/e7d8b725ffde0a5fffa6b0c8708ae1fc to your computer and use it in GitHub Desktop.
init_test.go Fixtures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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