https://github.com/takashabe/go-fixture
Management the fixtures of the database for testing.
https://github.com/takashabe/go-fixture
fixtures go golang testing testing-tools
Last synced: 4 months ago
JSON representation
Management the fixtures of the database for testing.
- Host: GitHub
- URL: https://github.com/takashabe/go-fixture
- Owner: takashabe
- License: mit
- Created: 2017-01-28T17:14:08.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-07-27T07:27:21.000Z (almost 6 years ago)
- Last Synced: 2024-04-18T04:57:34.572Z (about 2 years ago)
- Topics: fixtures, go, golang, testing, testing-tools
- Language: Go
- Homepage:
- Size: 40 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-fixture
[](https://godoc.org/github.com/takashabe/go-fixture)
[](https://circleci.com/gh/takashabe/go-fixture)
[](https://goreportcard.com/report/github.com/takashabe/go-fixture)
Management the fixtures of the database for testing.
## features
* Load database fixture from .yaml or .sql file
* Before cleanup table(.yaml only)
* Support databases
* MySQL
* and more drivers are todo...
## usage
* Import `go-fixture` and drirver `go-fixture/mysql` as like `database/sql` driver
```go
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"github.com/takashabe/go-fixture"
_ "github.com/takashabe/go-fixture/mysql"
)
func main() {
// omit error handling
db, _ := sql.Open("mysql", "fixture@/db_fixture")
f, _ := fixture.NewFixture(db, "mysql")
f.Load("fixture/setup.yml")
f.Load("fixture/setup.sql")
}
```
## fixture file format
#### .yml .yaml
```yml
table: foo
record:
- id: 1
first_name: foo
last_name: bar
- id: 2
first_name: piyo
last_name: fuga
```
#### .sql
* Need to add a semicolon at the end of the line
* If table cleanup is required it will need to be in the fixture file
```sql
DELETE FROM person;
INSERT INTO person(id, name) VALUES (1, 'foo');
```