From c855e4ba3b527e86f685d831d00131821e7a29b6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 5 Nov 2022 23:25:29 +0100 Subject: [PATCH] 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 --- vendor.mod | 2 +- vendor.sum | 4 +- vendor/gotest.tools/v3/assert/assert.go | 58 +++++++++---------- vendor/gotest.tools/v3/assert/cmp/compare.go | 25 +++++--- vendor/gotest.tools/v3/env/env.go | 3 +- vendor/gotest.tools/v3/fs/file.go | 14 ++--- vendor/gotest.tools/v3/fs/manifest.go | 9 ++- vendor/gotest.tools/v3/fs/ops.go | 55 +++++++++--------- vendor/gotest.tools/v3/fs/path.go | 3 +- vendor/gotest.tools/v3/fs/report.go | 6 +- vendor/gotest.tools/v3/golden/golden.go | 10 ++-- vendor/gotest.tools/v3/icmd/command.go | 2 +- vendor/gotest.tools/v3/icmd/exitcode.go | 3 +- .../gotest.tools/v3/internal/assert/assert.go | 1 + .../v3/internal/cleanup/cleanup.go | 3 +- .../gotest.tools/v3/internal/format/diff.go | 1 + .../gotest.tools/v3/internal/source/source.go | 1 + .../gotest.tools/v3/internal/source/update.go | 51 ++++++++++------ vendor/gotest.tools/v3/skip/skip.go | 3 +- vendor/modules.txt | 2 +- 20 files changed, 142 insertions(+), 114 deletions(-) diff --git a/vendor.mod b/vendor.mod index 0ce2966dc2..bf7f574d7b 100644 --- a/vendor.mod +++ b/vendor.mod @@ -41,7 +41,7 @@ require ( golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 golang.org/x/text v0.3.7 gopkg.in/yaml.v2 v2.4.0 - gotest.tools/v3 v3.3.0 + gotest.tools/v3 v3.4.0 ) require ( diff --git a/vendor.sum b/vendor.sum index 5022b2b315..cf76675fc5 100644 --- a/vendor.sum +++ b/vendor.sum @@ -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/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 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.3.0/go.mod h1:Mcr9QNxkg0uMvy/YElmo4SpXgJKWgQvYrT7Kw5RzJ1A= +gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= +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-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/vendor/gotest.tools/v3/assert/assert.go b/vendor/gotest.tools/v3/assert/assert.go index dbd4f5a016..f75f9f510e 100644 --- a/vendor/gotest.tools/v3/assert/assert.go +++ b/vendor/gotest.tools/v3/assert/assert.go @@ -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. -Example usage +# Example usage 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 @@ -64,7 +65,7 @@ message is omitted from these examples for brevity. assert.Assert(t, ref != nil) // use Assert for NotNil // assertion failed: ref is nil -Assert and Check +# Assert and Check 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 @@ -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 goroutine. -Comparisons +# Comparisons Package http://pkg.go.dev/gotest.tools/v3/assert/cmp provides many common comparisons. Additional comparisons can be written to compare 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 testify assertions to the assertions provided by this package. See http://pkg.go.dev/gotest.tools/v3/assert/cmd/gty-migrate-from-testify. - - */ package assert // import "gotest.tools/v3/assert" @@ -119,19 +118,18 @@ type helperT interface { // // The comparison argument may be one of three types: // -// bool -// True is success. False is a failure. The failure message will contain -// the literal source code of the expression. +// bool +// True is success. False is a failure. The failure message will contain +// the literal source code of the expression. // -// cmp.Comparison -// Uses cmp.Result.Success() to check for success or failure. -// The comparison is responsible for producing a helpful failure message. -// 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. +// cmp.Comparison +// Uses cmp.Result.Success() to check for success or failure. +// The comparison is responsible for producing a helpful failure message. +// 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. // // 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 @@ -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 // values. // -// assert.Equal(t, actual, expected) -// // main_test.go:41: assertion failed: 1 (actual int) != 21 (expected int32) +// assert.Equal(t, actual, expected) +// // 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 // 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: // -// func(error) bool -// The function should return true if the error is the expected type. +// func(error) bool +// The function should return true if the error is the expected type. // -// struct{} or *struct{} -// A struct or a pointer to a struct. The assertion fails if the error is -// not of the same type. +// struct{} or *struct{} +// A struct or a pointer to a struct. The assertion fails if the error is +// not of the same type. // -// *interface{} -// A pointer to an interface type. The assertion fails if err does not -// implement the interface. +// *interface{} +// A pointer to an interface type. The assertion fails if err does not +// implement the interface. // -// reflect.Type -// The assertion fails if err does not implement the reflect.Type. +// 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 // must be called from the goroutine running the test function, not from other diff --git a/vendor/gotest.tools/v3/assert/cmp/compare.go b/vendor/gotest.tools/v3/assert/cmp/compare.go index 78f76e4e88..4112b00433 100644 --- a/vendor/gotest.tools/v3/assert/cmp/compare.go +++ b/vendor/gotest.tools/v3/assert/cmp/compare.go @@ -68,9 +68,10 @@ type RegexOrPattern interface{} // Regexp succeeds if value v matches regular expression re. // // Example: -// assert.Assert(t, cmp.Regexp("^[0-9a-f]{32}$", str)) -// r := regexp.MustCompile("^[0-9a-f]{32}$") -// assert.Assert(t, cmp.Regexp(r, str)) +// +// assert.Assert(t, cmp.Regexp("^[0-9a-f]{32}$", str)) +// r := regexp.MustCompile("^[0-9a-f]{32}$") +// assert.Assert(t, cmp.Regexp(r, str)) func Regexp(re RegexOrPattern, v string) Comparison { match := func(re *regexp.Regexp) Result { return toResult( @@ -248,7 +249,7 @@ type causer interface { } func formatErrorMessage(err error) string { - // nolint: errorlint // unwrapping is not appropriate here + //nolint:errorlint // unwrapping is not appropriate here if _, ok := err.(causer); ok { 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. // // Expected can be one of: -// func(error) bool +// +// func(error) bool +// // 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. // Fails if the error is not of the same type as expected. -// type &interface{} +// +// type &interface{} +// // A pointer to an interface type. // Fails if err does not implement the interface. -// reflect.Type +// +// reflect.Type +// // Fails if err does not implement the reflect.Type func ErrorType(err error, expected interface{}) Comparison { return func() Result { diff --git a/vendor/gotest.tools/v3/env/env.go b/vendor/gotest.tools/v3/env/env.go index a06eab3ebe..71efc39307 100644 --- a/vendor/gotest.tools/v3/env/env.go +++ b/vendor/gotest.tools/v3/env/env.go @@ -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. */ package env // import "gotest.tools/v3/env" diff --git a/vendor/gotest.tools/v3/fs/file.go b/vendor/gotest.tools/v3/fs/file.go index 3ca5660399..f778e9c883 100644 --- a/vendor/gotest.tools/v3/fs/file.go +++ b/vendor/gotest.tools/v3/fs/file.go @@ -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. */ package fs // import "gotest.tools/v3/fs" import ( - "io/ioutil" "os" "path/filepath" "runtime" @@ -45,7 +45,7 @@ func NewFile(t assert.TestingT, prefix string, ops ...PathOp) *File { if ht, ok := t.(helperT); ok { ht.Helper() } - tempfile, err := ioutil.TempFile("", cleanPrefix(prefix)+"-") + tempfile, err := os.CreateTemp("", cleanPrefix(prefix)+"-") assert.NilError(t, err) file := &File{path: tempfile.Name()} @@ -71,8 +71,7 @@ func (f *File) Path() string { // Remove the file func (f *File) Remove() { - // nolint: errcheck - os.Remove(f.path) + _ = os.Remove(f.path) } // 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 { ht.Helper() } - path, err := ioutil.TempDir("", cleanPrefix(prefix)+"-") + path, err := os.MkdirTemp("", cleanPrefix(prefix)+"-") assert.NilError(t, err) dir := &Dir{path: path} cleanup.Cleanup(t, dir.Remove) @@ -105,8 +104,7 @@ func (d *Dir) Path() string { // Remove the directory 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 diff --git a/vendor/gotest.tools/v3/fs/manifest.go b/vendor/gotest.tools/v3/fs/manifest.go index b657bd96a9..44348c59ee 100644 --- a/vendor/gotest.tools/v3/fs/manifest.go +++ b/vendor/gotest.tools/v3/fs/manifest.go @@ -3,7 +3,6 @@ package fs import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" @@ -84,7 +83,7 @@ func manifestFromDir(path string) (Manifest, error) { func newDirectory(path string, info os.FileInfo) (*directory, error) { items := make(map[string]dirEntry) - children, err := ioutil.ReadDir(path) + children, err := os.ReadDir(path) if err != nil { return nil, err } @@ -103,7 +102,11 @@ func newDirectory(path string, info os.FileInfo) (*directory, error) { }, 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 { case info.IsDir(): return newDirectory(path, info) diff --git a/vendor/gotest.tools/v3/fs/ops.go b/vendor/gotest.tools/v3/fs/ops.go index 9e1e068b26..1bb72e3627 100644 --- a/vendor/gotest.tools/v3/fs/ops.go +++ b/vendor/gotest.tools/v3/fs/ops.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -43,10 +42,10 @@ type manifestDirectory interface { func WithContent(content string) PathOp { return func(path Path) error { if m, ok := path.(manifestFile); ok { - m.SetContent(ioutil.NopCloser(strings.NewReader(content))) + m.SetContent(io.NopCloser(strings.NewReader(content))) 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 { return func(path Path) error { if m, ok := path.(manifestFile); ok { - m.SetContent(ioutil.NopCloser(bytes.NewReader(raw))) + m.SetContent(io.NopCloser(bytes.NewReader(raw))) 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 { return func(path Path) error { if m, ok := path.(manifestFile); ok { - m.SetContent(ioutil.NopCloser(r)) + m.SetContent(io.NopCloser(r)) return nil } 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 { - 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 @@ -191,34 +190,38 @@ func WithMode(mode os.FileMode) PathOp { } func copyDirectory(source, dest string) error { - entries, err := ioutil.ReadDir(source) + entries, err := os.ReadDir(source) if err != nil { return err } for _, entry := range entries { sourcePath := filepath.Join(source, entry.Name()) destPath := filepath.Join(dest, entry.Name()) - switch { - case entry.IsDir(): - if err := os.Mkdir(destPath, 0755); err != nil { - 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 - } + err = copyEntry(entry, destPath, sourcePath) + if err != nil { + return err } } 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 { link, err := os.Readlink(source) if err != nil { @@ -228,11 +231,11 @@ func copySymLink(source, dest string) error { } func copyFile(source, dest string) error { - content, err := ioutil.ReadFile(source) + content, err := os.ReadFile(source) if err != nil { 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. diff --git a/vendor/gotest.tools/v3/fs/path.go b/vendor/gotest.tools/v3/fs/path.go index c301b90489..550044a05c 100644 --- a/vendor/gotest.tools/v3/fs/path.go +++ b/vendor/gotest.tools/v3/fs/path.go @@ -3,7 +3,6 @@ package fs import ( "bytes" "io" - "io/ioutil" "os" "gotest.tools/v3/assert" @@ -124,7 +123,7 @@ func normalizeID(id int) uint32 { 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 // at path may contain any content. diff --git a/vendor/gotest.tools/v3/fs/report.go b/vendor/gotest.tools/v3/fs/report.go index 1a3c6683bd..5e79e49b59 100644 --- a/vendor/gotest.tools/v3/fs/report.go +++ b/vendor/gotest.tools/v3/fs/report.go @@ -3,7 +3,7 @@ package fs import ( "bytes" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "runtime" @@ -86,9 +86,9 @@ func eqFile(x, y *file) []problem { return p } - xContent, xErr := ioutil.ReadAll(x.content) + xContent, xErr := io.ReadAll(x.content) defer x.content.Close() - yContent, yErr := ioutil.ReadAll(y.content) + yContent, yErr := io.ReadAll(y.content) defer y.content.Close() if xErr != nil { diff --git a/vendor/gotest.tools/v3/golden/golden.go b/vendor/gotest.tools/v3/golden/golden.go index 47ea85fe02..ce96ba173a 100644 --- a/vendor/gotest.tools/v3/golden/golden.go +++ b/vendor/gotest.tools/v3/golden/golden.go @@ -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 can be automatically updated to match new values by running @@ -11,7 +12,6 @@ import ( "bytes" "flag" "fmt" - "io/ioutil" "os" "path/filepath" @@ -62,7 +62,7 @@ func Get(t assert.TestingT, filename string) []byte { if ht, ok := t.(helperT); ok { ht.Helper() } - expected, err := ioutil.ReadFile(Path(filename)) + expected, err := os.ReadFile(Path(filename)) assert.NilError(t, err) return expected } @@ -167,7 +167,7 @@ func compare(actual []byte, filename string) (cmp.Result, []byte) { if err := update(filename, actual); err != nil { return cmp.ResultFromError(err), nil } - expected, err := ioutil.ReadFile(Path(filename)) + expected, err := os.ReadFile(Path(filename)) if err != nil { return cmp.ResultFromError(err), nil } @@ -186,5 +186,5 @@ func update(filename string, actual []byte) error { return err } } - return ioutil.WriteFile(Path(filename), actual, 0644) + return os.WriteFile(Path(filename), actual, 0644) } diff --git a/vendor/gotest.tools/v3/icmd/command.go b/vendor/gotest.tools/v3/icmd/command.go index 9613322806..a15834bab4 100644 --- a/vendor/gotest.tools/v3/icmd/command.go +++ b/vendor/gotest.tools/v3/icmd/command.go @@ -7,11 +7,11 @@ import ( "fmt" "io" "os" + "os/exec" "strings" "sync" "time" - exec "golang.org/x/sys/execabs" "gotest.tools/v3/assert" "gotest.tools/v3/assert/cmp" ) diff --git a/vendor/gotest.tools/v3/icmd/exitcode.go b/vendor/gotest.tools/v3/icmd/exitcode.go index 2e98f86c1a..4e48fc4fed 100644 --- a/vendor/gotest.tools/v3/icmd/exitcode.go +++ b/vendor/gotest.tools/v3/icmd/exitcode.go @@ -2,8 +2,7 @@ package icmd import ( "errors" - - exec "golang.org/x/sys/execabs" + "os/exec" ) func processExitCode(err error) int { diff --git a/vendor/gotest.tools/v3/internal/assert/assert.go b/vendor/gotest.tools/v3/internal/assert/assert.go index 0d67751da8..2dd80255ab 100644 --- a/vendor/gotest.tools/v3/internal/assert/assert.go +++ b/vendor/gotest.tools/v3/internal/assert/assert.go @@ -1,3 +1,4 @@ +// Package assert provides internal utilties for assertions. package assert import ( diff --git a/vendor/gotest.tools/v3/internal/cleanup/cleanup.go b/vendor/gotest.tools/v3/internal/cleanup/cleanup.go index 58206e57fa..6e7d3a3b73 100644 --- a/vendor/gotest.tools/v3/internal/cleanup/cleanup.go +++ b/vendor/gotest.tools/v3/internal/cleanup/cleanup.go @@ -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. */ package cleanup diff --git a/vendor/gotest.tools/v3/internal/format/diff.go b/vendor/gotest.tools/v3/internal/format/diff.go index 9897d4b9d9..4f6c07a350 100644 --- a/vendor/gotest.tools/v3/internal/format/diff.go +++ b/vendor/gotest.tools/v3/internal/format/diff.go @@ -1,3 +1,4 @@ +// Package format provides utilities for formatting diffs and messages. package format import ( diff --git a/vendor/gotest.tools/v3/internal/source/source.go b/vendor/gotest.tools/v3/internal/source/source.go index a3f70086d7..a4fc24ee63 100644 --- a/vendor/gotest.tools/v3/internal/source/source.go +++ b/vendor/gotest.tools/v3/internal/source/source.go @@ -1,3 +1,4 @@ +// Package source provides utilities for handling source-code. package source // import "gotest.tools/v3/internal/source" import ( diff --git a/vendor/gotest.tools/v3/internal/source/update.go b/vendor/gotest.tools/v3/internal/source/update.go index bd9678b831..f2006aacf2 100644 --- a/vendor/gotest.tools/v3/internal/source/update.go +++ b/vendor/gotest.tools/v3/internal/source/update.go @@ -54,8 +54,8 @@ func UpdateExpectedValue(stackIndex int, x, y interface{}) error { return ErrNotFound } - argIndex, varName := getVarNameForExpectedValueArg(expr) - if argIndex < 0 || varName == "" { + argIndex, ident := getIdentForExpectedValueArg(expr) + if argIndex < 0 || ident == nil { debug("no arguments started with the word 'expected': %v", debugFormatNode{Node: &ast.CallExpr{Args: expr}}) return ErrNotFound @@ -71,7 +71,7 @@ func UpdateExpectedValue(stackIndex int, x, y interface{}) error { debug("value must be type string, got %T", value) 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 @@ -80,10 +80,10 @@ func UpdateVariable( filename string, fileset *token.FileSet, astFile *ast.File, - varName string, + ident *ast.Ident, value string, ) error { - obj := astFile.Scope.Objects[varName] + obj := ident.Obj if obj == nil { return ErrNotFound } @@ -92,20 +92,33 @@ func UpdateVariable( return ErrNotFound } - spec, ok := obj.Decl.(*ast.ValueSpec) - if !ok { + switch decl := obj.Decl.(type) { + 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) 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 if err := format.Node(&buf, fileset, astFile); err != nil { @@ -125,14 +138,14 @@ func UpdateVariable( return nil } -func getVarNameForExpectedValueArg(expr []ast.Expr) (int, string) { +func getIdentForExpectedValueArg(expr []ast.Expr) (int, *ast.Ident) { for i := 1; i < 3; i++ { switch e := expr[i].(type) { case *ast.Ident: if strings.HasPrefix(strings.ToLower(e.Name), "expected") { - return i, e.Name + return i, e } } } - return -1, "" + return -1, nil } diff --git a/vendor/gotest.tools/v3/skip/skip.go b/vendor/gotest.tools/v3/skip/skip.go index cb899f78b1..495ce4aa32 100644 --- a/vendor/gotest.tools/v3/skip/skip.go +++ b/vendor/gotest.tools/v3/skip/skip.go @@ -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. */ package skip // import "gotest.tools/v3/skip" diff --git a/vendor/modules.txt b/vendor/modules.txt index 4529fb5329..db0771a5d1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -377,7 +377,7 @@ google.golang.org/protobuf/types/known/timestamppb # gopkg.in/yaml.v2 v2.4.0 ## explicit; go 1.15 gopkg.in/yaml.v2 -# gotest.tools/v3 v3.3.0 +# gotest.tools/v3 v3.4.0 ## explicit; go 1.13 gotest.tools/v3/assert gotest.tools/v3/assert/cmp