mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Update gomega godeps to include gstruct
This commit is contained in:
parent
11c5320750
commit
b19d71792f
58
Godeps/Godeps.json
generated
58
Godeps/Godeps.json
generated
@ -1666,63 +1666,73 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega",
|
"ImportPath": "github.com/onsi/gomega",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/format",
|
"ImportPath": "github.com/onsi/gomega/format",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ImportPath": "github.com/onsi/gomega/gstruct",
|
||||||
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ImportPath": "github.com/onsi/gomega/gstruct/errors",
|
||||||
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/internal/assertion",
|
"ImportPath": "github.com/onsi/gomega/internal/assertion",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/internal/asyncassertion",
|
"ImportPath": "github.com/onsi/gomega/internal/asyncassertion",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/internal/oraclematcher",
|
"ImportPath": "github.com/onsi/gomega/internal/oraclematcher",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/internal/testingtsupport",
|
"ImportPath": "github.com/onsi/gomega/internal/testingtsupport",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/matchers",
|
"ImportPath": "github.com/onsi/gomega/matchers",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/matchers/support/goraph/bipartitegraph",
|
"ImportPath": "github.com/onsi/gomega/matchers/support/goraph/bipartitegraph",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/matchers/support/goraph/edge",
|
"ImportPath": "github.com/onsi/gomega/matchers/support/goraph/edge",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/matchers/support/goraph/node",
|
"ImportPath": "github.com/onsi/gomega/matchers/support/goraph/node",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/matchers/support/goraph/util",
|
"ImportPath": "github.com/onsi/gomega/matchers/support/goraph/util",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/onsi/gomega/types",
|
"ImportPath": "github.com/onsi/gomega/types",
|
||||||
"Comment": "v1.0-115-g9ed8da1",
|
"Comment": "v1.0-122-gd59fa0a",
|
||||||
"Rev": "9ed8da19f2156b87a803a8fdf6d126f627a12db1"
|
"Rev": "d59fa0ac68bb5dd932ee8d24eed631cdd519efc3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/opencontainers/runc/libcontainer",
|
"ImportPath": "github.com/opencontainers/runc/libcontainer",
|
||||||
|
2344
Godeps/LICENSES
generated
2344
Godeps/LICENSES
generated
File diff suppressed because it is too large
Load Diff
4
vendor/github.com/onsi/gomega/README.md
generated
vendored
4
vendor/github.com/onsi/gomega/README.md
generated
vendored
@ -10,6 +10,10 @@ To discuss Gomega and get updates, join the [google group](https://groups.google
|
|||||||
|
|
||||||
Learn more about Ginkgo [here](http://onsi.github.io/ginkgo/)
|
Learn more about Ginkgo [here](http://onsi.github.io/ginkgo/)
|
||||||
|
|
||||||
|
## Community Matchers
|
||||||
|
|
||||||
|
A collection of community matchers is available on the [wiki](https://github.com/onsi/gomega/wiki).
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Gomega is MIT-Licensed
|
Gomega is MIT-Licensed
|
||||||
|
20
vendor/github.com/onsi/gomega/format/format.go
generated
vendored
20
vendor/github.com/onsi/gomega/format/format.go
generated
vendored
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Use MaxDepth to set the maximum recursion depth when printing deeply nested objects
|
// Use MaxDepth to set the maximum recursion depth when printing deeply nested objects
|
||||||
@ -143,9 +144,6 @@ func formatValue(value reflect.Value, indentation uint) string {
|
|||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
return formatValue(value.Elem(), indentation)
|
return formatValue(value.Elem(), indentation)
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
if value.Type().Elem().Kind() == reflect.Uint8 {
|
|
||||||
return formatString(value.Bytes(), indentation)
|
|
||||||
}
|
|
||||||
return formatSlice(value, indentation)
|
return formatSlice(value, indentation)
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
return formatString(value.String(), indentation)
|
return formatString(value.String(), indentation)
|
||||||
@ -189,6 +187,10 @@ func formatString(object interface{}, indentation uint) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func formatSlice(v reflect.Value, indentation uint) string {
|
func formatSlice(v reflect.Value, indentation uint) string {
|
||||||
|
if v.Kind() == reflect.Slice && v.Type().Elem().Kind() == reflect.Uint8 && isPrintableString(string(v.Bytes())){
|
||||||
|
return formatString(v.Bytes(), indentation)
|
||||||
|
}
|
||||||
|
|
||||||
l := v.Len()
|
l := v.Len()
|
||||||
result := make([]string, l)
|
result := make([]string, l)
|
||||||
longest := 0
|
longest := 0
|
||||||
@ -261,3 +263,15 @@ func isNilValue(a reflect.Value) bool {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns true when the string is entirely made of printable runes, false otherwise.
|
||||||
|
*/
|
||||||
|
func isPrintableString(str string) bool {
|
||||||
|
for _, runeValue := range str {
|
||||||
|
if !strconv.IsPrint(runeValue) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
141
vendor/github.com/onsi/gomega/gstruct/elements.go
generated
vendored
Normal file
141
vendor/github.com/onsi/gomega/gstruct/elements.go
generated
vendored
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
package gstruct
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"runtime/debug"
|
||||||
|
|
||||||
|
"github.com/onsi/gomega/format"
|
||||||
|
errorsutil "github.com/onsi/gomega/gstruct/errors"
|
||||||
|
"github.com/onsi/gomega/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
//MatchAllElements succeeds if every element of a slice matches the element matcher it maps to
|
||||||
|
//through the id function, and every element matcher is matched.
|
||||||
|
// Expect([]string{"a", "b"}).To(MatchAllElements(idFn, matchers.Elements{
|
||||||
|
// "a": BeEqual("a"),
|
||||||
|
// "b": BeEqual("b"),
|
||||||
|
// })
|
||||||
|
func MatchAllElements(identifier Identifier, elements Elements) types.GomegaMatcher {
|
||||||
|
return &ElementsMatcher{
|
||||||
|
Identifier: identifier,
|
||||||
|
Elements: elements,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//MatchElements succeeds if each element of a slice matches the element matcher it maps to
|
||||||
|
//through the id function. It can ignore extra elements and/or missing elements.
|
||||||
|
// Expect([]string{"a", "c"}).To(MatchElements(idFn, IgnoreMissing|IgnoreExtra, matchers.Elements{
|
||||||
|
// "a": BeEqual("a")
|
||||||
|
// "b": BeEqual("b"),
|
||||||
|
// })
|
||||||
|
func MatchElements(identifier Identifier, options Options, elements Elements) types.GomegaMatcher {
|
||||||
|
return &ElementsMatcher{
|
||||||
|
Identifier: identifier,
|
||||||
|
Elements: elements,
|
||||||
|
IgnoreExtras: options&IgnoreExtras != 0,
|
||||||
|
IgnoreMissing: options&IgnoreMissing != 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ElementsMatcher is a NestingMatcher that applies custom matchers to each element of a slice mapped
|
||||||
|
// by the Identifier function.
|
||||||
|
// TODO: Extend this to work with arrays & maps (map the key) as well.
|
||||||
|
type ElementsMatcher struct {
|
||||||
|
// Matchers for each element.
|
||||||
|
Elements Elements
|
||||||
|
// Function mapping an element to the string key identifying its matcher.
|
||||||
|
Identifier Identifier
|
||||||
|
|
||||||
|
// Whether to ignore extra elements or consider it an error.
|
||||||
|
IgnoreExtras bool
|
||||||
|
// Whether to ignore missing elements or consider it an error.
|
||||||
|
IgnoreMissing bool
|
||||||
|
|
||||||
|
// State.
|
||||||
|
failures []error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Element ID to matcher.
|
||||||
|
type Elements map[string]types.GomegaMatcher
|
||||||
|
|
||||||
|
// Function for identifying (mapping) elements.
|
||||||
|
type Identifier func(element interface{}) string
|
||||||
|
|
||||||
|
func (m *ElementsMatcher) Match(actual interface{}) (success bool, err error) {
|
||||||
|
if reflect.TypeOf(actual).Kind() != reflect.Slice {
|
||||||
|
return false, fmt.Errorf("%v is type %T, expected slice", actual, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.failures = m.matchElements(actual)
|
||||||
|
if len(m.failures) > 0 {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ElementsMatcher) matchElements(actual interface{}) (errs []error) {
|
||||||
|
// Provide more useful error messages in the case of a panic.
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("panic checking %+v: %v\n%s", actual, err, debug.Stack()))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
val := reflect.ValueOf(actual)
|
||||||
|
elements := map[string]bool{}
|
||||||
|
for i := 0; i < val.Len(); i++ {
|
||||||
|
element := val.Index(i).Interface()
|
||||||
|
id := m.Identifier(element)
|
||||||
|
// TODO: Add options to ignore & match duplicates.
|
||||||
|
if elements[id] {
|
||||||
|
errs = append(errs, fmt.Errorf("found duplicate element ID %s", id))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
elements[id] = true
|
||||||
|
|
||||||
|
matcher, expected := m.Elements[id]
|
||||||
|
if !expected {
|
||||||
|
if !m.IgnoreExtras {
|
||||||
|
errs = append(errs, fmt.Errorf("unexpected element %s", id))
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
match, err := matcher.Match(element)
|
||||||
|
if match {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
if nesting, ok := matcher.(errorsutil.NestingMatcher); ok {
|
||||||
|
err = errorsutil.AggregateError(nesting.Failures())
|
||||||
|
} else {
|
||||||
|
err = errors.New(matcher.FailureMessage(element))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errs = append(errs, errorsutil.Nest(fmt.Sprintf("[%s]", id), err))
|
||||||
|
}
|
||||||
|
|
||||||
|
for id := range m.Elements {
|
||||||
|
if !elements[id] && !m.IgnoreMissing {
|
||||||
|
errs = append(errs, fmt.Errorf("missing expected element %s", id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ElementsMatcher) FailureMessage(actual interface{}) (message string) {
|
||||||
|
failure := errorsutil.AggregateError(m.failures)
|
||||||
|
return format.Message(actual, fmt.Sprintf("to match elements: %v", failure))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ElementsMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||||
|
return format.Message(actual, "not to match elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ElementsMatcher) Failures() []error {
|
||||||
|
return m.failures
|
||||||
|
}
|
72
vendor/github.com/onsi/gomega/gstruct/errors/nested_types.go
generated
vendored
Normal file
72
vendor/github.com/onsi/gomega/gstruct/errors/nested_types.go
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package errors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/onsi/gomega/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A stateful matcher that nests other matchers within it and preserves the error types of the
|
||||||
|
// nested matcher failures.
|
||||||
|
type NestingMatcher interface {
|
||||||
|
types.GomegaMatcher
|
||||||
|
|
||||||
|
// Returns the failures of nested matchers.
|
||||||
|
Failures() []error
|
||||||
|
}
|
||||||
|
|
||||||
|
// An error type for labeling errors on deeply nested matchers.
|
||||||
|
type NestedError struct {
|
||||||
|
Path string
|
||||||
|
Err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *NestedError) Error() string {
|
||||||
|
// Indent Errors.
|
||||||
|
indented := strings.Replace(e.Err.Error(), "\n", "\n\t", -1)
|
||||||
|
return fmt.Sprintf("%s:\n\t%v", e.Path, indented)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a NestedError with the given path.
|
||||||
|
// If err is a NestedError, prepend the path to it.
|
||||||
|
// If err is an AggregateError, recursively Nest each error.
|
||||||
|
func Nest(path string, err error) error {
|
||||||
|
if ag, ok := err.(AggregateError); ok {
|
||||||
|
var errs AggregateError
|
||||||
|
for _, e := range ag {
|
||||||
|
errs = append(errs, Nest(path, e))
|
||||||
|
}
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
if ne, ok := err.(*NestedError); ok {
|
||||||
|
return &NestedError{
|
||||||
|
Path: path + ne.Path,
|
||||||
|
Err: ne.Err,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &NestedError{
|
||||||
|
Path: path,
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// An error type for treating multiple errors as a single error.
|
||||||
|
type AggregateError []error
|
||||||
|
|
||||||
|
// Error is part of the error interface.
|
||||||
|
func (err AggregateError) Error() string {
|
||||||
|
if len(err) == 0 {
|
||||||
|
// This should never happen, really.
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if len(err) == 1 {
|
||||||
|
return err[0].Error()
|
||||||
|
}
|
||||||
|
result := fmt.Sprintf("[%s", err[0].Error())
|
||||||
|
for i := 1; i < len(err); i++ {
|
||||||
|
result += fmt.Sprintf(", %s", err[i].Error())
|
||||||
|
}
|
||||||
|
result += "]"
|
||||||
|
return result
|
||||||
|
}
|
141
vendor/github.com/onsi/gomega/gstruct/fields.go
generated
vendored
Normal file
141
vendor/github.com/onsi/gomega/gstruct/fields.go
generated
vendored
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
package gstruct
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"runtime/debug"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/onsi/gomega/format"
|
||||||
|
errorsutil "github.com/onsi/gomega/gstruct/errors"
|
||||||
|
"github.com/onsi/gomega/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
//MatchAllFields succeeds if every field of a struct matches the field matcher associated with
|
||||||
|
//it, and every element matcher is matched.
|
||||||
|
// Expect([]string{"a", "b"}).To(MatchAllFields(idFn, gstruct.Fields{
|
||||||
|
// "a": BeEqual("a"),
|
||||||
|
// "b": BeEqual("b"),
|
||||||
|
// })
|
||||||
|
func MatchAllFields(fields Fields) types.GomegaMatcher {
|
||||||
|
return &FieldsMatcher{
|
||||||
|
Fields: fields,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//MatchFields succeeds if each element of a struct matches the field matcher associated with
|
||||||
|
//it. It can ignore extra fields and/or missing fields.
|
||||||
|
// Expect([]string{"a", "c"}).To(MatchFields(idFn, IgnoreMissing|IgnoreExtra, gstruct.Fields{
|
||||||
|
// "a": BeEqual("a")
|
||||||
|
// "b": BeEqual("b"),
|
||||||
|
// })
|
||||||
|
func MatchFields(options Options, fields Fields) types.GomegaMatcher {
|
||||||
|
return &FieldsMatcher{
|
||||||
|
Fields: fields,
|
||||||
|
IgnoreExtras: options&IgnoreExtras != 0,
|
||||||
|
IgnoreMissing: options&IgnoreMissing != 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type FieldsMatcher struct {
|
||||||
|
// Matchers for each field.
|
||||||
|
Fields Fields
|
||||||
|
|
||||||
|
// Whether to ignore extra elements or consider it an error.
|
||||||
|
IgnoreExtras bool
|
||||||
|
// Whether to ignore missing elements or consider it an error.
|
||||||
|
IgnoreMissing bool
|
||||||
|
|
||||||
|
// State.
|
||||||
|
failures []error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Field name to matcher.
|
||||||
|
type Fields map[string]types.GomegaMatcher
|
||||||
|
|
||||||
|
func (m *FieldsMatcher) Match(actual interface{}) (success bool, err error) {
|
||||||
|
if reflect.TypeOf(actual).Kind() != reflect.Struct {
|
||||||
|
return false, fmt.Errorf("%v is type %T, expected struct", actual, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.failures = m.matchFields(actual)
|
||||||
|
if len(m.failures) > 0 {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FieldsMatcher) matchFields(actual interface{}) (errs []error) {
|
||||||
|
val := reflect.ValueOf(actual)
|
||||||
|
typ := val.Type()
|
||||||
|
fields := map[string]bool{}
|
||||||
|
for i := 0; i < val.NumField(); i++ {
|
||||||
|
fieldName := typ.Field(i).Name
|
||||||
|
fields[fieldName] = true
|
||||||
|
|
||||||
|
err := func() (err error) {
|
||||||
|
// This test relies heavily on reflect, which tends to panic.
|
||||||
|
// Recover here to provide more useful error messages in that case.
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
err = fmt.Errorf("panic checking %+v: %v\n%s", actual, r, debug.Stack())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
matcher, expected := m.Fields[fieldName]
|
||||||
|
if !expected {
|
||||||
|
if !m.IgnoreExtras {
|
||||||
|
return fmt.Errorf("unexpected field %s: %+v", fieldName, actual)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var field interface{}
|
||||||
|
if val.Field(i).IsValid() {
|
||||||
|
field = val.Field(i).Interface()
|
||||||
|
} else {
|
||||||
|
field = reflect.Zero(typ.Field(i).Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
match, err := matcher.Match(field)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !match {
|
||||||
|
if nesting, ok := matcher.(errorsutil.NestingMatcher); ok {
|
||||||
|
return errorsutil.AggregateError(nesting.Failures())
|
||||||
|
}
|
||||||
|
return errors.New(matcher.FailureMessage(field))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}()
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, errorsutil.Nest("."+fieldName, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for field := range m.Fields {
|
||||||
|
if !fields[field] && !m.IgnoreMissing {
|
||||||
|
errs = append(errs, fmt.Errorf("missing expected field %s", field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FieldsMatcher) FailureMessage(actual interface{}) (message string) {
|
||||||
|
failures := make([]string, len(m.failures))
|
||||||
|
for i := range m.failures {
|
||||||
|
failures[i] = m.failures[i].Error()
|
||||||
|
}
|
||||||
|
return format.Message(reflect.TypeOf(actual).Name(),
|
||||||
|
fmt.Sprintf("to match fields: {\n%v\n}\n", strings.Join(failures, "\n")))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FieldsMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||||
|
return format.Message(actual, "not to match fields")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FieldsMatcher) Failures() []error {
|
||||||
|
return m.failures
|
||||||
|
}
|
37
vendor/github.com/onsi/gomega/gstruct/ignore.go
generated
vendored
Normal file
37
vendor/github.com/onsi/gomega/gstruct/ignore.go
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package gstruct
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/onsi/gomega/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
//Ignore ignores the actual value and always succeeds.
|
||||||
|
// Expect(nil).To(Ignore())
|
||||||
|
// Expect(true).To(Ignore())
|
||||||
|
func Ignore() types.GomegaMatcher {
|
||||||
|
return &IgnoreMatcher{true}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Reject ignores the actual value and always fails. It can be used in conjunction with IgnoreMissing
|
||||||
|
//to catch problematic elements, or to verify tests are running.
|
||||||
|
// Expect(nil).NotTo(Reject())
|
||||||
|
// Expect(true).NotTo(Reject())
|
||||||
|
func Reject() types.GomegaMatcher {
|
||||||
|
return &IgnoreMatcher{false}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A matcher that either always succeeds or always fails.
|
||||||
|
type IgnoreMatcher struct {
|
||||||
|
Succeed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IgnoreMatcher) Match(actual interface{}) (bool, error) {
|
||||||
|
return m.Succeed, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IgnoreMatcher) FailureMessage(_ interface{}) (message string) {
|
||||||
|
return "Unconditional failure"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IgnoreMatcher) NegatedFailureMessage(_ interface{}) (message string) {
|
||||||
|
return "Unconditional success"
|
||||||
|
}
|
56
vendor/github.com/onsi/gomega/gstruct/pointer.go
generated
vendored
Normal file
56
vendor/github.com/onsi/gomega/gstruct/pointer.go
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package gstruct
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/onsi/gomega/format"
|
||||||
|
"github.com/onsi/gomega/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
//PointTo applies the given matcher to the value pointed to by actual. It fails if the pointer is
|
||||||
|
//nil.
|
||||||
|
// actual := 5
|
||||||
|
// Expect(&actual).To(PointTo(Equal(5)))
|
||||||
|
func PointTo(matcher types.GomegaMatcher) types.GomegaMatcher {
|
||||||
|
return &PointerMatcher{
|
||||||
|
Matcher: matcher,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type PointerMatcher struct {
|
||||||
|
Matcher types.GomegaMatcher
|
||||||
|
|
||||||
|
// Failure message.
|
||||||
|
failure string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PointerMatcher) Match(actual interface{}) (bool, error) {
|
||||||
|
val := reflect.ValueOf(actual)
|
||||||
|
|
||||||
|
// return error if actual type is not a pointer
|
||||||
|
if val.Kind() != reflect.Ptr {
|
||||||
|
return false, fmt.Errorf("PointerMatcher expects a pointer but we have '%s'", val.Kind())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !val.IsValid() || val.IsNil() {
|
||||||
|
m.failure = format.Message(actual, "not to be <nil>")
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward the value.
|
||||||
|
elem := val.Elem().Interface()
|
||||||
|
match, err := m.Matcher.Match(elem)
|
||||||
|
if !match {
|
||||||
|
m.failure = m.Matcher.FailureMessage(elem)
|
||||||
|
}
|
||||||
|
return match, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PointerMatcher) FailureMessage(_ interface{}) (message string) {
|
||||||
|
return m.failure
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PointerMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||||
|
return m.Matcher.NegatedFailureMessage(actual)
|
||||||
|
}
|
11
vendor/github.com/onsi/gomega/gstruct/types.go
generated
vendored
Normal file
11
vendor/github.com/onsi/gomega/gstruct/types.go
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package gstruct
|
||||||
|
|
||||||
|
//Options is the type for options passed to some matchers.
|
||||||
|
type Options int
|
||||||
|
|
||||||
|
const (
|
||||||
|
//IgnoreExtras tells the matcher to ignore extra elements or fields, rather than triggering a failure.
|
||||||
|
IgnoreExtras Options = 1 << iota
|
||||||
|
//IgnoreMissing tells the matcher to ignore missing elements or fields, rather than triggering a failure.
|
||||||
|
IgnoreMissing
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user