Ruby on Rails' style test fixtures for Golang, use database transation to keep database clean state
Install the package by:
go get -u github.com/Martin91/gofixtures
- Reference to dummy to see demo yaml files.
- In your project, initalize database connection like:
import ( _ "github.com/go-sql-driver/mysql" "github.com/Martin91/gofixtures" ) // fixtures is shipped with a builtin sql driver which supports rollback db automatically, // so it is required to setup a transational *sql.DB by fixtures db := fixtures.OpenDB("mysql", "root:@tcp(localhost:3306)/?charset=utf8&parseTime=True&loc=Local") fixtures := fixtures.Load(tt.args.path, db) // do your test and something else // once the program exit, fixtures will rollback all database changes automatically // or if you want to manually rollback, run db.Driver().(base.TxDriverIface).ManualRollback()
This repository is still under active development and the overall design and performance is unstable.
[x] YAML based simple and clean syntax
[x] Built-in Faker supported
[x] Bundled field evaluators, enable you to customize dynamic data generation
[x] Support specifying database and tables
[x] Based on standard sql
package, compatible with different dialects
[x] Transaction based database cleaner
[ ] Templates to support batch data
- Test with different databases
- Complete test cases with high test coverage
- Review the overall architecture design