mirror of https://github.com/docker/cli.git
vendor: gotest.tools/v3 v3.4.0
- removes github.com/spf13/pflag dependency - removes use of deprecated io/ioutil package - drops support for go1.16 full diff: https://github.com/gotestyourself/gotest.tools/compare/v3.3.0...v3.4.0 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
46ba87dcf1
commit
c855e4ba3b
|
@ -41,7 +41,7 @@ require (
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
||||||
golang.org/x/text v0.3.7
|
golang.org/x/text v0.3.7
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
gotest.tools/v3 v3.3.0
|
gotest.tools/v3 v3.4.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|
|
@ -751,8 +751,8 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C
|
||||||
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.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
||||||
gotest.tools/v3 v3.3.0 h1:MfDY1b1/0xN1CyMlQDac0ziEy9zJQd9CXBRRDHw2jJo=
|
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
|
||||||
gotest.tools/v3 v3.3.0/go.mod h1:Mcr9QNxkg0uMvy/YElmo4SpXgJKWgQvYrT7Kw5RzJ1A=
|
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
/*Package assert provides assertions for comparing expected values to actual
|
/*
|
||||||
|
Package assert provides assertions for comparing expected values to actual
|
||||||
values in tests. When an assertion fails a helpful error message is printed.
|
values in tests. When an assertion fails a helpful error message is printed.
|
||||||
|
|
||||||
Example usage
|
# Example usage
|
||||||
|
|
||||||
All the assertions in this package use testing.T.Helper to mark themselves as
|
All the assertions in this package use testing.T.Helper to mark themselves as
|
||||||
test helpers. This allows the testing package to print the filename and line
|
test helpers. This allows the testing package to print the filename and line
|
||||||
|
@ -64,7 +65,7 @@ message is omitted from these examples for brevity.
|
||||||
assert.Assert(t, ref != nil) // use Assert for NotNil
|
assert.Assert(t, ref != nil) // use Assert for NotNil
|
||||||
// assertion failed: ref is nil
|
// assertion failed: ref is nil
|
||||||
|
|
||||||
Assert and Check
|
# Assert and Check
|
||||||
|
|
||||||
Assert and Check are very similar, they both accept a Comparison, and fail
|
Assert and Check are very similar, they both accept a Comparison, and fail
|
||||||
the test when the comparison fails. The one difference is that Assert uses
|
the test when the comparison fails. The one difference is that Assert uses
|
||||||
|
@ -76,20 +77,18 @@ Like testing.T.FailNow, Assert must be called from the goroutine running the tes
|
||||||
not from other goroutines created during the test. Check is safe to use from any
|
not from other goroutines created during the test. Check is safe to use from any
|
||||||
goroutine.
|
goroutine.
|
||||||
|
|
||||||
Comparisons
|
# Comparisons
|
||||||
|
|
||||||
Package http://pkg.go.dev/gotest.tools/v3/assert/cmp provides
|
Package http://pkg.go.dev/gotest.tools/v3/assert/cmp provides
|
||||||
many common comparisons. Additional comparisons can be written to compare
|
many common comparisons. Additional comparisons can be written to compare
|
||||||
values in other ways. See the example Assert (CustomComparison).
|
values in other ways. See the example Assert (CustomComparison).
|
||||||
|
|
||||||
Automated migration from testify
|
# Automated migration from testify
|
||||||
|
|
||||||
gty-migrate-from-testify is a command which translates Go source code from
|
gty-migrate-from-testify is a command which translates Go source code from
|
||||||
testify assertions to the assertions provided by this package.
|
testify assertions to the assertions provided by this package.
|
||||||
|
|
||||||
See http://pkg.go.dev/gotest.tools/v3/assert/cmd/gty-migrate-from-testify.
|
See http://pkg.go.dev/gotest.tools/v3/assert/cmd/gty-migrate-from-testify.
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package assert // import "gotest.tools/v3/assert"
|
package assert // import "gotest.tools/v3/assert"
|
||||||
|
|
||||||
|
@ -119,19 +118,18 @@ type helperT interface {
|
||||||
//
|
//
|
||||||
// The comparison argument may be one of three types:
|
// The comparison argument may be one of three types:
|
||||||
//
|
//
|
||||||
// bool
|
// bool
|
||||||
// True is success. False is a failure. The failure message will contain
|
// True is success. False is a failure. The failure message will contain
|
||||||
// the literal source code of the expression.
|
// the literal source code of the expression.
|
||||||
//
|
//
|
||||||
// cmp.Comparison
|
// cmp.Comparison
|
||||||
// Uses cmp.Result.Success() to check for success or failure.
|
// Uses cmp.Result.Success() to check for success or failure.
|
||||||
// The comparison is responsible for producing a helpful failure message.
|
// The comparison is responsible for producing a helpful failure message.
|
||||||
// http://pkg.go.dev/gotest.tools/v3/assert/cmp provides many common comparisons.
|
// http://pkg.go.dev/gotest.tools/v3/assert/cmp provides many common comparisons.
|
||||||
//
|
|
||||||
// error
|
|
||||||
// A nil value is considered success, and a non-nil error is a failure.
|
|
||||||
// The return value of error.Error is used as the failure message.
|
|
||||||
//
|
//
|
||||||
|
// error
|
||||||
|
// A nil value is considered success, and a non-nil error is a failure.
|
||||||
|
// The return value of error.Error is used as the failure message.
|
||||||
//
|
//
|
||||||
// Extra details can be added to the failure message using msgAndArgs. msgAndArgs
|
// Extra details can be added to the failure message using msgAndArgs. msgAndArgs
|
||||||
// may be either a single string, or a format string and args that will be
|
// may be either a single string, or a format string and args that will be
|
||||||
|
@ -187,8 +185,8 @@ func NilError(t TestingT, err error, msgAndArgs ...interface{}) {
|
||||||
// x and y as part of the failure message to identify the actual and expected
|
// x and y as part of the failure message to identify the actual and expected
|
||||||
// values.
|
// values.
|
||||||
//
|
//
|
||||||
// assert.Equal(t, actual, expected)
|
// assert.Equal(t, actual, expected)
|
||||||
// // main_test.go:41: assertion failed: 1 (actual int) != 21 (expected int32)
|
// // main_test.go:41: assertion failed: 1 (actual int) != 21 (expected int32)
|
||||||
//
|
//
|
||||||
// If either x or y are a multi-line string the failure message will include a
|
// If either x or y are a multi-line string the failure message will include a
|
||||||
// unified diff of the two values. If the values only differ by whitespace
|
// unified diff of the two values. If the values only differ by whitespace
|
||||||
|
@ -269,19 +267,19 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
|
||||||
//
|
//
|
||||||
// Expected can be one of:
|
// Expected can be one of:
|
||||||
//
|
//
|
||||||
// func(error) bool
|
// func(error) bool
|
||||||
// The function should return true if the error is the expected type.
|
// The function should return true if the error is the expected type.
|
||||||
//
|
//
|
||||||
// struct{} or *struct{}
|
// struct{} or *struct{}
|
||||||
// A struct or a pointer to a struct. The assertion fails if the error is
|
// A struct or a pointer to a struct. The assertion fails if the error is
|
||||||
// not of the same type.
|
// not of the same type.
|
||||||
//
|
//
|
||||||
// *interface{}
|
// *interface{}
|
||||||
// A pointer to an interface type. The assertion fails if err does not
|
// A pointer to an interface type. The assertion fails if err does not
|
||||||
// implement the interface.
|
// implement the interface.
|
||||||
//
|
//
|
||||||
// reflect.Type
|
// reflect.Type
|
||||||
// The assertion fails if err does not implement the reflect.Type.
|
// The assertion fails if err does not implement the reflect.Type.
|
||||||
//
|
//
|
||||||
// ErrorType uses t.FailNow to fail the test. Like t.FailNow, ErrorType
|
// ErrorType uses t.FailNow to fail the test. Like t.FailNow, ErrorType
|
||||||
// must be called from the goroutine running the test function, not from other
|
// must be called from the goroutine running the test function, not from other
|
||||||
|
|
|
@ -68,9 +68,10 @@ type RegexOrPattern interface{}
|
||||||
// Regexp succeeds if value v matches regular expression re.
|
// Regexp succeeds if value v matches regular expression re.
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
// assert.Assert(t, cmp.Regexp("^[0-9a-f]{32}$", str))
|
//
|
||||||
// r := regexp.MustCompile("^[0-9a-f]{32}$")
|
// assert.Assert(t, cmp.Regexp("^[0-9a-f]{32}$", str))
|
||||||
// assert.Assert(t, cmp.Regexp(r, str))
|
// r := regexp.MustCompile("^[0-9a-f]{32}$")
|
||||||
|
// assert.Assert(t, cmp.Regexp(r, str))
|
||||||
func Regexp(re RegexOrPattern, v string) Comparison {
|
func Regexp(re RegexOrPattern, v string) Comparison {
|
||||||
match := func(re *regexp.Regexp) Result {
|
match := func(re *regexp.Regexp) Result {
|
||||||
return toResult(
|
return toResult(
|
||||||
|
@ -248,7 +249,7 @@ type causer interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatErrorMessage(err error) string {
|
func formatErrorMessage(err error) string {
|
||||||
// nolint: errorlint // unwrapping is not appropriate here
|
//nolint:errorlint // unwrapping is not appropriate here
|
||||||
if _, ok := err.(causer); ok {
|
if _, ok := err.(causer); ok {
|
||||||
return fmt.Sprintf("%q\n%+v", err, err)
|
return fmt.Sprintf("%q\n%+v", err, err)
|
||||||
}
|
}
|
||||||
|
@ -288,15 +289,23 @@ func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison {
|
||||||
// ErrorType succeeds if err is not nil and is of the expected type.
|
// ErrorType succeeds if err is not nil and is of the expected type.
|
||||||
//
|
//
|
||||||
// Expected can be one of:
|
// Expected can be one of:
|
||||||
// func(error) bool
|
//
|
||||||
|
// func(error) bool
|
||||||
|
//
|
||||||
// Function should return true if the error is the expected type.
|
// Function should return true if the error is the expected type.
|
||||||
// type struct{}, type &struct{}
|
//
|
||||||
|
// type struct{}, type &struct{}
|
||||||
|
//
|
||||||
// A struct or a pointer to a struct.
|
// A struct or a pointer to a struct.
|
||||||
// Fails if the error is not of the same type as expected.
|
// Fails if the error is not of the same type as expected.
|
||||||
// type &interface{}
|
//
|
||||||
|
// type &interface{}
|
||||||
|
//
|
||||||
// A pointer to an interface type.
|
// A pointer to an interface type.
|
||||||
// Fails if err does not implement the interface.
|
// Fails if err does not implement the interface.
|
||||||
// reflect.Type
|
//
|
||||||
|
// reflect.Type
|
||||||
|
//
|
||||||
// Fails if err does not implement the reflect.Type
|
// Fails if err does not implement the reflect.Type
|
||||||
func ErrorType(err error, expected interface{}) Comparison {
|
func ErrorType(err error, expected interface{}) Comparison {
|
||||||
return func() Result {
|
return func() Result {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/*Package env provides functions to test code that read environment variables
|
/*
|
||||||
|
Package env provides functions to test code that read environment variables
|
||||||
or the current working directory.
|
or the current working directory.
|
||||||
*/
|
*/
|
||||||
package env // import "gotest.tools/v3/env"
|
package env // import "gotest.tools/v3/env"
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*Package fs provides tools for creating temporary files, and testing the
|
/*
|
||||||
|
Package fs provides tools for creating temporary files, and testing the
|
||||||
contents and structure of a directory.
|
contents and structure of a directory.
|
||||||
*/
|
*/
|
||||||
package fs // import "gotest.tools/v3/fs"
|
package fs // import "gotest.tools/v3/fs"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -45,7 +45,7 @@ func NewFile(t assert.TestingT, prefix string, ops ...PathOp) *File {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
tempfile, err := ioutil.TempFile("", cleanPrefix(prefix)+"-")
|
tempfile, err := os.CreateTemp("", cleanPrefix(prefix)+"-")
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
file := &File{path: tempfile.Name()}
|
file := &File{path: tempfile.Name()}
|
||||||
|
@ -71,8 +71,7 @@ func (f *File) Path() string {
|
||||||
|
|
||||||
// Remove the file
|
// Remove the file
|
||||||
func (f *File) Remove() {
|
func (f *File) Remove() {
|
||||||
// nolint: errcheck
|
_ = os.Remove(f.path)
|
||||||
os.Remove(f.path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dir is a temporary directory
|
// Dir is a temporary directory
|
||||||
|
@ -89,7 +88,7 @@ func NewDir(t assert.TestingT, prefix string, ops ...PathOp) *Dir {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
path, err := ioutil.TempDir("", cleanPrefix(prefix)+"-")
|
path, err := os.MkdirTemp("", cleanPrefix(prefix)+"-")
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
dir := &Dir{path: path}
|
dir := &Dir{path: path}
|
||||||
cleanup.Cleanup(t, dir.Remove)
|
cleanup.Cleanup(t, dir.Remove)
|
||||||
|
@ -105,8 +104,7 @@ func (d *Dir) Path() string {
|
||||||
|
|
||||||
// Remove the directory
|
// Remove the directory
|
||||||
func (d *Dir) Remove() {
|
func (d *Dir) Remove() {
|
||||||
// nolint: errcheck
|
_ = os.RemoveAll(d.path)
|
||||||
os.RemoveAll(d.path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join returns a new path with this directory as the base of the path
|
// Join returns a new path with this directory as the base of the path
|
||||||
|
|
|
@ -3,7 +3,6 @@ package fs
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
@ -84,7 +83,7 @@ func manifestFromDir(path string) (Manifest, error) {
|
||||||
|
|
||||||
func newDirectory(path string, info os.FileInfo) (*directory, error) {
|
func newDirectory(path string, info os.FileInfo) (*directory, error) {
|
||||||
items := make(map[string]dirEntry)
|
items := make(map[string]dirEntry)
|
||||||
children, err := ioutil.ReadDir(path)
|
children, err := os.ReadDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -103,7 +102,11 @@ func newDirectory(path string, info os.FileInfo) (*directory, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTypedResource(path string, info os.FileInfo) (dirEntry, error) {
|
func getTypedResource(path string, entry os.DirEntry) (dirEntry, error) {
|
||||||
|
info, err := entry.Info()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
switch {
|
switch {
|
||||||
case info.IsDir():
|
case info.IsDir():
|
||||||
return newDirectory(path, info)
|
return newDirectory(path, info)
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -43,10 +42,10 @@ type manifestDirectory interface {
|
||||||
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 {
|
||||||
m.SetContent(ioutil.NopCloser(strings.NewReader(content)))
|
m.SetContent(io.NopCloser(strings.NewReader(content)))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(path.Path(), []byte(content), defaultFileMode)
|
return os.WriteFile(path.Path(), []byte(content), defaultFileMode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,10 +53,10 @@ func WithContent(content string) PathOp {
|
||||||
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 {
|
||||||
m.SetContent(ioutil.NopCloser(bytes.NewReader(raw)))
|
m.SetContent(io.NopCloser(bytes.NewReader(raw)))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(path.Path(), raw, defaultFileMode)
|
return os.WriteFile(path.Path(), raw, defaultFileMode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +64,7 @@ func WithBytes(raw []byte) PathOp {
|
||||||
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 {
|
||||||
m.SetContent(ioutil.NopCloser(r))
|
m.SetContent(io.NopCloser(r))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
f, err := os.OpenFile(path.Path(), os.O_WRONLY, defaultFileMode)
|
f, err := os.OpenFile(path.Path(), os.O_WRONLY, defaultFileMode)
|
||||||
|
@ -107,7 +106,7 @@ func WithFile(filename, content string, ops ...PathOp) PathOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createFile(fullpath string, content string) error {
|
func createFile(fullpath string, content string) error {
|
||||||
return ioutil.WriteFile(fullpath, []byte(content), defaultFileMode)
|
return os.WriteFile(fullpath, []byte(content), defaultFileMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithFiles creates all the files in the directory at path with their content
|
// WithFiles creates all the files in the directory at path with their content
|
||||||
|
@ -191,34 +190,38 @@ func WithMode(mode os.FileMode) PathOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyDirectory(source, dest string) error {
|
func copyDirectory(source, dest string) error {
|
||||||
entries, err := ioutil.ReadDir(source)
|
entries, err := os.ReadDir(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
sourcePath := filepath.Join(source, entry.Name())
|
sourcePath := filepath.Join(source, entry.Name())
|
||||||
destPath := filepath.Join(dest, entry.Name())
|
destPath := filepath.Join(dest, entry.Name())
|
||||||
switch {
|
err = copyEntry(entry, destPath, sourcePath)
|
||||||
case entry.IsDir():
|
if err != nil {
|
||||||
if err := os.Mkdir(destPath, 0755); err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := copyDirectory(sourcePath, destPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case entry.Mode()&os.ModeSymlink != 0:
|
|
||||||
if err := copySymLink(sourcePath, destPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
if err := copyFile(sourcePath, destPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copyEntry(entry os.DirEntry, destPath string, sourcePath string) error {
|
||||||
|
if entry.IsDir() {
|
||||||
|
if err := os.Mkdir(destPath, 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return copyDirectory(sourcePath, destPath)
|
||||||
|
}
|
||||||
|
info, err := entry.Info()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if info.Mode()&os.ModeSymlink != 0 {
|
||||||
|
return copySymLink(sourcePath, destPath)
|
||||||
|
}
|
||||||
|
return copyFile(sourcePath, destPath)
|
||||||
|
}
|
||||||
|
|
||||||
func copySymLink(source, dest string) error {
|
func copySymLink(source, dest string) error {
|
||||||
link, err := os.Readlink(source)
|
link, err := os.Readlink(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -228,11 +231,11 @@ func copySymLink(source, dest string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyFile(source, dest string) error {
|
func copyFile(source, dest string) error {
|
||||||
content, err := ioutil.ReadFile(source)
|
content, err := os.ReadFile(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(dest, content, 0644)
|
return os.WriteFile(dest, content, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithSymlink creates a symlink in the directory which links to target.
|
// WithSymlink creates a symlink in the directory which links to target.
|
||||||
|
|
|
@ -3,7 +3,6 @@ package fs
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
|
@ -124,7 +123,7 @@ func normalizeID(id int) uint32 {
|
||||||
return uint32(id)
|
return uint32(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
var anyFileContent = ioutil.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.
|
||||||
|
|
|
@ -3,7 +3,7 @@ package fs
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -86,9 +86,9 @@ func eqFile(x, y *file) []problem {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
xContent, xErr := ioutil.ReadAll(x.content)
|
xContent, xErr := io.ReadAll(x.content)
|
||||||
defer x.content.Close()
|
defer x.content.Close()
|
||||||
yContent, yErr := ioutil.ReadAll(y.content)
|
yContent, yErr := io.ReadAll(y.content)
|
||||||
defer y.content.Close()
|
defer y.content.Close()
|
||||||
|
|
||||||
if xErr != nil {
|
if xErr != nil {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/*Package golden provides tools for comparing large mutli-line strings.
|
/*
|
||||||
|
Package golden provides tools for comparing large mutli-line strings.
|
||||||
|
|
||||||
Golden files are files in the ./testdata/ subdirectory of the package under test.
|
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
|
Golden files can be automatically updated to match new values by running
|
||||||
|
@ -11,7 +12,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ func Get(t assert.TestingT, filename string) []byte {
|
||||||
if ht, ok := t.(helperT); ok {
|
if ht, ok := t.(helperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
expected, err := ioutil.ReadFile(Path(filename))
|
expected, err := os.ReadFile(Path(filename))
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
return expected
|
return expected
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ func compare(actual []byte, filename string) (cmp.Result, []byte) {
|
||||||
if err := update(filename, actual); err != nil {
|
if err := update(filename, actual); err != nil {
|
||||||
return cmp.ResultFromError(err), nil
|
return cmp.ResultFromError(err), nil
|
||||||
}
|
}
|
||||||
expected, err := ioutil.ReadFile(Path(filename))
|
expected, err := os.ReadFile(Path(filename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmp.ResultFromError(err), nil
|
return cmp.ResultFromError(err), nil
|
||||||
}
|
}
|
||||||
|
@ -186,5 +186,5 @@ func update(filename string, actual []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(Path(filename), actual, 0644)
|
return os.WriteFile(Path(filename), actual, 0644)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
exec "golang.org/x/sys/execabs"
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
"gotest.tools/v3/assert/cmp"
|
"gotest.tools/v3/assert/cmp"
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,8 +2,7 @@ package icmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"os/exec"
|
||||||
exec "golang.org/x/sys/execabs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func processExitCode(err error) int {
|
func processExitCode(err error) int {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Package assert provides internal utilties for assertions.
|
||||||
package assert
|
package assert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/*Package cleanup handles migration to and support for the Go 1.14+
|
/*
|
||||||
|
Package cleanup handles migration to and support for the Go 1.14+
|
||||||
testing.TB.Cleanup() function.
|
testing.TB.Cleanup() function.
|
||||||
*/
|
*/
|
||||||
package cleanup
|
package cleanup
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Package format provides utilities for formatting diffs and messages.
|
||||||
package format
|
package format
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Package source provides utilities for handling source-code.
|
||||||
package source // import "gotest.tools/v3/internal/source"
|
package source // import "gotest.tools/v3/internal/source"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -54,8 +54,8 @@ func UpdateExpectedValue(stackIndex int, x, y interface{}) error {
|
||||||
return ErrNotFound
|
return ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
argIndex, varName := getVarNameForExpectedValueArg(expr)
|
argIndex, ident := getIdentForExpectedValueArg(expr)
|
||||||
if argIndex < 0 || varName == "" {
|
if argIndex < 0 || ident == nil {
|
||||||
debug("no arguments started with the word 'expected': %v",
|
debug("no arguments started with the word 'expected': %v",
|
||||||
debugFormatNode{Node: &ast.CallExpr{Args: expr}})
|
debugFormatNode{Node: &ast.CallExpr{Args: expr}})
|
||||||
return ErrNotFound
|
return ErrNotFound
|
||||||
|
@ -71,7 +71,7 @@ func UpdateExpectedValue(stackIndex int, x, y interface{}) error {
|
||||||
debug("value must be type string, got %T", value)
|
debug("value must be type string, got %T", value)
|
||||||
return ErrNotFound
|
return ErrNotFound
|
||||||
}
|
}
|
||||||
return UpdateVariable(filename, fileset, astFile, varName, strValue)
|
return UpdateVariable(filename, fileset, astFile, ident, strValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateVariable writes to filename the contents of astFile with the value of
|
// UpdateVariable writes to filename the contents of astFile with the value of
|
||||||
|
@ -80,10 +80,10 @@ func UpdateVariable(
|
||||||
filename string,
|
filename string,
|
||||||
fileset *token.FileSet,
|
fileset *token.FileSet,
|
||||||
astFile *ast.File,
|
astFile *ast.File,
|
||||||
varName string,
|
ident *ast.Ident,
|
||||||
value string,
|
value string,
|
||||||
) error {
|
) error {
|
||||||
obj := astFile.Scope.Objects[varName]
|
obj := ident.Obj
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
return ErrNotFound
|
return ErrNotFound
|
||||||
}
|
}
|
||||||
|
@ -92,20 +92,33 @@ func UpdateVariable(
|
||||||
return ErrNotFound
|
return ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
spec, ok := obj.Decl.(*ast.ValueSpec)
|
switch decl := obj.Decl.(type) {
|
||||||
if !ok {
|
case *ast.ValueSpec:
|
||||||
|
if len(decl.Names) != 1 {
|
||||||
|
debug("more than one name in ast.ValueSpec")
|
||||||
|
return ErrNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
decl.Values[0] = &ast.BasicLit{
|
||||||
|
Kind: token.STRING,
|
||||||
|
Value: "`" + value + "`",
|
||||||
|
}
|
||||||
|
|
||||||
|
case *ast.AssignStmt:
|
||||||
|
if len(decl.Lhs) != 1 {
|
||||||
|
debug("more than one name in ast.AssignStmt")
|
||||||
|
return ErrNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
decl.Rhs[0] = &ast.BasicLit{
|
||||||
|
Kind: token.STRING,
|
||||||
|
Value: "`" + value + "`",
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
debug("can only update *ast.ValueSpec, found %T", obj.Decl)
|
debug("can only update *ast.ValueSpec, found %T", obj.Decl)
|
||||||
return ErrNotFound
|
return ErrNotFound
|
||||||
}
|
}
|
||||||
if len(spec.Names) != 1 {
|
|
||||||
debug("more than one name in ast.ValueSpec")
|
|
||||||
return ErrNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
spec.Values[0] = &ast.BasicLit{
|
|
||||||
Kind: token.STRING,
|
|
||||||
Value: "`" + value + "`",
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if err := format.Node(&buf, fileset, astFile); err != nil {
|
if err := format.Node(&buf, fileset, astFile); err != nil {
|
||||||
|
@ -125,14 +138,14 @@ func UpdateVariable(
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVarNameForExpectedValueArg(expr []ast.Expr) (int, string) {
|
func getIdentForExpectedValueArg(expr []ast.Expr) (int, *ast.Ident) {
|
||||||
for i := 1; i < 3; i++ {
|
for i := 1; i < 3; i++ {
|
||||||
switch e := expr[i].(type) {
|
switch e := expr[i].(type) {
|
||||||
case *ast.Ident:
|
case *ast.Ident:
|
||||||
if strings.HasPrefix(strings.ToLower(e.Name), "expected") {
|
if strings.HasPrefix(strings.ToLower(e.Name), "expected") {
|
||||||
return i, e.Name
|
return i, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1, ""
|
return -1, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/*Package skip provides functions for skipping a test and printing the source code
|
/*
|
||||||
|
Package skip provides functions for skipping a test and printing the source code
|
||||||
of the condition used to skip the test.
|
of the condition used to skip the test.
|
||||||
*/
|
*/
|
||||||
package skip // import "gotest.tools/v3/skip"
|
package skip // import "gotest.tools/v3/skip"
|
||||||
|
|
|
@ -377,7 +377,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.3.0
|
# gotest.tools/v3 v3.4.0
|
||||||
## explicit; go 1.13
|
## explicit; go 1.13
|
||||||
gotest.tools/v3/assert
|
gotest.tools/v3/assert
|
||||||
gotest.tools/v3/assert/cmp
|
gotest.tools/v3/assert/cmp
|
||||||
|
|
Loading…
Reference in New Issue