deps: Bump github.com/go-test/deep to 1.0.3

This commit is contained in:
Radek Simko 2019-08-21 11:32:13 +01:00
parent 0c66c45163
commit 16ba85083f
No known key found for this signature in database
GPG Key ID: 1F1C84FE689A88D7
7 changed files with 72 additions and 35 deletions

2
go.mod
View File

@ -31,7 +31,7 @@ require (
github.com/dnaeon/go-vcr v0.0.0-20180920040454-5637cf3d8a31 // indirect
github.com/dylanmei/iso8601 v0.1.0 // indirect
github.com/dylanmei/winrmtest v0.0.0-20190225150635-99b7fe2fddf1
github.com/go-test/deep v1.0.1
github.com/go-test/deep v1.0.3
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 // indirect
github.com/golang/mock v1.3.1
github.com/golang/protobuf v1.3.1

2
go.sum
View File

@ -125,6 +125,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.1 h1:UQhStjbkDClarlmv0am7OXXO4/GaPdCGiUiMTvi28sg=
github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0 h1:xU6/SpYbvkNYiptHJYEDRseDLvYE7wSqhYYNy0QSUzI=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=

View File

@ -1,9 +1,9 @@
language: go
go:
- 1.7
- 1.8
- 1.9
- "1.10"
- "1.11"
- "1.12"
before_install:
- go get github.com/mattn/goveralls

View File

@ -1,8 +1,25 @@
# go-test/deep Changelog
## v1.0.3
* Fixed issue #31: panic on typed primitives that implement error interface
## v1.0.2 released 2019-07-14
* Enabled Go module (@radeksimko)
* Changed supported and tested Go versions: 1.10, 1.11, and 1.12 (dropped 1.9)
* Changed Error equality: additional struct fields are compared too (PR #29) (@andrewmostello)
* Fixed typos and ineffassign issues (PR #25) (@tariq1890)
* Fixed diff order for nil comparison (PR #16) (@gmarik)
* Fixed slice equality when slices are extracted from the same array (PR #11) (@risteli)
* Fixed test spelling and messages (PR #19) (@sofuture)
* Fixed issue #15: panic on comparing struct with anonymous time.Time
* Fixed issue #18: Panic when comparing structs with time.Time value and CompareUnexportedFields is true
* Fixed issue #21: Set default MaxDepth = 0 (disabled) (PR #23)
## v1.0.1 released 2018-01-28
* Fixed #12: Arrays are not properly compared (samlitowitz)
* Fixed issue #12: Arrays are not properly compared (@samlitowitz)
## v1.0.0 releaesd 2017-10-27

View File

@ -19,14 +19,15 @@ var (
// MaxDiff specifies the maximum number of differences to return.
MaxDiff = 10
// MaxDepth specifies the maximum levels of a struct to recurse into.
MaxDepth = 10
// MaxDepth specifies the maximum levels of a struct to recurse into,
// if greater than zero. If zero, there is no limit.
MaxDepth = 0
// LogErrors causes errors to be logged to STDERR when true.
LogErrors = false
// CompareUnexportedFields causes unexported struct fields, like s in
// T{s int}, to be comparsed when true.
// T{s int}, to be compared when true.
CompareUnexportedFields = false
)
@ -50,8 +51,9 @@ type cmp struct {
var errorType = reflect.TypeOf((*error)(nil)).Elem()
// Equal compares variables a and b, recursing into their structure up to
// MaxDepth levels deep, and returns a list of differences, or nil if there are
// none. Some differences may not be found if an error is also returned.
// MaxDepth levels deep (if greater than zero), and returns a list of differences,
// or nil if there are none. Some differences may not be found if an error is
// also returned.
//
// If a type has an Equal method, like time.Equal, it is called to check for
// equality.
@ -66,7 +68,7 @@ func Equal(a, b interface{}) []string {
if a == nil && b == nil {
return nil
} else if a == nil && b != nil {
c.saveDiff(b, "<nil pointer>")
c.saveDiff("<nil pointer>", b)
} else if a != nil && b == nil {
c.saveDiff(a, "<nil pointer>")
}
@ -82,7 +84,7 @@ func Equal(a, b interface{}) []string {
}
func (c *cmp) equals(a, b reflect.Value, level int) {
if level > MaxDepth {
if MaxDepth > 0 && level > MaxDepth {
logError(ErrMaxRecursion)
return
}
@ -97,7 +99,7 @@ func (c *cmp) equals(a, b reflect.Value, level int) {
return
}
// If differenet types, they can't be equal
// If different types, they can't be equal
aType := a.Type()
bType := b.Type()
if aType != bType {
@ -110,46 +112,37 @@ func (c *cmp) equals(a, b reflect.Value, level int) {
aKind := a.Kind()
bKind := b.Kind()
// Do a and b have underlying elements? Yes if they're ptr or interface.
aElem := aKind == reflect.Ptr || aKind == reflect.Interface
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.
// 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 a.Elem().IsValid() && b.Elem().IsValid() { // both err != nil
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
}
return
}
}
// Dereference pointers and interface{}
if aElem, bElem := (aKind == reflect.Ptr || aKind == reflect.Interface),
(bKind == reflect.Ptr || bKind == reflect.Interface); aElem || bElem {
if aElem || bElem {
if aElem {
a = a.Elem()
}
if bElem {
b = b.Elem()
}
c.equals(a, b, level+1)
return
}
// Types with an Equal(), like time.Time.
eqFunc := a.MethodByName("Equal")
if eqFunc.IsValid() {
retVals := eqFunc.Call([]reflect.Value{b})
if !retVals[0].Bool() {
c.saveDiff(a, b)
}
return
}
switch aKind {
/////////////////////////////////////////////////////////////////////
@ -167,6 +160,29 @@ func (c *cmp) equals(a, b reflect.Value, level int) {
Iterate through the fields (FirstName, LastName), recurse into their values.
*/
// Types with an Equal() method, like time.Time, only if struct field
// is exported (CanInterface)
if eqFunc := a.MethodByName("Equal"); eqFunc.IsValid() && eqFunc.CanInterface() {
// Handle https://github.com/go-test/deep/issues/15:
// Don't call T.Equal if the method is from an embedded struct, like:
// type Foo struct { time.Time }
// First, we'll encounter Equal(Ttime, time.Time) but if we pass b
// as the 2nd arg we'll panic: "Call using pkg.Foo as type time.Time"
// As far as I can tell, there's no way to see that the method is from
// time.Time not Foo. So we check the type of the 1st (0) arg and skip
// unless it's b type. Later, we'll encounter the time.Time anonymous/
// embedded field and then we'll have Equal(time.Time, time.Time).
funcType := eqFunc.Type()
if funcType.NumIn() == 1 && funcType.In(0) == bType {
retVals := eqFunc.Call([]reflect.Value{b})
if !retVals[0].Bool() {
c.saveDiff(a, b)
}
return
}
}
for i := 0; i < a.NumField(); i++ {
if aType.Field(i).PkgPath != "" && !CompareUnexportedFields {
continue // skip unexported field, e.g. s in type T struct {s string}
@ -267,12 +283,13 @@ func (c *cmp) equals(a, b reflect.Value, level int) {
return
}
if a.Pointer() == b.Pointer() {
aLen := a.Len()
bLen := b.Len()
if a.Pointer() == b.Pointer() && aLen == bLen {
return
}
aLen := a.Len()
bLen := b.Len()
n := aLen
if bLen > aLen {
n = bLen

1
vendor/github.com/go-test/deep/go.mod generated vendored Normal file
View File

@ -0,0 +1 @@
module github.com/go-test/deep

2
vendor/modules.txt vendored
View File

@ -158,7 +158,7 @@ github.com/dylanmei/iso8601
github.com/dylanmei/winrmtest
# github.com/fatih/color v1.7.0
github.com/fatih/color
# github.com/go-test/deep v1.0.1
# github.com/go-test/deep v1.0.3
github.com/go-test/deep
# github.com/gogo/protobuf v1.2.0
github.com/gogo/protobuf/gogoproto