Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "transactional fixtures" (or "transactional tests") #24

Open
andreynering opened this issue Mar 24, 2018 · 3 comments
Open

Implement "transactional fixtures" (or "transactional tests") #24

andreynering opened this issue Mar 24, 2018 · 3 comments

Comments

@andreynering
Copy link
Contributor

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.

@kswope
Copy link

kswope commented Mar 25, 2018

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

@KoduIsGreat
Copy link

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.

@andreynering
Copy link
Contributor Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants