1
0

Update module go-testfixtures/testfixtures/v3 to v3.2.0 (#505)

Update module go-testfixtures/testfixtures/v3 to v3.2.0

Reviewed-on: https://kolaente.dev/vikunja/api/pulls/505
This commit is contained in:
renovate
2020-05-11 10:10:15 +00:00
committed by konrad
parent a9d0079bf3
commit 55cd74efca
6 changed files with 72 additions and 5 deletions

View File

@ -1,9 +1,14 @@
# Changelog
## v3.2.0 - 2020-05-10
- Add support for loading multiple files and directories
([#65](https://github.com/go-testfixtures/testfixtures/pull/65)).
## v3.1.2 - 2020-04-26
- Dump: Fix column order in generated YAML files
[#62](https://github.com/go-testfixtures/testfixtures/pull/62)
([#62](https://github.com/go-testfixtures/testfixtures/pull/62)).
## v3.1.1 - 2020-01-11

View File

@ -192,6 +192,25 @@ if err != nil {
}
```
With `Paths` option, you can specify the paths that fixtures will load
from. Path can be directory or file. If directory, we will search YAML files
in it.
```go
fixtures, err := testfixtures.New(
testfixtures.Database(db),
testfixtures.Dialect("postgres"),
testfixtures.Paths(
"fixtures/orders.yml",
"fixtures/customers.yml",
"common_fixtures/users"
),
)
if err != nil {
...
}
```
## Security check
In order to prevent you from accidentally wiping the wrong database, this

View File

@ -5,6 +5,7 @@ import (
"database/sql"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
@ -185,7 +186,7 @@ func Directory(dir string) func(*Loader) error {
if err != nil {
return err
}
l.fixturesFiles = fixtures
l.fixturesFiles = append(l.fixturesFiles, fixtures...)
return nil
}
}
@ -197,7 +198,19 @@ func Files(files ...string) func(*Loader) error {
if err != nil {
return err
}
l.fixturesFiles = fixtures
l.fixturesFiles = append(l.fixturesFiles, fixtures...)
return nil
}
}
// Paths inform Loader to load a given set of YAML files and directories.
func Paths(paths ...string) func(*Loader) error {
return func(l *Loader) error {
fixtures, err := l.fixturesFromPaths(paths...)
if err != nil {
return err
}
l.fixturesFiles = append(l.fixturesFiles, fixtures...)
return nil
}
}
@ -534,6 +547,34 @@ func (l *Loader) fixturesFromFiles(fileNames ...string) ([]*fixtureFile, error)
return fixtureFiles, nil
}
func (l *Loader) fixturesFromPaths(paths ...string) ([]*fixtureFile, error) {
fixtureExtractor := func(p string, isDir bool) ([]*fixtureFile, error) {
if isDir {
return l.fixturesFromDir(p)
}
return l.fixturesFromFiles(p)
}
var fixtureFiles []*fixtureFile
for _, p := range paths {
f, err := os.Stat(p)
if err != nil {
return nil, fmt.Errorf(`testfixtures: could not stat path "%s": %w`, p, err)
}
fixtures, err := fixtureExtractor(p, f.IsDir())
if err != nil {
return nil, err
}
fixtureFiles = append(fixtureFiles, fixtures...)
}
return fixtureFiles, nil
}
func (l *Loader) processFileTemplate(f *fixtureFile) error {
if !l.template {
return nil