diff options
author | techknowlogick <techknowlogick@gitea.io> | 2021-02-28 18:08:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-28 18:08:33 -0500 |
commit | 47f6a4ec3f058f69b65fb6501d6ac98994b8f8da (patch) | |
tree | 4d1421a4c836de9de4014117419c151035c17eec /vendor/github.com/go-testfixtures | |
parent | 030646eea41e17e58e11e73b19339630b6d6148e (diff) | |
download | gitea-47f6a4ec3f058f69b65fb6501d6ac98994b8f8da.tar.gz gitea-47f6a4ec3f058f69b65fb6501d6ac98994b8f8da.zip |
go1.16 (#14783)
Diffstat (limited to 'vendor/github.com/go-testfixtures')
5 files changed, 43 insertions, 4 deletions
diff --git a/vendor/github.com/go-testfixtures/testfixtures/v3/CHANGELOG.md b/vendor/github.com/go-testfixtures/testfixtures/v3/CHANGELOG.md index 1f2f38cef5..1827f18581 100644 --- a/vendor/github.com/go-testfixtures/testfixtures/v3/CHANGELOG.md +++ b/vendor/github.com/go-testfixtures/testfixtures/v3/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## v3.5.0 - 2021-01-11 + +- Fix insert of JSON values on PostgreSQL when using `binary_parameters=yes` in + the connection string + ([#83](https://github.com/go-testfixtures/testfixtures/issues/83), [#84](https://github.com/go-testfixtures/testfixtures/pull/84), [lib/pq#528](https://github.com/lib/pq/issues/528)). +- Officially support binary columns through hexadecimal strings + ([#48](https://github.com/go-testfixtures/testfixtures/issues/48), [#82](https://github.com/go-testfixtures/testfixtures/pull/82)). + ## v3.4.1 - 2020-10-19 - Fix for Microsoft SQL Server databases with views diff --git a/vendor/github.com/go-testfixtures/testfixtures/v3/README.md b/vendor/github.com/go-testfixtures/testfixtures/v3/README.md index 1a34a33bd5..8b8748853d 100644 --- a/vendor/github.com/go-testfixtures/testfixtures/v3/README.md +++ b/vendor/github.com/go-testfixtures/testfixtures/v3/README.md @@ -90,6 +90,13 @@ databases. post: "..." ``` +Binary columns can be represented as hexadecimal strings (should start with `0x`): + +```yaml +- id: 1 + binary_column: 0x1234567890abcdef +``` + If you need to write raw SQL, probably to call a function, prefix the value of the column with `RAW=`: @@ -129,7 +136,7 @@ func TestMain(m *testing.M) { ... } - fixtures, err := testfixtures.New( + fixtures, err = testfixtures.New( testfixtures.Database(db), // You database connection testfixtures.Dialect("postgres"), // Available: "postgresql", "timescaledb", "mysql", "mariadb", "sqlite" and "sqlserver" testfixtures.Directory("testdata/fixtures"), // the directory containing the YAML files @@ -497,6 +504,7 @@ unit test database code without having to connect to a real database - [dbcleaner][dbcleaner] - Clean database for testing, inspired by database_cleaner for Ruby +[doc]: https://pkg.go.dev/github.com/go-testfixtures/testfixtures/v3?tab=doc [railstests]: http://guides.rubyonrails.org/testing.html#the-test-database [gotxdb]: https://github.com/DATA-DOG/go-txdb [gosqlmock]: https://github.com/DATA-DOG/go-sqlmock diff --git a/vendor/github.com/go-testfixtures/testfixtures/v3/bytes.go b/vendor/github.com/go-testfixtures/testfixtures/v3/bytes.go new file mode 100644 index 0000000000..478a5ec73e --- /dev/null +++ b/vendor/github.com/go-testfixtures/testfixtures/v3/bytes.go @@ -0,0 +1,14 @@ +package testfixtures + +import ( + "encoding/hex" + "fmt" + "strings" +) + +func (l *Loader) tryHexStringToBytes(s string) ([]byte, error) { + if !strings.HasPrefix(s, "0x") { + return nil, fmt.Errorf("not a hexadecimal string, must be prefix 0x") + } + return hex.DecodeString(strings.TrimPrefix(s, "0x")) +} diff --git a/vendor/github.com/go-testfixtures/testfixtures/v3/dump.go b/vendor/github.com/go-testfixtures/testfixtures/v3/dump.go index fe6f63350f..e2f6b05122 100644 --- a/vendor/github.com/go-testfixtures/testfixtures/v3/dump.go +++ b/vendor/github.com/go-testfixtures/testfixtures/v3/dump.go @@ -2,6 +2,7 @@ package testfixtures import ( "database/sql" + "encoding/hex" "fmt" "os" "path/filepath" @@ -160,6 +161,7 @@ func convertValue(value interface{}) interface{} { if utf8.Valid(v) { return string(v) } + return "0x" + hex.EncodeToString(value.([]byte)) } return value } diff --git a/vendor/github.com/go-testfixtures/testfixtures/v3/testfixtures.go b/vendor/github.com/go-testfixtures/testfixtures/v3/testfixtures.go index e80d2a8fba..87bec9f07a 100644 --- a/vendor/github.com/go-testfixtures/testfixtures/v3/testfixtures.go +++ b/vendor/github.com/go-testfixtures/testfixtures/v3/testfixtures.go @@ -3,6 +3,7 @@ package testfixtures // import "github.com/go-testfixtures/testfixtures/v3" import ( "bytes" "database/sql" + "encoding/json" "fmt" "io/ioutil" "os" @@ -496,12 +497,18 @@ func (l *Loader) buildInsertSQL(f *fixtureFile, record map[interface{}]interface sqlValues = append(sqlValues, strings.TrimPrefix(v, "RAW=")) continue } - - if t, err := l.tryStrToDate(v); err == nil { + if b, err := l.tryHexStringToBytes(v); err == nil { + value = b + } else if t, err := l.tryStrToDate(v); err == nil { value = t } case []interface{}, map[interface{}]interface{}: - value = recursiveToJSON(v) + var bytes []byte + bytes, err = json.Marshal(recursiveToJSON(v)) + if err != nil { + return + } + value = string(bytes) } switch l.helper.paramType() { |