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:
Sebastiaan van Stijn 2022-11-05 19:38:01 +01:00
parent 57ba2df970
commit d43bc26717
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
20 changed files with 142 additions and 114 deletions

View File

@ -87,7 +87,7 @@ require (
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21
google.golang.org/grpc v1.47.0
gotest.tools/v3 v3.3.0
gotest.tools/v3 v3.4.0
)
require (

View File

@ -1713,8 +1713,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
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=

View File

@ -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

View File

@ -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 {

View File

@ -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"

View File

@ -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

View File

@ -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)

View File

@ -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.

View File

@ -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.

View File

@ -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 {

View File

@ -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)
}

View File

@ -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"
)

View File

@ -2,8 +2,7 @@ package icmd
import (
"errors"
exec "golang.org/x/sys/execabs"
"os/exec"
)
func processExitCode(err error) int {

View File

@ -1,3 +1,4 @@
// Package assert provides internal utilties for assertions.
package assert
import (

View File

@ -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

View File

@ -1,3 +1,4 @@
// Package format provides utilities for formatting diffs and messages.
package format
import (

View File

@ -1,3 +1,4 @@
// Package source provides utilities for handling source-code.
package source // import "gotest.tools/v3/internal/source"
import (

View File

@ -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
}

View File

@ -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"

2
vendor/modules.txt vendored
View File

@ -1111,7 +1111,7 @@ google.golang.org/protobuf/types/known/fieldmaskpb
google.golang.org/protobuf/types/known/structpb
google.golang.org/protobuf/types/known/timestamppb
google.golang.org/protobuf/types/known/wrapperspb
# 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