powerman update

This commit is contained in:
Frank Denis 2021-08-17 16:56:09 +02:00
parent d8c4a90501
commit 785f86f50f
14 changed files with 450 additions and 6 deletions

2
go.mod
View File

@ -19,7 +19,7 @@ require (
github.com/k-sone/critbitgo v1.4.0
github.com/kardianos/service v1.2.0
github.com/miekg/dns v1.1.43
github.com/powerman/check v1.5.0
github.com/powerman/check v1.6.0
golang.org/x/crypto v0.0.0-20210812204632-0ba0e8f03122
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e

5
go.sum
View File

@ -539,8 +539,11 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/polyfloyd/go-errorlint v0.0.0-20210510181950-ab96adb96fea h1:Sk6Xawg57ZkjXmFYD1xCHSKN6FtYM+km51MM7Lveyyc=
github.com/polyfloyd/go-errorlint v0.0.0-20210510181950-ab96adb96fea/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/powerman/check v1.5.0 h1:72YL13AQcqtdepmD0aFnd6UXwf5XnjaZAn2AFddzqE4=
github.com/powerman/check v1.5.0/go.mod h1:rkG3EGrr9RzxN2N+ZAeOTMRIE1W+db7QGJjiIUlVsoA=
github.com/powerman/check v1.6.0 h1:8J3QQFD2QaeMu+pDZz+EChgY62IQtRfpUSD7WHBEgg4=
github.com/powerman/check v1.6.0/go.mod h1:sHb2NBEd2MdSGldglajwRsC1yxjcfngva5CGGsIMJDM=
github.com/powerman/deepequal v0.1.0 h1:sVwtyTsBuYIvdbLR1O2wzRY63YgPqdGZmk/o80l+C/U=
github.com/powerman/deepequal v0.1.0/go.mod h1:3k7aG/slufBhUANdN67o/UPg8i5YaiJ6FmibWX0cn04=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=

View File

@ -12,6 +12,7 @@ import (
"time"
pkgerrors "github.com/pkg/errors"
"github.com/powerman/deepequal"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
@ -478,6 +479,8 @@ func (t *C) NotBytesEqual(actual, expected []byte, msg ...interface{}) bool {
}
// DeepEqual checks for reflect.DeepEqual(actual, expected).
// It will also use Equal method for types which implements it
// (e.g. time.Time, decimal.Decimal, etc.).
// It will use proto.Equal for protobuf messages.
func (t *C) DeepEqual(actual, expected interface{}, msg ...interface{}) bool {
t.Helper()
@ -488,11 +491,13 @@ func (t *C) DeepEqual(actual, expected interface{}, msg ...interface{}) bool {
proto.Equal(protoActual, protoExpected))
}
return t.report2(actual, expected, msg,
reflect.DeepEqual(actual, expected))
deepequal.DeepEqual(actual, expected))
}
// NotDeepEqual checks for !reflect.DeepEqual(actual, expected).
// It will use !proto.Equal for protobuf messages.
// It will also use Equal method for types which implements it
// (e.g. time.Time, decimal.Decimal, etc.).
// It will use proto.Equal for protobuf messages.
func (t *C) NotDeepEqual(actual, expected interface{}, msg ...interface{}) bool {
t.Helper()
protoActual, proto1 := actual.(protoreflect.ProtoMessage)
@ -502,7 +507,7 @@ func (t *C) NotDeepEqual(actual, expected interface{}, msg ...interface{}) bool
!proto.Equal(protoActual, protoExpected))
}
return t.report1(actual, msg,
!reflect.DeepEqual(actual, expected))
!deepequal.DeepEqual(actual, expected))
}
// Match checks for regex.MatchString(actual).

View File

@ -8,6 +8,7 @@ require (
github.com/mattn/goveralls v0.0.9
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
github.com/powerman/deepequal v0.1.0
github.com/smartystreets/goconvey v1.6.4
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
google.golang.org/grpc v1.38.0

View File

@ -507,6 +507,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/polyfloyd/go-errorlint v0.0.0-20210510181950-ab96adb96fea h1:Sk6Xawg57ZkjXmFYD1xCHSKN6FtYM+km51MM7Lveyyc=
github.com/polyfloyd/go-errorlint v0.0.0-20210510181950-ab96adb96fea/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/powerman/deepequal v0.1.0 h1:sVwtyTsBuYIvdbLR1O2wzRY63YgPqdGZmk/o80l+C/U=
github.com/powerman/deepequal v0.1.0/go.mod h1:3k7aG/slufBhUANdN67o/UPg8i5YaiJ6FmibWX0cn04=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=

21
vendor/github.com/powerman/deepequal/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Alex Efros
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.

27
vendor/github.com/powerman/deepequal/LICENSE-go generated vendored Normal file
View File

@ -0,0 +1,27 @@
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

14
vendor/github.com/powerman/deepequal/README.md generated vendored Normal file
View File

@ -0,0 +1,14 @@
# Go package with improved reflect.DeepEqual
Most of the code is copied from Go reflect package with slight
modifications.
Differences from reflect.DeepEqual:
- If compared value implements `.Equal(valueOfSameType) bool` method then
it will be called instead of comparing values as is.
- If called `Equal` method will panics then whole DeepEqual will panics too.
This means you can use this DeepEqual method to correctly compare types
like time.Time or decimal.Decimal, without taking in account unimportant
differences (like time zone or exponent).

54
vendor/github.com/powerman/deepequal/custom.go generated vendored Normal file
View File

@ -0,0 +1,54 @@
// Package deepequal provides improved reflect.DeepEqual.
//
// Differences from reflect.DeepEqual:
//
// - If compared value implements `.Equal(valueOfSameType) bool` method then
// it will be called instead of comparing values as is.
// - If called `Equal` method will panics then whole DeepEqual will panics too.
//
// This means you can use this DeepEqual method to correctly compare types
// like time.Time or decimal.Decimal, without taking in account unimportant
// differences (like time zone or exponent).
package deepequal
import (
"reflect"
"unsafe"
)
// Disable check for unexported values.
func forceExported(v *reflect.Value) (undo func()) {
ref := (*value)(unsafe.Pointer(v))
flag := ref.flag
ref.flag &^= flagRO
return func() { ref.flag = flag }
}
func valueInterface(v reflect.Value) interface{} {
defer forceExported(&v)()
return v.Interface()
}
func call(v reflect.Value, in []reflect.Value) []reflect.Value {
defer forceExported(&v)()
for i := range in {
defer forceExported(&in[i])()
}
return v.Call(in)
}
var (
zeroValue reflect.Value
boolType = reflect.TypeOf(true)
)
func equalFunc(v reflect.Value) (equal reflect.Value, ok bool) {
equal = v.MethodByName("Equal")
if equal == zeroValue {
return zeroValue, false
}
typ := equal.Type()
ok = typ.NumIn() == 1 && typ.In(0) == v.Type() &&
typ.NumOut() == 1 && typ.Out(0) == boolType
return equal, ok
}

222
vendor/github.com/powerman/deepequal/deepequal.go generated vendored Normal file
View File

@ -0,0 +1,222 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE-go file.
// Deep equality test via reflection
package deepequal
import (
"reflect"
"unsafe"
)
// 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.
type visit struct {
a1 unsafe.Pointer
a2 unsafe.Pointer
typ reflect.Type
}
// Tests for deep equality using reflected types. The map argument tracks
// comparisons that have already been seen, which allows short circuiting on
// recursive types.
func deepValueEqual(v1, v2 reflect.Value, visited map[visit]bool) bool {
if !v1.IsValid() || !v2.IsValid() {
return v1.IsValid() == v2.IsValid()
}
if v1.Type() != v2.Type() {
return false
}
// We want to avoid putting more in the visited map than we need to.
// For any possible reference cycle that might be encountered,
// hard(v1, v2) needs to return true for at least one of the types in the cycle,
// and it's safe and valid to get Value's internal pointer.
hard := func(v1, v2 reflect.Value) bool {
switch v1.Kind() {
case reflect.Ptr:
fallthrough
case reflect.Map, reflect.Slice, reflect.Interface:
// Nil pointers cannot be cyclic. Avoid putting them in the visited map.
return !v1.IsNil() && !v2.IsNil()
}
return false
}
if hard(v1, v2) {
// For a Ptr or Map value, we need to check flagIndir,
// which we do by calling the pointer method.
// For Slice or Interface, flagIndir is always set,
// and using v.ptr suffices.
ptrval := func(v reflect.Value) unsafe.Pointer {
switch v.Kind() {
case reflect.Ptr, reflect.Map:
return (unsafe.Pointer)(v.Pointer())
default:
vRef := (*value)(unsafe.Pointer(&v))
return vRef.ptr
}
}
addr1 := ptrval(v1)
addr2 := ptrval(v2)
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 := v1.Type()
v := visit{addr1, addr2, typ}
if visited[v] {
return true
}
// Remember for later.
visited[v] = true
}
if equal, ok := equalFunc(v1); ok {
return call(equal, []reflect.Value{v2})[0].Bool()
}
switch v1.Kind() {
case reflect.Array:
for i := 0; i < v1.Len(); i++ {
if !deepValueEqual(v1.Index(i), v2.Index(i), visited) {
return false
}
}
return true
case reflect.Slice:
if v1.IsNil() != v2.IsNil() {
return false
}
if v1.Len() != v2.Len() {
return false
}
if v1.Pointer() == v2.Pointer() {
return true
}
for i := 0; i < v1.Len(); i++ {
if !deepValueEqual(v1.Index(i), v2.Index(i), visited) {
return false
}
}
return true
case reflect.Interface:
if v1.IsNil() || v2.IsNil() {
return v1.IsNil() == v2.IsNil()
}
return deepValueEqual(v1.Elem(), v2.Elem(), visited)
case reflect.Ptr:
if v1.Pointer() == v2.Pointer() {
return true
}
return deepValueEqual(v1.Elem(), v2.Elem(), visited)
case reflect.Struct:
for i, n := 0, v1.NumField(); i < n; i++ {
if !deepValueEqual(v1.Field(i), v2.Field(i), visited) {
return false
}
}
return true
case reflect.Map:
if v1.IsNil() != v2.IsNil() {
return false
}
if v1.Len() != v2.Len() {
return false
}
if v1.Pointer() == v2.Pointer() {
return true
}
for _, k := range v1.MapKeys() {
val1 := v1.MapIndex(k)
val2 := v2.MapIndex(k)
if !val1.IsValid() || !val2.IsValid() || !deepValueEqual(val1, val2, visited) {
return false
}
}
return true
case reflect.Func:
if v1.IsNil() && v2.IsNil() {
return true
}
// Can't do better than this:
return false
default:
// Normal equality suffices
return valueInterface(v1) == valueInterface(v2)
}
}
// DeepEqual reports whether x and y are ``deeply equal,'' defined as follows.
// Two values of identical type are deeply equal if one of the following cases applies.
// Values of distinct types are never deeply equal.
//
// If x's type implements Equal method such as x.Equal(y) returns true then
// values are deeply equal.
//
// Array values are deeply equal when their corresponding elements are deeply equal.
//
// Struct values are deeply equal if their corresponding fields,
// both exported and unexported, are deeply equal.
//
// Func values are deeply equal if both are nil; otherwise they are not deeply equal.
//
// Interface values are deeply equal if they hold deeply equal concrete values.
//
// Map values are deeply equal when all of the following are true:
// they are both nil or both non-nil, they have the same length,
// and either they are the same map object or their corresponding keys
// (matched using Go equality) map to deeply equal values.
//
// Pointer values are deeply equal if they are equal using Go's == operator
// or if they point to deeply equal values.
//
// Slice values are deeply equal when all of the following are true:
// they are both nil or both non-nil, they have the same length,
// and either they point to the same initial entry of the same underlying array
// (that is, &x[0] == &y[0]) or their corresponding elements (up to length) are deeply equal.
// Note that a non-nil empty slice and a nil slice (for example, []byte{} and []byte(nil))
// are not deeply equal.
//
// Other values - numbers, bools, strings, and channels - are deeply equal
// if they are equal using Go's == operator.
//
// In general DeepEqual is a recursive relaxation of Go's == operator.
// However, this idea is impossible to implement without some inconsistency.
// Specifically, it is possible for a value to be unequal to itself,
// either because it is of func type (uncomparable in general)
// or because it is a floating-point NaN value (not equal to itself in floating-point comparison),
// or because it is an array, struct, or interface containing
// such a value.
// On the other hand, pointer values are always equal to themselves,
// even if they point at or contain such problematic values,
// because they compare equal using Go's == operator, and that
// is a sufficient condition to be deeply equal, regardless of content.
// DeepEqual has been defined so that the same short-cut applies
// to slices and maps: if x and y are the same slice or the same map,
// they are deeply equal regardless of content.
//
// As DeepEqual traverses the data values it may find a cycle. The
// second and subsequent times that DeepEqual compares two pointer
// values that have been compared before, it treats the values as
// equal rather than examining the values to which they point.
// This ensures that DeepEqual terminates.
func DeepEqual(x, y interface{}) bool {
if x == nil || y == nil {
return x == y
}
v1 := reflect.ValueOf(x)
v2 := reflect.ValueOf(y)
if v1.Type() != v2.Type() {
return false
}
return deepValueEqual(v1, v2, make(map[visit]bool))
}

3
vendor/github.com/powerman/deepequal/go.mod generated vendored Normal file
View File

@ -0,0 +1,3 @@
module github.com/powerman/deepequal
go 1.16

40
vendor/github.com/powerman/deepequal/type.go generated vendored Normal file
View File

@ -0,0 +1,40 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE-go file.
package deepequal
import "unsafe"
// tflag is used by an rtype to signal what extra type information is
// available in the memory directly following the rtype value.
//
// tflag values must be kept in sync with copies in:
// cmd/compile/internal/gc/reflect.go
// cmd/link/internal/ld/decodesym.go
// runtime/type.go
type tflag uint8
// rtype is the common implementation of most values.
// It is embedded in other struct types.
//
// rtype must be kept in sync with ../runtime/type.go:/^type._type.
type rtype struct {
size uintptr
ptrdata uintptr // number of bytes in the type that can contain pointers
hash uint32 // hash of type; avoids computation in hash tables
tflag tflag // extra type information flags
align uint8 // alignment of variable with this type
fieldAlign uint8 // alignment of struct field with this type
kind uint8 // enumeration for C
// function for comparing objects of this type
// (ptr to object A, ptr to object B) -> ==?
equal func(unsafe.Pointer, unsafe.Pointer) bool
gcdata *byte // garbage collection data
str nameOff // string form
ptrToThis typeOff // type for pointer to this type, may be zero
}
type nameOff int32 // offset to a name
type typeOff int32 // offset to an *rtype

50
vendor/github.com/powerman/deepequal/value.go generated vendored Normal file
View File

@ -0,0 +1,50 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE-go file.
package deepequal
import "unsafe"
type value struct {
// typ holds the type of the value represented by a Value.
typ *rtype
// Pointer-valued data or, if flagIndir is set, pointer to data.
// Valid when either flagIndir is set or typ.pointers() is true.
ptr unsafe.Pointer
// flag holds metadata about the value.
// The lowest bits are flag bits:
// - flagStickyRO: obtained via unexported not embedded field, so read-only
// - flagEmbedRO: obtained via unexported embedded field, so read-only
// - flagIndir: val holds a pointer to the data
// - flagAddr: v.CanAddr is true (implies flagIndir)
// - flagMethod: v is a method value.
// The next five bits give the Kind of the value.
// This repeats typ.Kind() except for method values.
// The remaining 23+ bits give a method number for method values.
// If flag.kind() != Func, code can assume that flagMethod is unset.
// If ifaceIndir(typ), code can assume that flagIndir is set.
flag
// A method value represents a curried method invocation
// like r.Read for some receiver r. The typ+val+flag bits describe
// the receiver r, but the flag's Kind bits say Func (methods are
// functions), and the top bits of the flag give the method number
// in r's type's method table.
}
type flag uintptr
const (
flagKindWidth = 5 // there are 27 kinds
flagKindMask flag = 1<<flagKindWidth - 1
flagStickyRO flag = 1 << 5
flagEmbedRO flag = 1 << 6
flagIndir flag = 1 << 7
flagAddr flag = 1 << 8
flagMethod flag = 1 << 9
flagMethodShift = 10
flagRO flag = flagStickyRO | flagEmbedRO
)

4
vendor/modules.txt vendored
View File

@ -304,9 +304,11 @@ github.com/pkg/errors
github.com/pmezard/go-difflib/difflib
# github.com/polyfloyd/go-errorlint v0.0.0-20210510181950-ab96adb96fea
github.com/polyfloyd/go-errorlint/errorlint
# github.com/powerman/check v1.5.0
# github.com/powerman/check v1.6.0
## explicit
github.com/powerman/check
# github.com/powerman/deepequal v0.1.0
github.com/powerman/deepequal
# github.com/prometheus/client_golang v1.7.1
github.com/prometheus/client_golang/prometheus
github.com/prometheus/client_golang/prometheus/internal