1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

vendor: gotest.tools v3.3.0

full diff: https://github.com/gotestyourself/gotest.tools/compare/v3.2.0...v3.3.0

- golden: accept -update for updating files
- assert: golden variables

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-09-22 15:45:08 +02:00
parent 08dccc2cb4
commit 3e1601a980
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
11 changed files with 245 additions and 76 deletions

View file

@ -2,7 +2,7 @@
Golden files are files in the ./testdata/ subdirectory of the package under test.
Golden files can be automatically updated to match new values by running
`go test pkgname -test.update-golden`. To ensure the update is correct
`go test pkgname -update`. To ensure the update is correct
compare the diff of the old expected value to the new expected value.
*/
package golden // import "gotest.tools/v3/golden"
@ -18,9 +18,12 @@ import (
"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"
"gotest.tools/v3/internal/format"
"gotest.tools/v3/internal/source"
)
var flagUpdate = flag.Bool("test.update-golden", false, "update golden file")
func init() {
flag.BoolVar(&source.Update, "test.update-golden", false, "deprecated flag")
}
type helperT interface {
Helper()
@ -28,7 +31,7 @@ type helperT interface {
// NormalizeCRLFToLF enables end-of-line normalization for actual values passed
// to Assert and String, as well as the values saved to golden files with
// -test.update-golden.
// -update.
//
// Defaults to true. If you use the core.autocrlf=true git setting on windows
// you will need to set this to false.
@ -39,9 +42,9 @@ type helperT interface {
// The default value may change in a future major release.
var NormalizeCRLFToLF = os.Getenv("GOTESTTOOLS_GOLDEN_NormalizeCRLFToLF") != "false"
// FlagUpdate returns true when the -test.update-golden flag has been set.
// FlagUpdate returns true when the -update flag has been set.
func FlagUpdate() bool {
return *flagUpdate
return source.Update
}
// Open opens the file in ./testdata
@ -81,7 +84,7 @@ func removeCarriageReturn(in []byte) []byte {
// Assert compares actual to the expected value in the golden file.
//
// Running `go test pkgname -test.update-golden` will write the value of actual
// Running `go test pkgname -update` will write the value of actual
// to the golden file.
//
// This is equivalent to assert.Assert(t, String(actual, filename))
@ -95,7 +98,7 @@ func Assert(t assert.TestingT, actual string, filename string, msgAndArgs ...int
// String compares actual to the contents of filename and returns success
// if the strings are equal.
//
// Running `go test pkgname -test.update-golden` will write the value of actual
// Running `go test pkgname -update` will write the value of actual
// to the golden file.
//
// Any \r\n substrings in actual are converted to a single \n character
@ -122,13 +125,13 @@ func String(actual string, filename string) cmp.Comparison {
func failurePostamble(filename string) string {
return fmt.Sprintf(`
You can run 'go test . -test.update-golden' to automatically update %s to the new expected value.'
You can run 'go test . -update' to automatically update %s to the new expected value.'
`, Path(filename))
}
// AssertBytes compares actual to the expected value in the golden.
//
// Running `go test pkgname -test.update-golden` will write the value of actual
// Running `go test pkgname -update` will write the value of actual
// to the golden file.
//
// This is equivalent to assert.Assert(t, Bytes(actual, filename))
@ -147,7 +150,7 @@ func AssertBytes(
// Bytes compares actual to the contents of filename and returns success
// if the bytes are equal.
//
// Running `go test pkgname -test.update-golden` will write the value of actual
// Running `go test pkgname -update` will write the value of actual
// to the golden file.
func Bytes(actual []byte, filename string) cmp.Comparison {
return func() cmp.Result {
@ -175,7 +178,7 @@ func compare(actual []byte, filename string) (cmp.Result, []byte) {
}
func update(filename string, actual []byte) error {
if !*flagUpdate {
if !source.Update {
return nil
}
if dir := filepath.Dir(Path(filename)); dir != "." {