mirror of https://github.com/docker/cli.git
vendor: gotest.tools/v3 v3.5.1
full diff: https://github.com/gotestyourself/gotest.tools/compare/v3.5.0..v3.5.1 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
4d6cf135a3
commit
7a2ea5c536
|
@ -43,7 +43,7 @@ require (
|
||||||
golang.org/x/term v0.13.0
|
golang.org/x/term v0.13.0
|
||||||
golang.org/x/text v0.13.0
|
golang.org/x/text v0.13.0
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
gotest.tools/v3 v3.5.0
|
gotest.tools/v3 v3.5.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|
|
@ -386,6 +386,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
|
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
|
||||||
gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
|
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
|
||||||
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
|
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
|
||||||
|
|
|
@ -55,9 +55,9 @@ type dirEntry interface {
|
||||||
Type() string
|
Type() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManifestFromDir creates a Manifest by reading the directory at path. The
|
// ManifestFromDir creates a [Manifest] by reading the directory at path. The
|
||||||
// manifest stores the structure and properties of files in the directory.
|
// manifest stores the structure and properties of files in the directory.
|
||||||
// ManifestFromDir can be used with Equal to compare two directories.
|
// ManifestFromDir can be used with [Equal] to compare two directories.
|
||||||
func ManifestFromDir(t assert.TestingT, path string) Manifest {
|
func ManifestFromDir(t assert.TestingT, path string) Manifest {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
|
|
|
@ -14,9 +14,9 @@ import (
|
||||||
|
|
||||||
const defaultFileMode = 0644
|
const defaultFileMode = 0644
|
||||||
|
|
||||||
// PathOp is a function which accepts a Path and performs an operation on that
|
// PathOp is a function which accepts a [Path] and performs an operation on that
|
||||||
// path. When called with real filesystem objects (File or Dir) a PathOp modifies
|
// path. When called with real filesystem objects ([File] or [Dir]) a PathOp modifies
|
||||||
// the filesystem at the path. When used with a Manifest object a PathOp updates
|
// the filesystem at the path. When used with a [Manifest] object a PathOp updates
|
||||||
// the manifest to expect a value.
|
// the manifest to expect a value.
|
||||||
type PathOp func(path Path) error
|
type PathOp func(path Path) error
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ type manifestDirectory interface {
|
||||||
AddDirectory(path string, ops ...PathOp) error
|
AddDirectory(path string, ops ...PathOp) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithContent writes content to a file at Path
|
// WithContent writes content to a file at [Path]
|
||||||
func WithContent(content string) PathOp {
|
func WithContent(content string) PathOp {
|
||||||
return func(path Path) error {
|
return func(path Path) error {
|
||||||
if m, ok := path.(manifestFile); ok {
|
if m, ok := path.(manifestFile); ok {
|
||||||
|
@ -49,7 +49,7 @@ func WithContent(content string) PathOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithBytes write bytes to a file at Path
|
// WithBytes write bytes to a file at [Path]
|
||||||
func WithBytes(raw []byte) PathOp {
|
func WithBytes(raw []byte) PathOp {
|
||||||
return func(path Path) error {
|
return func(path Path) error {
|
||||||
if m, ok := path.(manifestFile); ok {
|
if m, ok := path.(manifestFile); ok {
|
||||||
|
@ -60,7 +60,7 @@ func WithBytes(raw []byte) PathOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithReaderContent copies the reader contents to the file at Path
|
// WithReaderContent copies the reader contents to the file at [Path]
|
||||||
func WithReaderContent(r io.Reader) PathOp {
|
func WithReaderContent(r io.Reader) PathOp {
|
||||||
return func(path Path) error {
|
return func(path Path) error {
|
||||||
if m, ok := path.(manifestFile); ok {
|
if m, ok := path.(manifestFile); ok {
|
||||||
|
@ -77,7 +77,7 @@ func WithReaderContent(r io.Reader) PathOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsUser changes ownership of the file system object at Path
|
// AsUser changes ownership of the file system object at [Path]
|
||||||
func AsUser(uid, gid int) PathOp {
|
func AsUser(uid, gid int) PathOp {
|
||||||
return func(path Path) error {
|
return func(path Path) error {
|
||||||
if m, ok := path.(manifestResource); ok {
|
if m, ok := path.(manifestResource); ok {
|
||||||
|
@ -132,7 +132,7 @@ func WithFiles(files map[string]string) PathOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromDir copies the directory tree from the source path into the new Dir
|
// FromDir copies the directory tree from the source path into the new [Dir]
|
||||||
func FromDir(source string) PathOp {
|
func FromDir(source string) PathOp {
|
||||||
return func(path Path) error {
|
return func(path Path) error {
|
||||||
if _, ok := path.(manifestDirectory); ok {
|
if _, ok := path.(manifestDirectory); ok {
|
||||||
|
@ -142,7 +142,7 @@ func FromDir(source string) PathOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithDir creates a subdirectory in the directory at path. Additional PathOp
|
// WithDir creates a subdirectory in the directory at path. Additional [PathOp]
|
||||||
// can be used to modify the subdirectory
|
// can be used to modify the subdirectory
|
||||||
func WithDir(name string, ops ...PathOp) PathOp {
|
func WithDir(name string, ops ...PathOp) PathOp {
|
||||||
const defaultMode = 0755
|
const defaultMode = 0755
|
||||||
|
@ -161,7 +161,7 @@ func WithDir(name string, ops ...PathOp) PathOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the PathOps to the File
|
// Apply the PathOps to the [File]
|
||||||
func Apply(t assert.TestingT, path Path, ops ...PathOp) {
|
func Apply(t assert.TestingT, path Path, ops ...PathOp) {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
|
@ -178,7 +178,7 @@ func applyPathOps(path Path, ops []PathOp) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithMode sets the file mode on the directory or file at path
|
// WithMode sets the file mode on the directory or file at [Path]
|
||||||
func WithMode(mode os.FileMode) PathOp {
|
func WithMode(mode os.FileMode) PathOp {
|
||||||
return func(path Path) error {
|
return func(path Path) error {
|
||||||
if m, ok := path.(manifestResource); ok {
|
if m, ok := path.(manifestResource); ok {
|
||||||
|
@ -241,7 +241,7 @@ func copyFile(source, dest string) error {
|
||||||
// WithSymlink creates a symlink in the directory which links to target.
|
// WithSymlink creates a symlink in the directory which links to target.
|
||||||
// Target must be a path relative to the directory.
|
// Target must be a path relative to the directory.
|
||||||
//
|
//
|
||||||
// Note: the argument order is the inverse of os.Symlink to be consistent with
|
// Note: the argument order is the inverse of [os.Symlink] to be consistent with
|
||||||
// the other functions in this package.
|
// the other functions in this package.
|
||||||
func WithSymlink(path, target string) PathOp {
|
func WithSymlink(path, target string) PathOp {
|
||||||
return func(root Path) error {
|
return func(root Path) error {
|
||||||
|
@ -255,7 +255,7 @@ func WithSymlink(path, target string) PathOp {
|
||||||
// WithHardlink creates a link in the directory which links to target.
|
// WithHardlink creates a link in the directory which links to target.
|
||||||
// Target must be a path relative to the directory.
|
// Target must be a path relative to the directory.
|
||||||
//
|
//
|
||||||
// Note: the argument order is the inverse of os.Link to be consistent with
|
// Note: the argument order is the inverse of [os.Link] to be consistent with
|
||||||
// the other functions in this package.
|
// the other functions in this package.
|
||||||
func WithHardlink(path, target string) PathOp {
|
func WithHardlink(path, target string) PathOp {
|
||||||
return func(root Path) error {
|
return func(root Path) error {
|
||||||
|
|
|
@ -77,8 +77,8 @@ func (p *directoryPath) AddDirectory(path string, ops ...PathOp) error {
|
||||||
return applyPathOps(exp, ops)
|
return applyPathOps(exp, ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expected returns a Manifest with a directory structured created by ops. The
|
// Expected returns a [Manifest] with a directory structured created by ops. The
|
||||||
// PathOp operations are applied to the manifest as expectations of the
|
// [PathOp] operations are applied to the manifest as expectations of the
|
||||||
// filesystem structure and properties.
|
// filesystem structure and properties.
|
||||||
func Expected(t assert.TestingT, ops ...PathOp) Manifest {
|
func Expected(t assert.TestingT, ops ...PathOp) Manifest {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
|
@ -125,7 +125,7 @@ func normalizeID(id int) uint32 {
|
||||||
|
|
||||||
var anyFileContent = io.NopCloser(bytes.NewReader(nil))
|
var anyFileContent = io.NopCloser(bytes.NewReader(nil))
|
||||||
|
|
||||||
// MatchAnyFileContent is a PathOp that updates a Manifest so that the file
|
// MatchAnyFileContent is a [PathOp] that updates a [Manifest] so that the file
|
||||||
// at path may contain any content.
|
// at path may contain any content.
|
||||||
func MatchAnyFileContent(path Path) error {
|
func MatchAnyFileContent(path Path) error {
|
||||||
if m, ok := path.(*filePath); ok {
|
if m, ok := path.(*filePath); ok {
|
||||||
|
@ -134,7 +134,7 @@ func MatchAnyFileContent(path Path) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatchContentIgnoreCarriageReturn is a PathOp that ignores cariage return
|
// MatchContentIgnoreCarriageReturn is a [PathOp] that ignores cariage return
|
||||||
// discrepancies.
|
// discrepancies.
|
||||||
func MatchContentIgnoreCarriageReturn(path Path) error {
|
func MatchContentIgnoreCarriageReturn(path Path) error {
|
||||||
if m, ok := path.(*filePath); ok {
|
if m, ok := path.(*filePath); ok {
|
||||||
|
@ -145,7 +145,7 @@ func MatchContentIgnoreCarriageReturn(path Path) error {
|
||||||
|
|
||||||
const anyFile = "*"
|
const anyFile = "*"
|
||||||
|
|
||||||
// MatchExtraFiles is a PathOp that updates a Manifest to allow a directory
|
// MatchExtraFiles is a [PathOp] that updates a [Manifest] to allow a directory
|
||||||
// to contain unspecified files.
|
// to contain unspecified files.
|
||||||
func MatchExtraFiles(path Path) error {
|
func MatchExtraFiles(path Path) error {
|
||||||
if m, ok := path.(*directoryPath); ok {
|
if m, ok := path.(*directoryPath); ok {
|
||||||
|
@ -156,14 +156,14 @@ func MatchExtraFiles(path Path) error {
|
||||||
|
|
||||||
// CompareResult is the result of comparison.
|
// CompareResult is the result of comparison.
|
||||||
//
|
//
|
||||||
// See gotest.tools/assert/cmp.StringResult for a convenient implementation of
|
// See [gotest.tools/v3/assert/cmp.StringResult] for a convenient implementation of
|
||||||
// this interface.
|
// this interface.
|
||||||
type CompareResult interface {
|
type CompareResult interface {
|
||||||
Success() bool
|
Success() bool
|
||||||
FailureMessage() string
|
FailureMessage() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatchFileContent is a PathOp that updates a Manifest to use the provided
|
// MatchFileContent is a [PathOp] that updates a [Manifest] to use the provided
|
||||||
// function to determine if a file's content matches the expectation.
|
// function to determine if a file's content matches the expectation.
|
||||||
func MatchFileContent(f func([]byte) CompareResult) PathOp {
|
func MatchFileContent(f func([]byte) CompareResult) PathOp {
|
||||||
return func(path Path) error {
|
return func(path Path) error {
|
||||||
|
@ -174,7 +174,7 @@ func MatchFileContent(f func([]byte) CompareResult) PathOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatchFilesWithGlob is a PathOp that updates a Manifest to match files using
|
// MatchFilesWithGlob is a [PathOp] that updates a [Manifest] to match files using
|
||||||
// glob pattern, and check them using the ops.
|
// glob pattern, and check them using the ops.
|
||||||
func MatchFilesWithGlob(glob string, ops ...PathOp) PathOp {
|
func MatchFilesWithGlob(glob string, ops ...PathOp) PathOp {
|
||||||
return func(path Path) error {
|
return func(path Path) error {
|
||||||
|
@ -188,7 +188,7 @@ func MatchFilesWithGlob(glob string, ops ...PathOp) PathOp {
|
||||||
// anyFileMode is represented by uint32_max
|
// anyFileMode is represented by uint32_max
|
||||||
const anyFileMode os.FileMode = 4294967295
|
const anyFileMode os.FileMode = 4294967295
|
||||||
|
|
||||||
// MatchAnyFileMode is a PathOp that updates a Manifest so that the resource at path
|
// MatchAnyFileMode is a [PathOp] that updates a [Manifest] so that the resource at path
|
||||||
// will match any file mode.
|
// will match any file mode.
|
||||||
func MatchAnyFileMode(path Path) error {
|
func MatchAnyFileMode(path Path) error {
|
||||||
if m, ok := path.(manifestResource); ok {
|
if m, ok := path.(manifestResource); ok {
|
||||||
|
|
|
@ -17,9 +17,9 @@ import (
|
||||||
// Equal compares a directory to the expected structured described by a manifest
|
// Equal compares a directory to the expected structured described by a manifest
|
||||||
// and returns success if they match. If they do not match the failure message
|
// and returns success if they match. If they do not match the failure message
|
||||||
// will contain all the differences between the directory structure and the
|
// will contain all the differences between the directory structure and the
|
||||||
// expected structure defined by the Manifest.
|
// expected structure defined by the [Manifest].
|
||||||
//
|
//
|
||||||
// Equal is a cmp.Comparison which can be used with assert.Assert().
|
// Equal is a [cmp.Comparison] which can be used with [gotest.tools/v3/assert.Assert].
|
||||||
func Equal(path string, expected Manifest) cmp.Comparison {
|
func Equal(path string, expected Manifest) cmp.Comparison {
|
||||||
return func() cmp.Result {
|
return func() cmp.Result {
|
||||||
actual, err := manifestFromDir(path)
|
actual, err := manifestFromDir(path)
|
||||||
|
|
|
@ -6,7 +6,7 @@ Golden files can be automatically updated to match new values by running
|
||||||
`go test pkgname -update`. 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.
|
compare the diff of the old expected value to the new expected value.
|
||||||
*/
|
*/
|
||||||
package golden // import "gotest.tools/v3/golden"
|
package golden
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -40,11 +40,19 @@ type helperT interface {
|
||||||
// in the environment before running tests.
|
// in the environment before running tests.
|
||||||
//
|
//
|
||||||
// The default value may change in a future major release.
|
// The default value may change in a future major release.
|
||||||
|
//
|
||||||
|
// This does not affect the contents of the golden files themselves. And depending on the
|
||||||
|
// git settings on your system (or in github action platform default like windows), the
|
||||||
|
// golden files may contain CRLF line endings. You can avoid this by setting the
|
||||||
|
// .gitattributes file in your repo to use LF line endings for all files, or just the golden
|
||||||
|
// files, by adding the following line to your .gitattributes file:
|
||||||
|
//
|
||||||
|
// * text=auto eol=lf
|
||||||
var NormalizeCRLFToLF = os.Getenv("GOTESTTOOLS_GOLDEN_NormalizeCRLFToLF") != "false"
|
var NormalizeCRLFToLF = os.Getenv("GOTESTTOOLS_GOLDEN_NormalizeCRLFToLF") != "false"
|
||||||
|
|
||||||
// FlagUpdate returns true when the -update flag has been set.
|
// FlagUpdate returns true when the -update flag has been set.
|
||||||
func FlagUpdate() bool {
|
func FlagUpdate() bool {
|
||||||
return source.Update
|
return source.IsUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open opens the file in ./testdata
|
// Open opens the file in ./testdata
|
||||||
|
@ -178,7 +186,7 @@ func compare(actual []byte, filename string) (cmp.Result, []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(filename string, actual []byte) error {
|
func update(filename string, actual []byte) error {
|
||||||
if !source.Update {
|
if !source.IsUpdate() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if dir := filepath.Dir(Path(filename)); dir != "." {
|
if dir := filepath.Dir(Path(filename)); dir != "." {
|
||||||
|
|
|
@ -26,7 +26,7 @@ func RunComparison(
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if source.Update {
|
if source.IsUpdate() {
|
||||||
if updater, ok := result.(updateExpected); ok {
|
if updater, ok := result.(updateExpected); ok {
|
||||||
const stackIndex = 3 // Assert/Check, assert, RunComparison
|
const stackIndex = 3 // Assert/Check, assert, RunComparison
|
||||||
err := updater.UpdatedExpected(stackIndex)
|
err := updater.UpdatedExpected(stackIndex)
|
||||||
|
|
|
@ -14,12 +14,32 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Update is set by the -update flag. It indicates the user running the tests
|
// IsUpdate is returns true if the -update flag is set. It indicates the user
|
||||||
// would like to update any golden values.
|
// running the tests would like to update any golden values.
|
||||||
|
func IsUpdate() bool {
|
||||||
|
if Update {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return flag.Lookup("update").Value.(flag.Getter).Get().(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is a shim for testing, and for compatibility with the old -update-golden
|
||||||
|
// flag.
|
||||||
var Update bool
|
var Update bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.BoolVar(&Update, "update", false, "update golden values")
|
if f := flag.Lookup("update"); f != nil {
|
||||||
|
getter, ok := f.Value.(flag.Getter)
|
||||||
|
msg := "some other package defined an incompatible -update flag, expected a flag.Bool"
|
||||||
|
if !ok {
|
||||||
|
panic(msg)
|
||||||
|
}
|
||||||
|
if _, ok := getter.Get().(bool); !ok {
|
||||||
|
panic(msg)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
flag.Bool("update", false, "update golden values")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrNotFound indicates that UpdateExpectedValue failed to find the
|
// ErrNotFound indicates that UpdateExpectedValue failed to find the
|
||||||
|
|
|
@ -460,7 +460,7 @@ google.golang.org/protobuf/types/known/timestamppb
|
||||||
# gopkg.in/yaml.v2 v2.4.0
|
# gopkg.in/yaml.v2 v2.4.0
|
||||||
## explicit; go 1.15
|
## explicit; go 1.15
|
||||||
gopkg.in/yaml.v2
|
gopkg.in/yaml.v2
|
||||||
# gotest.tools/v3 v3.5.0
|
# gotest.tools/v3 v3.5.1
|
||||||
## explicit; go 1.17
|
## explicit; go 1.17
|
||||||
gotest.tools/v3/assert
|
gotest.tools/v3/assert
|
||||||
gotest.tools/v3/assert/cmp
|
gotest.tools/v3/assert/cmp
|
||||||
|
|
Loading…
Reference in New Issue