Skip to content

Instantly share code, notes, and snippets.

@efueyo
Last active October 25, 2019 23:44
Show Gist options
  • Save efueyo/e6b20a5c36dd6b94807939b69e7d4de4 to your computer and use it in GitHub Desktop.
Save efueyo/e6b20a5c36dd6b94807939b69e7d4de4 to your computer and use it in GitHub Desktop.
TestFixtures.go
var fixtures *testfixtures.Context
func TestMain(m *testing.M) { // errors skipped for brevity here
db, _ := sql.Open("postgres", "dbname=myapp_test")
fixtures, _ = testfixtures.NewFolder(db, &testfixtures.PostgreSQL{}, "testdata/fixtures")
os.Exit(m.Run())
}
// now remember to call fixtures.Load() at the beginning of every tests and check for errors
// in Ginkgo you can use BeforeEach like:
var _ = Describe("My Test", func() {
BeforeEach(func() {
err := fixtures.Load()
Expect(err).ToNot(HaveOccurred())
})
...
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment