testfixtures
testfixtures copied to clipboard
Implement "transactional fixtures" (or "transactional tests")
Originally asked in #23, but I've being thinking about it for some time.
Today, this lib cleans the database, load everything and then commit the changes for every test run. Rails has an option called "transactional fixtures" (or "transactional tests"), where fixtures are loaded once before all tests, and then each test runs inside a transaction. This would allow concurrent running of tests that touch the database.
Needs investigation on implementation and the better public interface to expose this.
Ideas and help would be very much appreciated.
Would it simply work to just add another function like this
fixtures, err = testfixtures.NewFolderWithTx(tx, &testfixtures.PostgreSQL{}, "testdata/fixtures")
and replace the sql.DB with a sqlTx?
I haven't looked at closely but with my limited go knowledge I suspect it would cause an explosion of code duplication internallly, but I'm mostly thinking out loud about the public API
I am currently doing this using this library in conjunction with go-txdb i have a shell script that runs my tests, and i load the fixtures once using the testfixtures cli, and then run go test ./...
I would be interested in seeing a go API to do this as well though.
@KoduIsGreat I don't think there's a reason to specifically use the CLI to load fixtures. You could use the library to load fixtures once, and then use go-txdb to wrap each test in a transaction.