Tests can now use config files (#36)
This commit is contained in:
2
vendor/gopkg.in/testfixtures.v2/.travis.yml
generated
vendored
2
vendor/gopkg.in/testfixtures.v2/.travis.yml
generated
vendored
@ -1,8 +1,8 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- '1.9'
|
||||
- '1.10'
|
||||
- '1.11'
|
||||
|
||||
services:
|
||||
- postgresql
|
||||
|
30
vendor/gopkg.in/testfixtures.v2/README.md
generated
vendored
30
vendor/gopkg.in/testfixtures.v2/README.md
generated
vendored
@ -229,6 +229,15 @@ errors with the previous approach. It is as simple as using:
|
||||
&testfixtures.PostgreSQL{UseAlterConstraint: true}
|
||||
```
|
||||
|
||||
#### Skipping reset of sequences
|
||||
|
||||
You can skip the reset of PostgreSQL sequences if you're debugging a problem
|
||||
with it, but most of the time you shouldn't do it:
|
||||
|
||||
```go
|
||||
&testfixtures.PostgreSQL{SkipResetSequences: true}
|
||||
```
|
||||
|
||||
### MySQL / MariaDB
|
||||
|
||||
Just make sure the connection string have
|
||||
@ -302,6 +311,27 @@ if err != nil {
|
||||
> This was thought to run in small sample databases. It will likely break
|
||||
if run in a production/big database.
|
||||
|
||||
## Gotchas
|
||||
|
||||
### Parallel testing
|
||||
|
||||
This library doesn't yet support running tests in parallel! Running tests
|
||||
in parallel can result in random data being present in the database, which
|
||||
will likely cause tests to randomly/intermittently fail.
|
||||
|
||||
This is specially tricky since it's not immediately clear that `go test ./...`
|
||||
run tests for each package in parallel. If more than one package use this
|
||||
library, you can face this issue. Please, use `go test -p 1 ./...` or run tests
|
||||
for each package in separated commands to fix this issue.
|
||||
|
||||
See [#40](https://github.com/go-testfixtures/testfixtures/issues/40)
|
||||
and [golang/go#11521](https://github.com/golang/go/issues/11521) for more information.
|
||||
|
||||
We're also planning to implement transactional tests to allow running tests
|
||||
in parallel (see [#24](https://github.com/go-testfixtures/testfixtures/issues/24)).
|
||||
Running each test package in a separated database would also allow you to do that.
|
||||
Open issues for other ideas :slightly_smiling_face:.
|
||||
|
||||
## Contributing
|
||||
|
||||
Tests were written to ensure everything work as expected. You can run the tests
|
||||
|
4
vendor/gopkg.in/testfixtures.v2/Taskfile.yml
generated
vendored
4
vendor/gopkg.in/testfixtures.v2/Taskfile.yml
generated
vendored
@ -1,4 +1,4 @@
|
||||
# github.com/go-task/task
|
||||
# https://taskfile.org
|
||||
|
||||
version: '2'
|
||||
|
||||
@ -6,7 +6,7 @@ tasks:
|
||||
dl-deps:
|
||||
desc: Download cli deps
|
||||
cmds:
|
||||
- go get -u github.com/golang/lint/golint
|
||||
- go get -u golang.org/x/lint/golint
|
||||
|
||||
lint:
|
||||
desc: Runs golint
|
||||
|
2
vendor/gopkg.in/testfixtures.v2/appveyor.yml
generated
vendored
2
vendor/gopkg.in/testfixtures.v2/appveyor.yml
generated
vendored
@ -27,7 +27,7 @@ environment:
|
||||
MINGW_PATH: C:\MinGW
|
||||
|
||||
GOPATH: C:\GOPATH
|
||||
GOVERSION: 1.10.3
|
||||
GOVERSION: 1.11.2
|
||||
|
||||
install:
|
||||
- SET PATH=%POSTGRES_PATH%\bin;%MYSQL_PATH%\bin;%MINGW_PATH%\bin;%PATH%
|
||||
|
15
vendor/gopkg.in/testfixtures.v2/go.mod
generated
vendored
Normal file
15
vendor/gopkg.in/testfixtures.v2/go.mod
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
module gopkg.in/testfixtures.v2
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.33.1 // indirect
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f
|
||||
github.com/go-sql-driver/mysql v1.4.1
|
||||
github.com/google/go-cmp v0.2.0 // indirect
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/lib/pq v1.0.0
|
||||
github.com/mattn/go-oci8 v0.0.0-20181115070430-6eefff3c767c
|
||||
github.com/mattn/go-sqlite3 v1.10.0
|
||||
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869 // indirect
|
||||
google.golang.org/appengine v1.3.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.1
|
||||
)
|
27
vendor/gopkg.in/testfixtures.v2/go.sum
generated
vendored
Normal file
27
vendor/gopkg.in/testfixtures.v2/go.sum
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
cloud.google.com/go v0.33.1 h1:fmJQWZ1w9PGkHR1YL/P7HloDvqlmKQ4Vpb7PC2e+aCk=
|
||||
cloud.google.com/go v0.33.1/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f h1:WH0w/R4Yoey+04HhFxqZ6VX6I0d7RMyw5aXQ9UTvQPs=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f/go.mod h1:xN/JuLBIz4bjkxNmByTiV1IbhfnYb6oo99phBn4Eqhc=
|
||||
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
|
||||
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
|
||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/mattn/go-oci8 v0.0.0-20181115070430-6eefff3c767c h1:RkC3vqmJwowDCqtL7d8cFEMNdoGHBcqoR4jKO9/mWuA=
|
||||
github.com/mattn/go-oci8 v0.0.0-20181115070430-6eefff3c767c/go.mod h1:/M9VLO+lUPmxvoOK2PfWRZ8mTtB4q1Hy9lEGijv9Nr8=
|
||||
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
|
||||
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869 h1:kkXA53yGe04D0adEYJwEVQjeBppL01Exg+fnMjfUraU=
|
||||
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
google.golang.org/appengine v1.3.0 h1:FBSsiFRMz3LBeXIomRnVzrQwSDj4ibvcRexLG0LZGQk=
|
||||
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
14
vendor/gopkg.in/testfixtures.v2/mysql.go
generated
vendored
14
vendor/gopkg.in/testfixtures.v2/mysql.go
generated
vendored
@ -70,13 +70,6 @@ func (h *MySQL) tableNames(q queryable) ([]string, error) {
|
||||
}
|
||||
|
||||
func (h *MySQL) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) (err error) {
|
||||
// re-enable after load
|
||||
defer func() {
|
||||
if _, err2 := db.Exec("SET FOREIGN_KEY_CHECKS = 1"); err2 != nil && err == nil {
|
||||
err = err2
|
||||
}
|
||||
}()
|
||||
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -87,9 +80,14 @@ func (h *MySQL) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) (er
|
||||
return err
|
||||
}
|
||||
|
||||
if err = loadFn(tx); err != nil {
|
||||
err = loadFn(tx)
|
||||
_, err2 := tx.Exec("SET FOREIGN_KEY_CHECKS = 1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
16
vendor/gopkg.in/testfixtures.v2/postgresql.go
generated
vendored
16
vendor/gopkg.in/testfixtures.v2/postgresql.go
generated
vendored
@ -16,6 +16,10 @@ type PostgreSQL struct {
|
||||
// which requires SUPERUSER privileges.
|
||||
UseAlterConstraint bool
|
||||
|
||||
// SkipResetSequences prevents the reset of the databases
|
||||
// sequences after load fixtures time
|
||||
SkipResetSequences bool
|
||||
|
||||
tables []string
|
||||
sequences []string
|
||||
nonDeferrableConstraints []pgConstraint
|
||||
@ -216,11 +220,13 @@ func (h *PostgreSQL) makeConstraintsDeferrable(db *sql.DB, loadFn loadFunction)
|
||||
|
||||
func (h *PostgreSQL) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) (err error) {
|
||||
// ensure sequences being reset after load
|
||||
defer func() {
|
||||
if err2 := h.resetSequences(db); err2 != nil && err == nil {
|
||||
err = err2
|
||||
}
|
||||
}()
|
||||
if !h.SkipResetSequences {
|
||||
defer func() {
|
||||
if err2 := h.resetSequences(db); err2 != nil && err == nil {
|
||||
err = err2
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if h.UseAlterConstraint {
|
||||
return h.makeConstraintsDeferrable(db, loadFn)
|
||||
|
24
vendor/gopkg.in/testfixtures.v2/testfixtures.go
generated
vendored
24
vendor/gopkg.in/testfixtures.v2/testfixtures.go
generated
vendored
@ -89,19 +89,30 @@ func newContext(db *sql.DB, helper Helper, fixtures []*fixtureFile) (*Context, e
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// DetectTestDatabase returns nil if databaseName matches regexp
|
||||
// if err := fixtures.DetectTestDatabase(); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
func (c *Context) DetectTestDatabase() error {
|
||||
dbName, err := c.helper.databaseName(c.db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !dbnameRegexp.MatchString(dbName) {
|
||||
return ErrNotTestDatabase
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Load wipes and after load all fixtures in the database.
|
||||
// if err := fixtures.Load(); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
func (c *Context) Load() error {
|
||||
if !skipDatabaseNameCheck {
|
||||
dbName, err := c.helper.databaseName(c.db)
|
||||
if err != nil {
|
||||
if err := c.DetectTestDatabase(); err != nil {
|
||||
return err
|
||||
}
|
||||
if !dbnameRegexp.MatchString(dbName) {
|
||||
return ErrNotTestDatabase
|
||||
}
|
||||
}
|
||||
|
||||
err := c.helper.disableReferentialIntegrity(c.db, func(tx *sql.Tx) error {
|
||||
@ -257,7 +268,8 @@ func fixturesFromFolder(folderName string) ([]*fixtureFile, error) {
|
||||
}
|
||||
|
||||
for _, fileinfo := range fileinfos {
|
||||
if !fileinfo.IsDir() && filepath.Ext(fileinfo.Name()) == ".yml" {
|
||||
fileExt := filepath.Ext(fileinfo.Name())
|
||||
if !fileinfo.IsDir() && (fileExt == ".yml" || fileExt == ".yaml") {
|
||||
fixture := &fixtureFile{
|
||||
path: path.Join(folderName, fileinfo.Name()),
|
||||
fileName: fileinfo.Name(),
|
||||
|
Reference in New Issue
Block a user