Integration tests (#71)
This commit is contained in:
1
vendor/gopkg.in/d4l3k/messagediff.v1/.coveralls.yml
generated
vendored
Normal file
1
vendor/gopkg.in/d4l3k/messagediff.v1/.coveralls.yml
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
repo_token: LWIe7rP7M3hBnAxpsMaZhrVBs2DSyhzoQ
|
24
vendor/gopkg.in/d4l3k/messagediff.v1/.gitignore
generated
vendored
Normal file
24
vendor/gopkg.in/d4l3k/messagediff.v1/.gitignore
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
26
vendor/gopkg.in/d4l3k/messagediff.v1/.travis.yml
generated
vendored
Normal file
26
vendor/gopkg.in/d4l3k/messagediff.v1/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
language: go
|
||||
|
||||
os:
|
||||
- linux
|
||||
|
||||
go:
|
||||
- 1
|
||||
- 1.3
|
||||
- 1.4
|
||||
- 1.5
|
||||
- 1.6
|
||||
- 1.7.x
|
||||
- 1.8.x
|
||||
- tip
|
||||
|
||||
before_install:
|
||||
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
|
||||
- go get github.com/axw/gocov/gocov
|
||||
- go get github.com/modocache/gover
|
||||
- go get github.com/mattn/goveralls
|
||||
|
||||
script:
|
||||
- go test -v -coverprofile=example.coverprofile ./example
|
||||
- go test -v -coverprofile=main.coverprofile
|
||||
- $HOME/gopath/bin/gover
|
||||
- $HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=gover.coverprofile
|
14
vendor/gopkg.in/d4l3k/messagediff.v1/CHANGELOG.md
generated
vendored
Normal file
14
vendor/gopkg.in/d4l3k/messagediff.v1/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
## nightly
|
||||
* Added support for ignoring fields.
|
||||
|
||||
## v1.1.0
|
||||
|
||||
* Added support for recursive data structures.
|
||||
* Fixed bug with embedded fixed length arrays in structs.
|
||||
* Added `example/` directory.
|
||||
* Minor test bug fixes for future go versions.
|
||||
* Added change log.
|
||||
|
||||
## v1.0.0
|
||||
|
||||
Initial tagged release release.
|
22
vendor/gopkg.in/d4l3k/messagediff.v1/LICENSE
generated
vendored
Normal file
22
vendor/gopkg.in/d4l3k/messagediff.v1/LICENSE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Tristan Rice
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
90
vendor/gopkg.in/d4l3k/messagediff.v1/README.md
generated
vendored
Normal file
90
vendor/gopkg.in/d4l3k/messagediff.v1/README.md
generated
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
# messagediff [](https://travis-ci.org/d4l3k/messagediff) [](https://coveralls.io/github/d4l3k/messagediff?branch=master) [](https://godoc.org/github.com/d4l3k/messagediff)
|
||||
|
||||
A library for doing diffs of arbitrary Golang structs.
|
||||
|
||||
If the unsafe package is available messagediff will diff unexported fields in
|
||||
addition to exported fields. This is primarily used for testing purposes as it
|
||||
allows for providing informative error messages.
|
||||
|
||||
Optionally, fields in structs can be tagged as `testdiff:"ignore"` to make
|
||||
messagediff skip it when doing the comparison.
|
||||
|
||||
|
||||
## Example Usage
|
||||
In a normal file:
|
||||
```go
|
||||
package main
|
||||
|
||||
import "gopkg.in/d4l3k/messagediff.v1"
|
||||
|
||||
type someStruct struct {
|
||||
A, b int
|
||||
C []int
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := someStruct{1, 2, []int{1}}
|
||||
b := someStruct{1, 3, []int{1, 2}}
|
||||
diff, equal := messagediff.PrettyDiff(a, b)
|
||||
/*
|
||||
diff =
|
||||
`added: .C[1] = 2
|
||||
modified: .b = 3`
|
||||
|
||||
equal = false
|
||||
*/
|
||||
}
|
||||
|
||||
```
|
||||
In a test:
|
||||
```go
|
||||
import "gopkg.in/d4l3k/messagediff.v1"
|
||||
|
||||
...
|
||||
|
||||
type someStruct struct {
|
||||
A, b int
|
||||
C []int
|
||||
}
|
||||
|
||||
func TestSomething(t *testing.T) {
|
||||
want := someStruct{1, 2, []int{1}}
|
||||
got := someStruct{1, 3, []int{1, 2}}
|
||||
if diff, equal := messagediff.PrettyDiff(want, got); !equal {
|
||||
t.Errorf("Something() = %#v\n%s", got, diff)
|
||||
}
|
||||
}
|
||||
```
|
||||
To ignore a field in a struct, just annotate it with testdiff:"ignore" like
|
||||
this:
|
||||
```go
|
||||
package main
|
||||
|
||||
import "gopkg.in/d4l3k/messagediff.v1"
|
||||
|
||||
type someStruct struct {
|
||||
A int
|
||||
B int `testdiff:"ignore"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := someStruct{1, 2}
|
||||
b := someStruct{1, 3}
|
||||
diff, equal := messagediff.PrettyDiff(a, b)
|
||||
/*
|
||||
equal = true
|
||||
diff = ""
|
||||
*/
|
||||
}
|
||||
```
|
||||
|
||||
See the `DeepDiff` function for using the diff results programmatically.
|
||||
|
||||
## License
|
||||
Copyright (c) 2015 [Tristan Rice](https://fn.lc) <rice@fn.lc>
|
||||
|
||||
messagediff is licensed under the MIT license. See the LICENSE file for more information.
|
||||
|
||||
bypass.go and bypasssafe.go are borrowed from
|
||||
[go-spew](https://github.com/davecgh/go-spew) and have a seperate copyright
|
||||
notice.
|
151
vendor/gopkg.in/d4l3k/messagediff.v1/bypass.go
generated
vendored
Normal file
151
vendor/gopkg.in/d4l3k/messagediff.v1/bypass.go
generated
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
// Copyright (c) 2015 Dave Collins <dave@davec.name>
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
// NOTE: Due to the following build constraints, this file will only be compiled
|
||||
// when the code is not running on Google App Engine and "-tags disableunsafe"
|
||||
// is not added to the go build command line.
|
||||
// +build !appengine,!disableunsafe
|
||||
|
||||
package messagediff
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
// UnsafeDisabled is a build-time constant which specifies whether or
|
||||
// not access to the unsafe package is available.
|
||||
UnsafeDisabled = false
|
||||
|
||||
// ptrSize is the size of a pointer on the current arch.
|
||||
ptrSize = unsafe.Sizeof((*byte)(nil))
|
||||
)
|
||||
|
||||
var (
|
||||
// offsetPtr, offsetScalar, and offsetFlag are the offsets for the
|
||||
// internal reflect.Value fields. These values are valid before golang
|
||||
// commit ecccf07e7f9d which changed the format. The are also valid
|
||||
// after commit 82f48826c6c7 which changed the format again to mirror
|
||||
// the original format. Code in the init function updates these offsets
|
||||
// as necessary.
|
||||
offsetPtr = uintptr(ptrSize)
|
||||
offsetScalar = uintptr(0)
|
||||
offsetFlag = uintptr(ptrSize * 2)
|
||||
|
||||
// flagKindWidth and flagKindShift indicate various bits that the
|
||||
// reflect package uses internally to track kind information.
|
||||
//
|
||||
// flagRO indicates whether or not the value field of a reflect.Value is
|
||||
// read-only.
|
||||
//
|
||||
// flagIndir indicates whether the value field of a reflect.Value is
|
||||
// the actual data or a pointer to the data.
|
||||
//
|
||||
// These values are valid before golang commit 90a7c3c86944 which
|
||||
// changed their positions. Code in the init function updates these
|
||||
// flags as necessary.
|
||||
flagKindWidth = uintptr(5)
|
||||
flagKindShift = uintptr(flagKindWidth - 1)
|
||||
flagRO = uintptr(1 << 0)
|
||||
flagIndir = uintptr(1 << 1)
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Older versions of reflect.Value stored small integers directly in the
|
||||
// ptr field (which is named val in the older versions). Versions
|
||||
// between commits ecccf07e7f9d and 82f48826c6c7 added a new field named
|
||||
// scalar for this purpose which unfortunately came before the flag
|
||||
// field, so the offset of the flag field is different for those
|
||||
// versions.
|
||||
//
|
||||
// This code constructs a new reflect.Value from a known small integer
|
||||
// and checks if the size of the reflect.Value struct indicates it has
|
||||
// the scalar field. When it does, the offsets are updated accordingly.
|
||||
vv := reflect.ValueOf(0xf00)
|
||||
if unsafe.Sizeof(vv) == (ptrSize * 4) {
|
||||
offsetScalar = ptrSize * 2
|
||||
offsetFlag = ptrSize * 3
|
||||
}
|
||||
|
||||
// Commit 90a7c3c86944 changed the flag positions such that the low
|
||||
// order bits are the kind. This code extracts the kind from the flags
|
||||
// field and ensures it's the correct type. When it's not, the flag
|
||||
// order has been changed to the newer format, so the flags are updated
|
||||
// accordingly.
|
||||
upf := unsafe.Pointer(uintptr(unsafe.Pointer(&vv)) + offsetFlag)
|
||||
upfv := *(*uintptr)(upf)
|
||||
flagKindMask := uintptr((1<<flagKindWidth - 1) << flagKindShift)
|
||||
if (upfv&flagKindMask)>>flagKindShift != uintptr(reflect.Int) {
|
||||
flagKindShift = 0
|
||||
flagRO = 1 << 5
|
||||
flagIndir = 1 << 6
|
||||
|
||||
// Commit adf9b30e5594 modified the flags to separate the
|
||||
// flagRO flag into two bits which specifies whether or not the
|
||||
// field is embedded. This causes flagIndir to move over a bit
|
||||
// and means that flagRO is the combination of either of the
|
||||
// original flagRO bit and the new bit.
|
||||
//
|
||||
// This code detects the change by extracting what used to be
|
||||
// the indirect bit to ensure it's set. When it's not, the flag
|
||||
// order has been changed to the newer format, so the flags are
|
||||
// updated accordingly.
|
||||
if upfv&flagIndir == 0 {
|
||||
flagRO = 3 << 5
|
||||
flagIndir = 1 << 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unsafeReflectValue converts the passed reflect.Value into a one that bypasses
|
||||
// the typical safety restrictions preventing access to unaddressable and
|
||||
// unexported data. It works by digging the raw pointer to the underlying
|
||||
// value out of the protected value and generating a new unprotected (unsafe)
|
||||
// reflect.Value to it.
|
||||
//
|
||||
// This allows us to check for implementations of the Stringer and error
|
||||
// interfaces to be used for pretty printing ordinarily unaddressable and
|
||||
// inaccessible values such as unexported struct fields.
|
||||
func unsafeReflectValue(v reflect.Value) (rv reflect.Value) {
|
||||
indirects := 1
|
||||
vt := v.Type()
|
||||
upv := unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetPtr)
|
||||
rvf := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetFlag))
|
||||
if rvf&flagIndir != 0 {
|
||||
vt = reflect.PtrTo(v.Type())
|
||||
indirects++
|
||||
} else if offsetScalar != 0 {
|
||||
// The value is in the scalar field when it's not one of the
|
||||
// reference types.
|
||||
switch vt.Kind() {
|
||||
case reflect.Uintptr:
|
||||
case reflect.Chan:
|
||||
case reflect.Func:
|
||||
case reflect.Map:
|
||||
case reflect.Ptr:
|
||||
case reflect.UnsafePointer:
|
||||
default:
|
||||
upv = unsafe.Pointer(uintptr(unsafe.Pointer(&v)) +
|
||||
offsetScalar)
|
||||
}
|
||||
}
|
||||
|
||||
pv := reflect.NewAt(vt, upv)
|
||||
rv = pv
|
||||
for i := 0; i < indirects; i++ {
|
||||
rv = rv.Elem()
|
||||
}
|
||||
return rv
|
||||
}
|
37
vendor/gopkg.in/d4l3k/messagediff.v1/bypasssafe.go
generated
vendored
Normal file
37
vendor/gopkg.in/d4l3k/messagediff.v1/bypasssafe.go
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2015 Dave Collins <dave@davec.name>
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
// NOTE: Due to the following build constraints, this file will only be compiled
|
||||
// when either the code is running on Google App Engine or "-tags disableunsafe"
|
||||
// is added to the go build command line.
|
||||
// +build appengine disableunsafe
|
||||
|
||||
package messagediff
|
||||
|
||||
import "reflect"
|
||||
|
||||
const (
|
||||
// UnsafeDisabled is a build-time constant which specifies whether or
|
||||
// not access to the unsafe package is available.
|
||||
UnsafeDisabled = true
|
||||
)
|
||||
|
||||
// unsafeReflectValue typically converts the passed reflect.Value into a one
|
||||
// that bypasses the typical safety restrictions preventing access to
|
||||
// unaddressable and unexported data. However, doing this relies on access to
|
||||
// the unsafe package. This is a stub version which simply returns the passed
|
||||
// reflect.Value when the unsafe package is not available.
|
||||
func unsafeReflectValue(v reflect.Value) reflect.Value {
|
||||
return v
|
||||
}
|
242
vendor/gopkg.in/d4l3k/messagediff.v1/messagediff.go
generated
vendored
Normal file
242
vendor/gopkg.in/d4l3k/messagediff.v1/messagediff.go
generated
vendored
Normal file
@ -0,0 +1,242 @@
|
||||
package messagediff
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// PrettyDiff does a deep comparison and returns the nicely formated results.
|
||||
func PrettyDiff(a, b interface{}) (string, bool) {
|
||||
d, equal := DeepDiff(a, b)
|
||||
var dstr []string
|
||||
for path, added := range d.Added {
|
||||
dstr = append(dstr, fmt.Sprintf("added: %s = %#v\n", path.String(), added))
|
||||
}
|
||||
for path, removed := range d.Removed {
|
||||
dstr = append(dstr, fmt.Sprintf("removed: %s = %#v\n", path.String(), removed))
|
||||
}
|
||||
for path, modified := range d.Modified {
|
||||
dstr = append(dstr, fmt.Sprintf("modified: %s = %#v\n", path.String(), modified))
|
||||
}
|
||||
sort.Strings(dstr)
|
||||
return strings.Join(dstr, ""), equal
|
||||
}
|
||||
|
||||
// DeepDiff does a deep comparison and returns the results.
|
||||
func DeepDiff(a, b interface{}) (*Diff, bool) {
|
||||
d := newDiff()
|
||||
return d, d.diff(reflect.ValueOf(a), reflect.ValueOf(b), nil)
|
||||
}
|
||||
|
||||
func newDiff() *Diff {
|
||||
return &Diff{
|
||||
Added: make(map[*Path]interface{}),
|
||||
Removed: make(map[*Path]interface{}),
|
||||
Modified: make(map[*Path]interface{}),
|
||||
visited: make(map[visit]bool),
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Diff) diff(aVal, bVal reflect.Value, path Path) bool {
|
||||
// The array underlying `path` could be modified in subsequent
|
||||
// calls. Make sure we have a local copy.
|
||||
localPath := make(Path, len(path))
|
||||
copy(localPath, path)
|
||||
|
||||
// Validity checks. Should only trigger if nil is one of the original arguments.
|
||||
if !aVal.IsValid() && !bVal.IsValid() {
|
||||
return true
|
||||
}
|
||||
if !bVal.IsValid() {
|
||||
d.Modified[&localPath] = nil
|
||||
return false
|
||||
} else if !aVal.IsValid() {
|
||||
d.Modified[&localPath] = bVal.Interface()
|
||||
return false
|
||||
}
|
||||
|
||||
if aVal.Type() != bVal.Type() {
|
||||
d.Modified[&localPath] = bVal.Interface()
|
||||
return false
|
||||
}
|
||||
kind := aVal.Kind()
|
||||
|
||||
// Borrowed from the reflect package to handle recursive data structures.
|
||||
hard := func(k reflect.Kind) bool {
|
||||
switch k {
|
||||
case reflect.Array, reflect.Map, reflect.Slice, reflect.Struct:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if aVal.CanAddr() && bVal.CanAddr() && hard(kind) {
|
||||
addr1 := unsafe.Pointer(aVal.UnsafeAddr())
|
||||
addr2 := unsafe.Pointer(bVal.UnsafeAddr())
|
||||
if uintptr(addr1) > uintptr(addr2) {
|
||||
// Canonicalize order to reduce number of entries in visited.
|
||||
// Assumes non-moving garbage collector.
|
||||
addr1, addr2 = addr2, addr1
|
||||
}
|
||||
|
||||
// Short circuit if references are already seen.
|
||||
typ := aVal.Type()
|
||||
v := visit{addr1, addr2, typ}
|
||||
if d.visited[v] {
|
||||
return true
|
||||
}
|
||||
|
||||
// Remember for later.
|
||||
d.visited[v] = true
|
||||
}
|
||||
// End of borrowed code.
|
||||
|
||||
equal := true
|
||||
switch kind {
|
||||
case reflect.Map, reflect.Ptr, reflect.Func, reflect.Chan, reflect.Slice:
|
||||
if aVal.IsNil() && bVal.IsNil() {
|
||||
return true
|
||||
}
|
||||
if aVal.IsNil() || bVal.IsNil() {
|
||||
d.Modified[&localPath] = bVal.Interface()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
switch kind {
|
||||
case reflect.Array, reflect.Slice:
|
||||
aLen := aVal.Len()
|
||||
bLen := bVal.Len()
|
||||
for i := 0; i < min(aLen, bLen); i++ {
|
||||
localPath := append(localPath, SliceIndex(i))
|
||||
if eq := d.diff(aVal.Index(i), bVal.Index(i), localPath); !eq {
|
||||
equal = false
|
||||
}
|
||||
}
|
||||
if aLen > bLen {
|
||||
for i := bLen; i < aLen; i++ {
|
||||
localPath := append(localPath, SliceIndex(i))
|
||||
d.Removed[&localPath] = aVal.Index(i).Interface()
|
||||
equal = false
|
||||
}
|
||||
} else if aLen < bLen {
|
||||
for i := aLen; i < bLen; i++ {
|
||||
localPath := append(localPath, SliceIndex(i))
|
||||
d.Added[&localPath] = bVal.Index(i).Interface()
|
||||
equal = false
|
||||
}
|
||||
}
|
||||
case reflect.Map:
|
||||
for _, key := range aVal.MapKeys() {
|
||||
aI := aVal.MapIndex(key)
|
||||
bI := bVal.MapIndex(key)
|
||||
localPath := append(localPath, MapKey{key.Interface()})
|
||||
if !bI.IsValid() {
|
||||
d.Removed[&localPath] = aI.Interface()
|
||||
equal = false
|
||||
} else if eq := d.diff(aI, bI, localPath); !eq {
|
||||
equal = false
|
||||
}
|
||||
}
|
||||
for _, key := range bVal.MapKeys() {
|
||||
aI := aVal.MapIndex(key)
|
||||
if !aI.IsValid() {
|
||||
bI := bVal.MapIndex(key)
|
||||
localPath := append(localPath, MapKey{key.Interface()})
|
||||
d.Added[&localPath] = bI.Interface()
|
||||
equal = false
|
||||
}
|
||||
}
|
||||
case reflect.Struct:
|
||||
typ := aVal.Type()
|
||||
for i := 0; i < typ.NumField(); i++ {
|
||||
index := []int{i}
|
||||
field := typ.FieldByIndex(index)
|
||||
if field.Tag.Get("testdiff") == "ignore" { // skip fields marked to be ignored
|
||||
continue
|
||||
}
|
||||
localPath := append(localPath, StructField(field.Name))
|
||||
aI := unsafeReflectValue(aVal.FieldByIndex(index))
|
||||
bI := unsafeReflectValue(bVal.FieldByIndex(index))
|
||||
if eq := d.diff(aI, bI, localPath); !eq {
|
||||
equal = false
|
||||
}
|
||||
}
|
||||
case reflect.Ptr:
|
||||
equal = d.diff(aVal.Elem(), bVal.Elem(), localPath)
|
||||
default:
|
||||
if reflect.DeepEqual(aVal.Interface(), bVal.Interface()) {
|
||||
equal = true
|
||||
} else {
|
||||
d.Modified[&localPath] = bVal.Interface()
|
||||
equal = false
|
||||
}
|
||||
}
|
||||
return equal
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// During deepValueEqual, must keep track of checks that are
|
||||
// in progress. The comparison algorithm assumes that all
|
||||
// checks in progress are true when it reencounters them.
|
||||
// Visited comparisons are stored in a map indexed by visit.
|
||||
// This is borrowed from the reflect package.
|
||||
type visit struct {
|
||||
a1 unsafe.Pointer
|
||||
a2 unsafe.Pointer
|
||||
typ reflect.Type
|
||||
}
|
||||
|
||||
// Diff represents a change in a struct.
|
||||
type Diff struct {
|
||||
Added, Removed, Modified map[*Path]interface{}
|
||||
visited map[visit]bool
|
||||
}
|
||||
|
||||
// Path represents a path to a changed datum.
|
||||
type Path []PathNode
|
||||
|
||||
func (p Path) String() string {
|
||||
var out string
|
||||
for _, n := range p {
|
||||
out += n.String()
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// PathNode represents one step in the path.
|
||||
type PathNode interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
// StructField is a path element representing a field of a struct.
|
||||
type StructField string
|
||||
|
||||
func (n StructField) String() string {
|
||||
return fmt.Sprintf(".%s", string(n))
|
||||
}
|
||||
|
||||
// MapKey is a path element representing a key of a map.
|
||||
type MapKey struct {
|
||||
Key interface{}
|
||||
}
|
||||
|
||||
func (n MapKey) String() string {
|
||||
return fmt.Sprintf("[%#v]", n.Key)
|
||||
}
|
||||
|
||||
// SliceIndex is a path element representing a index of a slice.
|
||||
type SliceIndex int
|
||||
|
||||
func (n SliceIndex) String() string {
|
||||
return fmt.Sprintf("[%d]", n)
|
||||
}
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -192,6 +192,8 @@ golang.org/x/tools/internal/fastwalk
|
||||
google.golang.org/appengine/cloudsql
|
||||
# gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc
|
||||
gopkg.in/alexcesaro/quotedprintable.v3
|
||||
# gopkg.in/d4l3k/messagediff.v1 v1.2.1
|
||||
gopkg.in/d4l3k/messagediff.v1
|
||||
# gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||
gopkg.in/gomail.v2
|
||||
# gopkg.in/testfixtures.v2 v2.5.3
|
||||
|
Reference in New Issue
Block a user