From 0150418478304ecfa3d2865dadba22158663fcab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:02:38 -0500 Subject: [PATCH] Bump github.com/go-test/deep from 1.0.8 to 1.1.1 (#4278) Bumps [github.com/go-test/deep](https://github.com/go-test/deep) from 1.0.8 to 1.1.1. - [Release notes](https://github.com/go-test/deep/releases) - [Changelog](https://github.com/go-test/deep/blob/master/CHANGES.md) - [Commits](https://github.com/go-test/deep/compare/v1.0.8...v1.1.1) --- updated-dependencies: - dependency-name: github.com/go-test/deep dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/go-test/deep/.travis.yml | 13 -- vendor/github.com/go-test/deep/CHANGES.md | 19 ++- vendor/github.com/go-test/deep/README.md | 4 +- vendor/github.com/go-test/deep/SECURITY.md | 3 +- vendor/github.com/go-test/deep/deep.go | 156 +++++++++++++++++---- vendor/modules.txt | 2 +- 8 files changed, 153 insertions(+), 50 deletions(-) delete mode 100644 vendor/github.com/go-test/deep/.travis.yml diff --git a/go.mod b/go.mod index 61d6df975f5..24a30a7fa25 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/go-kit/log v0.2.1 github.com/go-logfmt/logfmt v0.6.0 github.com/go-redis/redis/v8 v8.11.5 - github.com/go-test/deep v1.0.8 + github.com/go-test/deep v1.1.1 github.com/gogo/protobuf v1.3.2 github.com/gogo/status v1.1.1 github.com/golang/protobuf v1.5.4 diff --git a/go.sum b/go.sum index e725b02bfe4..2d180262d0a 100644 --- a/go.sum +++ b/go.sum @@ -298,8 +298,8 @@ github.com/go-resty/resty/v2 v2.13.1 h1:x+LHXBI2nMB1vqndymf26quycC4aggYJ7DECYbiz github.com/go-resty/resty/v2 v2.13.1/go.mod h1:GznXlLxkq6Nh4sU59rPmUw3VtgpO3aS96ORAI6Q7d+0= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-test/deep v1.0.2-0.20181118220953-042da051cf31/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= -github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= -github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= +github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U= +github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 h1:TQcrn6Wq+sKGkpyPvppOz99zsMBaUOKXq6HSv655U1c= github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/go-zookeeper/zk v1.0.3 h1:7M2kwOsc//9VeeFiPtf+uSJlVpU66x9Ba5+8XK7/TDg= diff --git a/vendor/github.com/go-test/deep/.travis.yml b/vendor/github.com/go-test/deep/.travis.yml deleted file mode 100644 index c459ee7b0e8..00000000000 --- a/vendor/github.com/go-test/deep/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: go - -go: - - "1.15" - - "1.16" - - "1.17" - -before_install: - - go get github.com/mattn/goveralls - - go get golang.org/x/tools/cover - -script: - - $HOME/gopath/bin/goveralls -service=travis-pro -package github.com/go-test/deep diff --git a/vendor/github.com/go-test/deep/CHANGES.md b/vendor/github.com/go-test/deep/CHANGES.md index ade9e79c68f..163d6d5cb51 100644 --- a/vendor/github.com/go-test/deep/CHANGES.md +++ b/vendor/github.com/go-test/deep/CHANGES.md @@ -1,8 +1,25 @@ # go-test/deep Changelog +## v1.1.1 released 2024-06-23 + +* Added `NilPointersAreZero` option: causes a nil pointer to be equal to a zero value (PR #61) (@seveas) +* Updated test matrix to go1.22, go1.21, and go1.20 + +## v1.1.0 released 2022-12-09 + +* Add optional flags: `Equal(a, b, flags..)` and `FLAG_IGNORE_SLICE_ORDER` (issue #28, PR #56) (@alenkacz) + +--- + +## v1.0.9 released 2022-12-09 + +* Fixed issue #45: Panic when comparing errors in unexported fields (PR #54) (@seveas) +* Fixed issue #46: Functions are handled differently from reflect.DeepEqual (PR #55) (@countcb) +* Updated test matrix to go1.17, go1.18, and go1.19 and moved testing to GitHub Actions + ## v1.0.8 released 2021-10-13 -* Updated matrix to go1.15, go1.16, and go1.17 +* Updated test matrix to go1.15, go1.16, and go1.17 * Added SECURITY.md and GitHub code analysis ## v1.0.7 released 2020-07-11 diff --git a/vendor/github.com/go-test/deep/README.md b/vendor/github.com/go-test/deep/README.md index 56770a69b34..08a86070d1a 100644 --- a/vendor/github.com/go-test/deep/README.md +++ b/vendor/github.com/go-test/deep/README.md @@ -1,6 +1,8 @@ # Deep Variable Equality for Humans -[![Go Report Card](https://goreportcard.com/badge/github.com/go-test/deep)](https://goreportcard.com/report/github.com/go-test/deep) [![Build Status](https://app.travis-ci.com/go-test/deep.svg?branch=master)](https://app.travis-ci.com/go-test/deep) [![Coverage Status](https://coveralls.io/repos/github/go-test/deep/badge.svg?branch=master)](https://coveralls.io/github/go-test/deep?branch=master) [![GoDoc](https://godoc.org/github.com/go-test/deep?status.svg)](https://pkg.go.dev/github.com/go-test/deep) +[![Go Report Card](https://goreportcard.com/badge/github.com/go-test/deep)](https://goreportcard.com/report/github.com/go-test/deep) +[![Coverage Status](https://coveralls.io/repos/github/go-test/deep/badge.svg?branch=master)](https://coveralls.io/github/go-test/deep?branch=master) +[![Go Reference](https://pkg.go.dev/badge/github.com/go-test/deep.svg)](https://pkg.go.dev/github.com/go-test/deep) This package provides a single function: `deep.Equal`. It's like [reflect.DeepEqual](http://golang.org/pkg/reflect/#DeepEqual) but much friendlier to humans (or any sentient being) for two reason: diff --git a/vendor/github.com/go-test/deep/SECURITY.md b/vendor/github.com/go-test/deep/SECURITY.md index 845584a9a9e..d007137ad1d 100644 --- a/vendor/github.com/go-test/deep/SECURITY.md +++ b/vendor/github.com/go-test/deep/SECURITY.md @@ -6,7 +6,8 @@ For security patches, the latest release is supported: | Version | Supported | | ------- | ------------------ | -| 1.0.x | :white_check_mark: | +| 1.1.x | Yes | +| 1.0.x | No | ## Reporting a Vulnerability diff --git a/vendor/github.com/go-test/deep/deep.go b/vendor/github.com/go-test/deep/deep.go index dbc89c04bb9..4be3e1f4e6a 100644 --- a/vendor/github.com/go-test/deep/deep.go +++ b/vendor/github.com/go-test/deep/deep.go @@ -27,14 +27,25 @@ var ( LogErrors = false // CompareUnexportedFields causes unexported struct fields, like s in - // T{s int}, to be compared when true. + // T{s int}, to be compared when true. This does not work for comparing + // error or Time types on unexported fields because methods on unexported + // fields cannot be called. CompareUnexportedFields = false + // CompareFunctions compares functions the same as reflect.DeepEqual: + // only two nil functions are equal. Every other combination is not equal. + // This is disabled by default because previous versions of this package + // ignored functions. Enabling it can possibly report new diffs. + CompareFunctions = false + // NilSlicesAreEmpty causes a nil slice to be equal to an empty slice. NilSlicesAreEmpty = false // NilMapsAreEmpty causes a nil map to be equal to an empty map. NilMapsAreEmpty = false + + // NilPointersAreZero causes a nil pointer to be equal to a zero value. + NilPointersAreZero = false ) var ( @@ -48,10 +59,24 @@ var ( ErrNotHandled = errors.New("cannot compare the reflect.Kind") ) +const ( + // FLAG_NONE is a placeholder for default Equal behavior. You don't have to + // pass it to Equal; if you do, it does nothing. + FLAG_NONE byte = iota + + // FLAG_IGNORE_SLICE_ORDER causes Equal to ignore slice order so that + // []int{1, 2} and []int{2, 1} are equal. Only slices of primitive scalars + // like numbers and strings are supported. Slices of complex types, + // like []T where T is a struct, are undefined because Equal does not + // recurse into the slice value when this flag is enabled. + FLAG_IGNORE_SLICE_ORDER +) + type cmp struct { diff []string buff []string floatFormat string + flag map[byte]bool } var errorType = reflect.TypeOf((*error)(nil)).Elem() @@ -66,13 +91,17 @@ var errorType = reflect.TypeOf((*error)(nil)).Elem() // // When comparing a struct, if a field has the tag `deep:"-"` then it will be // ignored. -func Equal(a, b interface{}) []string { +func Equal(a, b interface{}, flags ...interface{}) []string { aVal := reflect.ValueOf(a) bVal := reflect.ValueOf(b) c := &cmp{ diff: []string{}, buff: []string{}, floatFormat: fmt.Sprintf("%%.%df", FloatPrecision), + flag: map[byte]bool{}, + } + for i := range flags { + c.flag[flags[i].(byte)] = true } if a == nil && b == nil { return nil @@ -137,18 +166,23 @@ func (c *cmp) equals(a, b reflect.Value, level int) { bElem := bKind == reflect.Ptr || bKind == reflect.Interface // If both types implement the error interface, compare the error strings. - // This must be done before dereferencing because the interface is on a - // pointer receiver. Re https://github.com/go-test/deep/issues/31, a/b might - // be primitive kinds; see TestErrorPrimitiveKind. - if aType.Implements(errorType) && bType.Implements(errorType) { - if (!aElem || !a.IsNil()) && (!bElem || !b.IsNil()) { - aString := a.MethodByName("Error").Call(nil)[0].String() - bString := b.MethodByName("Error").Call(nil)[0].String() - if aString != bString { - c.saveDiff(aString, bString) - return - } + // This must be done before dereferencing because errors.New() returns a + // pointer to a struct that implements the interface: + // func (e *errorString) Error() string { + // And we check CanInterface as a hack to make sure the underlying method + // is callable because https://github.com/golang/go/issues/32438 + // Issues: + // https://github.com/go-test/deep/issues/31 + // https://github.com/go-test/deep/issues/45 + if (aType.Implements(errorType) && bType.Implements(errorType)) && + ((!aElem || !a.IsNil()) && (!bElem || !b.IsNil())) && + (a.CanInterface() && b.CanInterface()) { + aString := a.MethodByName("Error").Call(nil)[0].String() + bString := b.MethodByName("Error").Call(nil)[0].String() + if aString != bString { + c.saveDiff(aString, bString) } + return } // Dereference pointers and interface{} @@ -159,6 +193,12 @@ func (c *cmp) equals(a, b reflect.Value, level int) { if bElem { b = b.Elem() } + if aElem && NilPointersAreZero && !a.IsValid() && b.IsValid() { + a = reflect.Zero(b.Type()) + } + if bElem && NilPointersAreZero && !b.IsValid() && a.IsValid() { + b = reflect.Zero(a.Type()) + } c.equals(a, b, level+1) return } @@ -326,29 +366,54 @@ func (c *cmp) equals(a, b reflect.Value, level int) { } } + // Equal if same underlying pointer and same length, this latter handles + // foo := []int{1, 2, 3, 4} + // a := foo[0:2] // == {1,2} + // b := foo[2:4] // == {3,4} + // a and b are same pointer but different slices (lengths) of the underlying + // array, so not equal. aLen := a.Len() bLen := b.Len() - if a.Pointer() == b.Pointer() && aLen == bLen { return } - n := aLen - if bLen > aLen { - n = bLen - } - for i := 0; i < n; i++ { - c.push(fmt.Sprintf("slice[%d]", i)) - if i < aLen && i < bLen { - c.equals(a.Index(i), b.Index(i), level+1) - } else if i < aLen { - c.saveDiff(a.Index(i), "") - } else { - c.saveDiff("", b.Index(i)) + if c.flag[FLAG_IGNORE_SLICE_ORDER] { + // Compare slices by value and value count; ignore order. + // Value equality is impliclity established by the maps: + // any value v1 will hash to the same map value if it's equal + // to another value v2. Then equality is determiend by value + // count: presuming v1==v2, then the slics are equal if there + // are equal numbers of v1 in each slice. + am := map[interface{}]int{} + for i := 0; i < a.Len(); i++ { + am[a.Index(i).Interface()] += 1 } - c.pop() - if len(c.diff) >= MaxDiff { - break + bm := map[interface{}]int{} + for i := 0; i < b.Len(); i++ { + bm[b.Index(i).Interface()] += 1 + } + c.cmpMapValueCounts(a, b, am, bm, true) // a cmp b + c.cmpMapValueCounts(b, a, bm, am, false) // b cmp a + } else { + // Compare slices by order + n := aLen + if bLen > aLen { + n = bLen + } + for i := 0; i < n; i++ { + c.push(fmt.Sprintf("slice[%d]", i)) + if i < aLen && i < bLen { + c.equals(a.Index(i), b.Index(i), level+1) + } else if i < aLen { + c.saveDiff(a.Index(i), "") + } else { + c.saveDiff("", b.Index(i)) + } + c.pop() + if len(c.diff) >= MaxDiff { + break + } } } @@ -385,7 +450,19 @@ func (c *cmp) equals(a, b reflect.Value, level int) { if a.String() != b.String() { c.saveDiff(a.String(), b.String()) } - + case reflect.Func: + if CompareFunctions { + if !a.IsNil() || !b.IsNil() { + aVal, bVal := "nil func", "nil func" + if !a.IsNil() { + aVal = "func" + } + if !b.IsNil() { + bVal = "func" + } + c.saveDiff(aVal, bVal) + } + } default: logError(ErrNotHandled) } @@ -410,6 +487,25 @@ func (c *cmp) saveDiff(aval, bval interface{}) { } } +func (c *cmp) cmpMapValueCounts(a, b reflect.Value, am, bm map[interface{}]int, a2b bool) { + for v := range am { + aCount, _ := am[v] + bCount, _ := bm[v] + + if aCount != bCount { + c.push(fmt.Sprintf("(unordered) slice[]=%v: value count", v)) + if a2b { + c.saveDiff(fmt.Sprintf("%d", aCount), fmt.Sprintf("%d", bCount)) + } else { + c.saveDiff(fmt.Sprintf("%d", bCount), fmt.Sprintf("%d", aCount)) + } + c.pop() + } + delete(am, v) + delete(bm, v) + } +} + func logError(err error) { if LogErrors { log.Println(err) diff --git a/vendor/modules.txt b/vendor/modules.txt index 4ac38306996..4a504396aa6 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -375,7 +375,7 @@ github.com/go-redis/redis/v8/internal/pool github.com/go-redis/redis/v8/internal/proto github.com/go-redis/redis/v8/internal/rand github.com/go-redis/redis/v8/internal/util -# github.com/go-test/deep v1.0.8 +# github.com/go-test/deep v1.1.1 ## explicit; go 1.16 github.com/go-test/deep # github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1