mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: bump the github-dependencies group with 3 updates
Bumps the github-dependencies group with 3 updates: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo), [github.com/onsi/gomega](https://github.com/onsi/gomega) and [github.com/stretchr/testify](https://github.com/stretchr/testify). Updates `github.com/onsi/ginkgo/v2` from 2.21.0 to 2.22.0 - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/ginkgo/compare/v2.21.0...v2.22.0) Updates `github.com/onsi/gomega` from 1.35.1 to 1.36.0 - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.35.1...v1.36.0) Updates `github.com/stretchr/testify` from 1.9.0 to 1.10.0 - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.9.0...v1.10.0) --- updated-dependencies: - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-dependencies - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-dependencies - dependency-name: github.com/stretchr/testify dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
mergify[bot]
parent
84aadc9189
commit
630c97a009
16
vendor/github.com/onsi/gomega/matchers/be_empty_matcher.go
generated
vendored
16
vendor/github.com/onsi/gomega/matchers/be_empty_matcher.go
generated
vendored
@ -4,17 +4,31 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
"github.com/onsi/gomega/matchers/internal/miter"
|
||||
)
|
||||
|
||||
type BeEmptyMatcher struct {
|
||||
}
|
||||
|
||||
func (matcher *BeEmptyMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
// short-circuit the iterator case, as we only need to see the first
|
||||
// element, if any.
|
||||
if miter.IsIter(actual) {
|
||||
var length int
|
||||
if miter.IsSeq2(actual) {
|
||||
miter.IterateKV(actual, func(k, v reflect.Value) bool { length++; return false })
|
||||
} else {
|
||||
miter.IterateV(actual, func(v reflect.Value) bool { length++; return false })
|
||||
}
|
||||
return length == 0, nil
|
||||
}
|
||||
|
||||
length, ok := lengthOf(actual)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("BeEmpty matcher expects a string/array/map/channel/slice. Got:\n%s", format.Object(actual, 1))
|
||||
return false, fmt.Errorf("BeEmpty matcher expects a string/array/map/channel/slice/iterator. Got:\n%s", format.Object(actual, 1))
|
||||
}
|
||||
|
||||
return length == 0, nil
|
||||
|
32
vendor/github.com/onsi/gomega/matchers/consist_of.go
generated
vendored
32
vendor/github.com/onsi/gomega/matchers/consist_of.go
generated
vendored
@ -7,6 +7,7 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
"github.com/onsi/gomega/matchers/internal/miter"
|
||||
"github.com/onsi/gomega/matchers/support/goraph/bipartitegraph"
|
||||
)
|
||||
|
||||
@ -17,8 +18,8 @@ type ConsistOfMatcher struct {
|
||||
}
|
||||
|
||||
func (matcher *ConsistOfMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
if !isArrayOrSlice(actual) && !isMap(actual) {
|
||||
return false, fmt.Errorf("ConsistOf matcher expects an array/slice/map. Got:\n%s", format.Object(actual, 1))
|
||||
if !isArrayOrSlice(actual) && !isMap(actual) && !miter.IsIter(actual) {
|
||||
return false, fmt.Errorf("ConsistOf matcher expects an array/slice/map/iter.Seq/iter.Seq2. Got:\n%s", format.Object(actual, 1))
|
||||
}
|
||||
|
||||
matchers := matchers(matcher.Elements)
|
||||
@ -60,10 +61,21 @@ func equalMatchersToElements(matchers []interface{}) (elements []interface{}) {
|
||||
}
|
||||
|
||||
func flatten(elems []interface{}) []interface{} {
|
||||
if len(elems) != 1 || !isArrayOrSlice(elems[0]) {
|
||||
if len(elems) != 1 ||
|
||||
!(isArrayOrSlice(elems[0]) ||
|
||||
(miter.IsIter(elems[0]) && !miter.IsSeq2(elems[0]))) {
|
||||
return elems
|
||||
}
|
||||
|
||||
if miter.IsIter(elems[0]) {
|
||||
flattened := []any{}
|
||||
miter.IterateV(elems[0], func(v reflect.Value) bool {
|
||||
flattened = append(flattened, v.Interface())
|
||||
return true
|
||||
})
|
||||
return flattened
|
||||
}
|
||||
|
||||
value := reflect.ValueOf(elems[0])
|
||||
flattened := make([]interface{}, value.Len())
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
@ -116,7 +128,19 @@ func presentable(elems []interface{}) interface{} {
|
||||
func valuesOf(actual interface{}) []interface{} {
|
||||
value := reflect.ValueOf(actual)
|
||||
values := []interface{}{}
|
||||
if isMap(actual) {
|
||||
if miter.IsIter(actual) {
|
||||
if miter.IsSeq2(actual) {
|
||||
miter.IterateKV(actual, func(k, v reflect.Value) bool {
|
||||
values = append(values, v.Interface())
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
miter.IterateV(actual, func(v reflect.Value) bool {
|
||||
values = append(values, v.Interface())
|
||||
return true
|
||||
})
|
||||
}
|
||||
} else if isMap(actual) {
|
||||
keys := value.MapKeys()
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
values = append(values, value.MapIndex(keys[i]).Interface())
|
||||
|
241
vendor/github.com/onsi/gomega/matchers/contain_element_matcher.go
generated
vendored
241
vendor/github.com/onsi/gomega/matchers/contain_element_matcher.go
generated
vendored
@ -8,6 +8,7 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
"github.com/onsi/gomega/matchers/internal/miter"
|
||||
)
|
||||
|
||||
type ContainElementMatcher struct {
|
||||
@ -16,16 +17,18 @@ type ContainElementMatcher struct {
|
||||
}
|
||||
|
||||
func (matcher *ContainElementMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
if !isArrayOrSlice(actual) && !isMap(actual) {
|
||||
return false, fmt.Errorf("ContainElement matcher expects an array/slice/map. Got:\n%s", format.Object(actual, 1))
|
||||
if !isArrayOrSlice(actual) && !isMap(actual) && !miter.IsIter(actual) {
|
||||
return false, fmt.Errorf("ContainElement matcher expects an array/slice/map/iterator. Got:\n%s", format.Object(actual, 1))
|
||||
}
|
||||
|
||||
var actualT reflect.Type
|
||||
var result reflect.Value
|
||||
switch l := len(matcher.Result); {
|
||||
case l > 1:
|
||||
switch numResultArgs := len(matcher.Result); {
|
||||
case numResultArgs > 1:
|
||||
return false, errors.New("ContainElement matcher expects at most a single optional pointer to store its findings at")
|
||||
case l == 1:
|
||||
case numResultArgs == 1:
|
||||
// Check the optional result arg to point to a single value/array/slice/map
|
||||
// of a type compatible with the actual value.
|
||||
if reflect.ValueOf(matcher.Result[0]).Kind() != reflect.Ptr {
|
||||
return false, fmt.Errorf("ContainElement matcher expects a non-nil pointer to store its findings at. Got\n%s",
|
||||
format.Object(matcher.Result[0], 1))
|
||||
@ -34,93 +37,209 @@ func (matcher *ContainElementMatcher) Match(actual interface{}) (success bool, e
|
||||
resultReference := matcher.Result[0]
|
||||
result = reflect.ValueOf(resultReference).Elem() // what ResultReference points to, to stash away our findings
|
||||
switch result.Kind() {
|
||||
case reflect.Array:
|
||||
case reflect.Array: // result arrays are not supported, as they cannot be dynamically sized.
|
||||
if miter.IsIter(actual) {
|
||||
_, actualvT := miter.IterKVTypes(actual)
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
reflect.SliceOf(actualvT), result.Type().String())
|
||||
}
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
reflect.SliceOf(actualT.Elem()).String(), result.Type().String())
|
||||
case reflect.Slice:
|
||||
if !isArrayOrSlice(actual) {
|
||||
|
||||
case reflect.Slice: // result slice
|
||||
// can we assign elements in actual to elements in what the result
|
||||
// arg points to?
|
||||
// - ✔ actual is an array or slice
|
||||
// - ✔ actual is an iter.Seq producing "v" elements
|
||||
// - ✔ actual is an iter.Seq2 producing "v" elements, ignoring
|
||||
// the "k" elements.
|
||||
switch {
|
||||
case isArrayOrSlice(actual):
|
||||
if !actualT.Elem().AssignableTo(result.Type().Elem()) {
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
actualT.String(), result.Type().String())
|
||||
}
|
||||
|
||||
case miter.IsIter(actual):
|
||||
_, actualvT := miter.IterKVTypes(actual)
|
||||
if !actualvT.AssignableTo(result.Type().Elem()) {
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
actualvT.String(), result.Type().String())
|
||||
}
|
||||
|
||||
default: // incompatible result reference
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
reflect.MapOf(actualT.Key(), actualT.Elem()).String(), result.Type().String())
|
||||
}
|
||||
if !actualT.Elem().AssignableTo(result.Type().Elem()) {
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
actualT.String(), result.Type().String())
|
||||
}
|
||||
case reflect.Map:
|
||||
if !isMap(actual) {
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
actualT.String(), result.Type().String())
|
||||
}
|
||||
if !actualT.AssignableTo(result.Type()) {
|
||||
|
||||
case reflect.Map: // result map
|
||||
// can we assign elements in actual to elements in what the result
|
||||
// arg points to?
|
||||
// - ✔ actual is a map
|
||||
// - ✔ actual is an iter.Seq2 (iter.Seq doesn't fit though)
|
||||
switch {
|
||||
case isMap(actual):
|
||||
if !actualT.AssignableTo(result.Type()) {
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
actualT.String(), result.Type().String())
|
||||
}
|
||||
|
||||
case miter.IsIter(actual):
|
||||
actualkT, actualvT := miter.IterKVTypes(actual)
|
||||
if actualkT == nil {
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
reflect.SliceOf(actualvT).String(), result.Type().String())
|
||||
}
|
||||
if !reflect.MapOf(actualkT, actualvT).AssignableTo(result.Type()) {
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
reflect.MapOf(actualkT, actualvT), result.Type().String())
|
||||
}
|
||||
|
||||
default: // incompatible result reference
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
actualT.String(), result.Type().String())
|
||||
}
|
||||
|
||||
default:
|
||||
if !actualT.Elem().AssignableTo(result.Type()) {
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
actualT.Elem().String(), result.Type().String())
|
||||
// can we assign a (single) element in actual to what the result arg
|
||||
// points to?
|
||||
switch {
|
||||
case miter.IsIter(actual):
|
||||
_, actualvT := miter.IterKVTypes(actual)
|
||||
if !actualvT.AssignableTo(result.Type()) {
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
actualvT.String(), result.Type().String())
|
||||
}
|
||||
default:
|
||||
if !actualT.Elem().AssignableTo(result.Type()) {
|
||||
return false, fmt.Errorf("ContainElement cannot return findings. Need *%s, got *%s",
|
||||
actualT.Elem().String(), result.Type().String())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the supplied matcher isn't an Omega matcher, default to the Equal
|
||||
// matcher.
|
||||
elemMatcher, elementIsMatcher := matcher.Element.(omegaMatcher)
|
||||
if !elementIsMatcher {
|
||||
elemMatcher = &EqualMatcher{Expected: matcher.Element}
|
||||
}
|
||||
|
||||
value := reflect.ValueOf(actual)
|
||||
var valueAt func(int) interface{}
|
||||
|
||||
var getFindings func() reflect.Value
|
||||
var foundAt func(int)
|
||||
var getFindings func() reflect.Value // abstracts how the findings are collected and stored
|
||||
var lastError error
|
||||
|
||||
if isMap(actual) {
|
||||
keys := value.MapKeys()
|
||||
valueAt = func(i int) interface{} {
|
||||
return value.MapIndex(keys[i]).Interface()
|
||||
}
|
||||
if result.Kind() != reflect.Invalid {
|
||||
fm := reflect.MakeMap(actualT)
|
||||
getFindings = func() reflect.Value {
|
||||
return fm
|
||||
if !miter.IsIter(actual) {
|
||||
var valueAt func(int) interface{}
|
||||
var foundAt func(int)
|
||||
// We're dealing with an array/slice/map, so in all cases we can iterate
|
||||
// over the elements in actual using indices (that can be considered
|
||||
// keys in case of maps).
|
||||
if isMap(actual) {
|
||||
keys := value.MapKeys()
|
||||
valueAt = func(i int) interface{} {
|
||||
return value.MapIndex(keys[i]).Interface()
|
||||
}
|
||||
foundAt = func(i int) {
|
||||
fm.SetMapIndex(keys[i], value.MapIndex(keys[i]))
|
||||
if result.Kind() != reflect.Invalid {
|
||||
fm := reflect.MakeMap(actualT)
|
||||
getFindings = func() reflect.Value { return fm }
|
||||
foundAt = func(i int) {
|
||||
fm.SetMapIndex(keys[i], value.MapIndex(keys[i]))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
valueAt = func(i int) interface{} {
|
||||
return value.Index(i).Interface()
|
||||
}
|
||||
if result.Kind() != reflect.Invalid {
|
||||
var fsl reflect.Value
|
||||
if result.Kind() == reflect.Slice {
|
||||
fsl = reflect.MakeSlice(result.Type(), 0, 0)
|
||||
} else {
|
||||
fsl = reflect.MakeSlice(reflect.SliceOf(result.Type()), 0, 0)
|
||||
}
|
||||
getFindings = func() reflect.Value { return fsl }
|
||||
foundAt = func(i int) {
|
||||
fsl = reflect.Append(fsl, value.Index(i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
elem := valueAt(i)
|
||||
success, err := elemMatcher.Match(elem)
|
||||
if err != nil {
|
||||
lastError = err
|
||||
continue
|
||||
}
|
||||
if success {
|
||||
if result.Kind() == reflect.Invalid {
|
||||
return true, nil
|
||||
}
|
||||
foundAt(i)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
valueAt = func(i int) interface{} {
|
||||
return value.Index(i).Interface()
|
||||
}
|
||||
// We're dealing with an iterator as a first-class construct, so things
|
||||
// are slightly different: there is no index defined as in case of
|
||||
// arrays/slices/maps, just "ooooorder"
|
||||
var found func(k, v reflect.Value)
|
||||
if result.Kind() != reflect.Invalid {
|
||||
var f reflect.Value
|
||||
if result.Kind() == reflect.Slice {
|
||||
f = reflect.MakeSlice(result.Type(), 0, 0)
|
||||
if result.Kind() == reflect.Map {
|
||||
fm := reflect.MakeMap(result.Type())
|
||||
getFindings = func() reflect.Value { return fm }
|
||||
found = func(k, v reflect.Value) { fm.SetMapIndex(k, v) }
|
||||
} else {
|
||||
f = reflect.MakeSlice(reflect.SliceOf(result.Type()), 0, 0)
|
||||
}
|
||||
getFindings = func() reflect.Value {
|
||||
return f
|
||||
}
|
||||
foundAt = func(i int) {
|
||||
f = reflect.Append(f, value.Index(i))
|
||||
var fsl reflect.Value
|
||||
if result.Kind() == reflect.Slice {
|
||||
fsl = reflect.MakeSlice(result.Type(), 0, 0)
|
||||
} else {
|
||||
fsl = reflect.MakeSlice(reflect.SliceOf(result.Type()), 0, 0)
|
||||
}
|
||||
getFindings = func() reflect.Value { return fsl }
|
||||
found = func(_, v reflect.Value) { fsl = reflect.Append(fsl, v) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var lastError error
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
elem := valueAt(i)
|
||||
success, err := elemMatcher.Match(elem)
|
||||
if err != nil {
|
||||
lastError = err
|
||||
continue
|
||||
success := false
|
||||
actualkT, _ := miter.IterKVTypes(actual)
|
||||
if actualkT == nil {
|
||||
miter.IterateV(actual, func(v reflect.Value) bool {
|
||||
var err error
|
||||
success, err = elemMatcher.Match(v.Interface())
|
||||
if err != nil {
|
||||
lastError = err
|
||||
return true // iterate on...
|
||||
}
|
||||
if success {
|
||||
if result.Kind() == reflect.Invalid {
|
||||
return false // a match and no result needed, so we're done
|
||||
}
|
||||
found(reflect.Value{}, v)
|
||||
}
|
||||
return true // iterate on...
|
||||
})
|
||||
} else {
|
||||
miter.IterateKV(actual, func(k, v reflect.Value) bool {
|
||||
var err error
|
||||
success, err = elemMatcher.Match(v.Interface())
|
||||
if err != nil {
|
||||
lastError = err
|
||||
return true // iterate on...
|
||||
}
|
||||
if success {
|
||||
if result.Kind() == reflect.Invalid {
|
||||
return false // a match and no result needed, so we're done
|
||||
}
|
||||
found(k, v)
|
||||
}
|
||||
return true // iterate on...
|
||||
})
|
||||
}
|
||||
if success {
|
||||
if result.Kind() == reflect.Invalid {
|
||||
return true, nil
|
||||
}
|
||||
foundAt(i)
|
||||
if success && result.Kind() == reflect.Invalid {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
5
vendor/github.com/onsi/gomega/matchers/contain_elements_matcher.go
generated
vendored
5
vendor/github.com/onsi/gomega/matchers/contain_elements_matcher.go
generated
vendored
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
"github.com/onsi/gomega/matchers/internal/miter"
|
||||
"github.com/onsi/gomega/matchers/support/goraph/bipartitegraph"
|
||||
)
|
||||
|
||||
@ -13,8 +14,8 @@ type ContainElementsMatcher struct {
|
||||
}
|
||||
|
||||
func (matcher *ContainElementsMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
if !isArrayOrSlice(actual) && !isMap(actual) {
|
||||
return false, fmt.Errorf("ContainElements matcher expects an array/slice/map. Got:\n%s", format.Object(actual, 1))
|
||||
if !isArrayOrSlice(actual) && !isMap(actual) && !miter.IsIter(actual) {
|
||||
return false, fmt.Errorf("ContainElements matcher expects an array/slice/map/iter.Seq/iter.Seq2. Got:\n%s", format.Object(actual, 1))
|
||||
}
|
||||
|
||||
matchers := matchers(matcher.Elements)
|
||||
|
40
vendor/github.com/onsi/gomega/matchers/have_each_matcher.go
generated
vendored
40
vendor/github.com/onsi/gomega/matchers/have_each_matcher.go
generated
vendored
@ -5,6 +5,7 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
"github.com/onsi/gomega/matchers/internal/miter"
|
||||
)
|
||||
|
||||
type HaveEachMatcher struct {
|
||||
@ -12,8 +13,8 @@ type HaveEachMatcher struct {
|
||||
}
|
||||
|
||||
func (matcher *HaveEachMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
if !isArrayOrSlice(actual) && !isMap(actual) {
|
||||
return false, fmt.Errorf("HaveEach matcher expects an array/slice/map. Got:\n%s",
|
||||
if !isArrayOrSlice(actual) && !isMap(actual) && !miter.IsIter(actual) {
|
||||
return false, fmt.Errorf("HaveEach matcher expects an array/slice/map/iter.Seq/iter.Seq2. Got:\n%s",
|
||||
format.Object(actual, 1))
|
||||
}
|
||||
|
||||
@ -22,6 +23,38 @@ func (matcher *HaveEachMatcher) Match(actual interface{}) (success bool, err err
|
||||
elemMatcher = &EqualMatcher{Expected: matcher.Element}
|
||||
}
|
||||
|
||||
if miter.IsIter(actual) {
|
||||
// rejecting the non-elements case works different for iterators as we
|
||||
// don't want to fetch all elements into a slice first.
|
||||
count := 0
|
||||
var success bool
|
||||
var err error
|
||||
if miter.IsSeq2(actual) {
|
||||
miter.IterateKV(actual, func(k, v reflect.Value) bool {
|
||||
count++
|
||||
success, err = elemMatcher.Match(v.Interface())
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return success
|
||||
})
|
||||
} else {
|
||||
miter.IterateV(actual, func(v reflect.Value) bool {
|
||||
count++
|
||||
success, err = elemMatcher.Match(v.Interface())
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return success
|
||||
})
|
||||
}
|
||||
if count == 0 {
|
||||
return false, fmt.Errorf("HaveEach matcher expects a non-empty iter.Seq/iter.Seq2. Got:\n%s",
|
||||
format.Object(actual, 1))
|
||||
}
|
||||
return success, err
|
||||
}
|
||||
|
||||
value := reflect.ValueOf(actual)
|
||||
if value.Len() == 0 {
|
||||
return false, fmt.Errorf("HaveEach matcher expects a non-empty array/slice/map. Got:\n%s",
|
||||
@ -40,7 +73,8 @@ func (matcher *HaveEachMatcher) Match(actual interface{}) (success bool, err err
|
||||
}
|
||||
}
|
||||
|
||||
// if there are no elements, then HaveEach will match.
|
||||
// if we never failed then we succeed; the empty/nil cases have already been
|
||||
// rejected above.
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
success, err := elemMatcher.Match(valueAt(i))
|
||||
if err != nil {
|
||||
|
53
vendor/github.com/onsi/gomega/matchers/have_exact_elements.go
generated
vendored
53
vendor/github.com/onsi/gomega/matchers/have_exact_elements.go
generated
vendored
@ -2,8 +2,10 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
"github.com/onsi/gomega/matchers/internal/miter"
|
||||
)
|
||||
|
||||
type mismatchFailure struct {
|
||||
@ -21,17 +23,58 @@ type HaveExactElementsMatcher struct {
|
||||
func (matcher *HaveExactElementsMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
matcher.resetState()
|
||||
|
||||
if isMap(actual) {
|
||||
return false, fmt.Errorf("error")
|
||||
if isMap(actual) || miter.IsSeq2(actual) {
|
||||
return false, fmt.Errorf("HaveExactElements matcher doesn't work on map or iter.Seq2. Got:\n%s", format.Object(actual, 1))
|
||||
}
|
||||
|
||||
matchers := matchers(matcher.Elements)
|
||||
values := valuesOf(actual)
|
||||
|
||||
lenMatchers := len(matchers)
|
||||
lenValues := len(values)
|
||||
|
||||
success = true
|
||||
|
||||
if miter.IsIter(actual) {
|
||||
// In the worst case, we need to see everything before we can give our
|
||||
// verdict. The only exception is fast fail.
|
||||
i := 0
|
||||
miter.IterateV(actual, func(v reflect.Value) bool {
|
||||
if i >= lenMatchers {
|
||||
// the iterator produces more values than we got matchers: this
|
||||
// is not good.
|
||||
matcher.extraIndex = i
|
||||
success = false
|
||||
return false
|
||||
}
|
||||
|
||||
elemMatcher := matchers[i].(omegaMatcher)
|
||||
match, err := elemMatcher.Match(v.Interface())
|
||||
if err != nil {
|
||||
matcher.mismatchFailures = append(matcher.mismatchFailures, mismatchFailure{
|
||||
index: i,
|
||||
failure: err.Error(),
|
||||
})
|
||||
success = false
|
||||
} else if !match {
|
||||
matcher.mismatchFailures = append(matcher.mismatchFailures, mismatchFailure{
|
||||
index: i,
|
||||
failure: elemMatcher.FailureMessage(v.Interface()),
|
||||
})
|
||||
success = false
|
||||
}
|
||||
i++
|
||||
return true
|
||||
})
|
||||
if i < len(matchers) {
|
||||
// the iterator produced less values than we got matchers: this is
|
||||
// no good, no no no.
|
||||
matcher.missingIndex = i
|
||||
success = false
|
||||
}
|
||||
return success, nil
|
||||
}
|
||||
|
||||
values := valuesOf(actual)
|
||||
lenValues := len(values)
|
||||
|
||||
for i := 0; i < lenMatchers || i < lenValues; i++ {
|
||||
if i >= lenMatchers {
|
||||
matcher.extraIndex = i
|
||||
|
19
vendor/github.com/onsi/gomega/matchers/have_key_matcher.go
generated
vendored
19
vendor/github.com/onsi/gomega/matchers/have_key_matcher.go
generated
vendored
@ -7,6 +7,7 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
"github.com/onsi/gomega/matchers/internal/miter"
|
||||
)
|
||||
|
||||
type HaveKeyMatcher struct {
|
||||
@ -14,8 +15,8 @@ type HaveKeyMatcher struct {
|
||||
}
|
||||
|
||||
func (matcher *HaveKeyMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
if !isMap(actual) {
|
||||
return false, fmt.Errorf("HaveKey matcher expects a map. Got:%s", format.Object(actual, 1))
|
||||
if !isMap(actual) && !miter.IsSeq2(actual) {
|
||||
return false, fmt.Errorf("HaveKey matcher expects a map/iter.Seq2. Got:%s", format.Object(actual, 1))
|
||||
}
|
||||
|
||||
keyMatcher, keyIsMatcher := matcher.Key.(omegaMatcher)
|
||||
@ -23,6 +24,20 @@ func (matcher *HaveKeyMatcher) Match(actual interface{}) (success bool, err erro
|
||||
keyMatcher = &EqualMatcher{Expected: matcher.Key}
|
||||
}
|
||||
|
||||
if miter.IsSeq2(actual) {
|
||||
var success bool
|
||||
var err error
|
||||
miter.IterateKV(actual, func(k, v reflect.Value) bool {
|
||||
success, err = keyMatcher.Match(k.Interface())
|
||||
if err != nil {
|
||||
err = fmt.Errorf("HaveKey's key matcher failed with:\n%s%s", format.Indent, err.Error())
|
||||
return false
|
||||
}
|
||||
return !success
|
||||
})
|
||||
return success, err
|
||||
}
|
||||
|
||||
keys := reflect.ValueOf(actual).MapKeys()
|
||||
for i := 0; i < len(keys); i++ {
|
||||
success, err := keyMatcher.Match(keys[i].Interface())
|
||||
|
26
vendor/github.com/onsi/gomega/matchers/have_key_with_value_matcher.go
generated
vendored
26
vendor/github.com/onsi/gomega/matchers/have_key_with_value_matcher.go
generated
vendored
@ -7,6 +7,7 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
"github.com/onsi/gomega/matchers/internal/miter"
|
||||
)
|
||||
|
||||
type HaveKeyWithValueMatcher struct {
|
||||
@ -15,8 +16,8 @@ type HaveKeyWithValueMatcher struct {
|
||||
}
|
||||
|
||||
func (matcher *HaveKeyWithValueMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
if !isMap(actual) {
|
||||
return false, fmt.Errorf("HaveKeyWithValue matcher expects a map. Got:%s", format.Object(actual, 1))
|
||||
if !isMap(actual) && !miter.IsSeq2(actual) {
|
||||
return false, fmt.Errorf("HaveKeyWithValue matcher expects a map/iter.Seq2. Got:%s", format.Object(actual, 1))
|
||||
}
|
||||
|
||||
keyMatcher, keyIsMatcher := matcher.Key.(omegaMatcher)
|
||||
@ -29,6 +30,27 @@ func (matcher *HaveKeyWithValueMatcher) Match(actual interface{}) (success bool,
|
||||
valueMatcher = &EqualMatcher{Expected: matcher.Value}
|
||||
}
|
||||
|
||||
if miter.IsSeq2(actual) {
|
||||
var success bool
|
||||
var err error
|
||||
miter.IterateKV(actual, func(k, v reflect.Value) bool {
|
||||
success, err = keyMatcher.Match(k.Interface())
|
||||
if err != nil {
|
||||
err = fmt.Errorf("HaveKey's key matcher failed with:\n%s%s", format.Indent, err.Error())
|
||||
return false
|
||||
}
|
||||
if success {
|
||||
success, err = valueMatcher.Match(v.Interface())
|
||||
if err != nil {
|
||||
err = fmt.Errorf("HaveKeyWithValue's value matcher failed with:\n%s%s", format.Indent, err.Error())
|
||||
return false
|
||||
}
|
||||
}
|
||||
return !success
|
||||
})
|
||||
return success, err
|
||||
}
|
||||
|
||||
keys := reflect.ValueOf(actual).MapKeys()
|
||||
for i := 0; i < len(keys); i++ {
|
||||
success, err := keyMatcher.Match(keys[i].Interface())
|
||||
|
2
vendor/github.com/onsi/gomega/matchers/have_len_matcher.go
generated
vendored
2
vendor/github.com/onsi/gomega/matchers/have_len_matcher.go
generated
vendored
@ -13,7 +13,7 @@ type HaveLenMatcher struct {
|
||||
func (matcher *HaveLenMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
length, ok := lengthOf(actual)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("HaveLen matcher expects a string/array/map/channel/slice. Got:\n%s", format.Object(actual, 1))
|
||||
return false, fmt.Errorf("HaveLen matcher expects a string/array/map/channel/slice/iterator. Got:\n%s", format.Object(actual, 1))
|
||||
}
|
||||
|
||||
return length == matcher.Count, nil
|
||||
|
128
vendor/github.com/onsi/gomega/matchers/internal/miter/type_support_iter.go
generated
vendored
Normal file
128
vendor/github.com/onsi/gomega/matchers/internal/miter/type_support_iter.go
generated
vendored
Normal file
@ -0,0 +1,128 @@
|
||||
//go:build go1.23
|
||||
|
||||
package miter
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// HasIterators always returns false for Go versions before 1.23.
|
||||
func HasIterators() bool { return true }
|
||||
|
||||
// IsIter returns true if the specified value is a function type that can be
|
||||
// range-d over, otherwise false.
|
||||
//
|
||||
// We don't use reflect's CanSeq and CanSeq2 directly, as these would return
|
||||
// true also for other value types that are range-able, such as integers,
|
||||
// slices, et cetera. Here, we aim only at range-able (iterator) functions.
|
||||
func IsIter(it any) bool {
|
||||
if it == nil { // on purpose we only test for untyped nil.
|
||||
return false
|
||||
}
|
||||
// reject all non-iterator-func values, even if they're range-able.
|
||||
t := reflect.TypeOf(it)
|
||||
if t.Kind() != reflect.Func {
|
||||
return false
|
||||
}
|
||||
return t.CanSeq() || t.CanSeq2()
|
||||
}
|
||||
|
||||
// IterKVTypes returns the reflection types of an iterator's yield function's K
|
||||
// and optional V arguments, otherwise nil K and V reflection types.
|
||||
func IterKVTypes(it any) (k, v reflect.Type) {
|
||||
if it == nil {
|
||||
return
|
||||
}
|
||||
// reject all non-iterator-func values, even if they're range-able.
|
||||
t := reflect.TypeOf(it)
|
||||
if t.Kind() != reflect.Func {
|
||||
return
|
||||
}
|
||||
// get the reflection types for V, and where applicable, K.
|
||||
switch {
|
||||
case t.CanSeq():
|
||||
v = t. /*iterator fn*/ In(0). /*yield fn*/ In(0)
|
||||
case t.CanSeq2():
|
||||
yieldfn := t. /*iterator fn*/ In(0)
|
||||
k = yieldfn.In(0)
|
||||
v = yieldfn.In(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IsSeq2 returns true if the passed iterator function is compatible with
|
||||
// iter.Seq2, otherwise false.
|
||||
//
|
||||
// IsSeq2 hides the Go 1.23+ specific reflect.Type.CanSeq2 behind a facade which
|
||||
// is empty for Go versions before 1.23.
|
||||
func IsSeq2(it any) bool {
|
||||
if it == nil {
|
||||
return false
|
||||
}
|
||||
t := reflect.TypeOf(it)
|
||||
return t.Kind() == reflect.Func && t.CanSeq2()
|
||||
}
|
||||
|
||||
// isNilly returns true if v is either an untyped nil, or is a nil function (not
|
||||
// necessarily an iterator function).
|
||||
func isNilly(v any) bool {
|
||||
if v == nil {
|
||||
return true
|
||||
}
|
||||
rv := reflect.ValueOf(v)
|
||||
return rv.Kind() == reflect.Func && rv.IsNil()
|
||||
}
|
||||
|
||||
// IterateV loops over the elements produced by an iterator function, passing
|
||||
// the elements to the specified yield function individually and stopping only
|
||||
// when either the iterator function runs out of elements or the yield function
|
||||
// tell us to stop it.
|
||||
//
|
||||
// IterateV works very much like reflect.Value.Seq but hides the Go 1.23+
|
||||
// specific parts behind a facade which is empty for Go versions before 1.23, in
|
||||
// order to simplify code maintenance for matchers when using older Go versions.
|
||||
func IterateV(it any, yield func(v reflect.Value) bool) {
|
||||
if isNilly(it) {
|
||||
return
|
||||
}
|
||||
// reject all non-iterator-func values, even if they're range-able.
|
||||
t := reflect.TypeOf(it)
|
||||
if t.Kind() != reflect.Func || !t.CanSeq() {
|
||||
return
|
||||
}
|
||||
// Call the specified iterator function, handing it our adaptor to call the
|
||||
// specified generic reflection yield function.
|
||||
reflectedYield := reflect.MakeFunc(
|
||||
t. /*iterator fn*/ In(0),
|
||||
func(args []reflect.Value) []reflect.Value {
|
||||
return []reflect.Value{reflect.ValueOf(yield(args[0]))}
|
||||
})
|
||||
reflect.ValueOf(it).Call([]reflect.Value{reflectedYield})
|
||||
}
|
||||
|
||||
// IterateKV loops over the key-value elements produced by an iterator function,
|
||||
// passing the elements to the specified yield function individually and
|
||||
// stopping only when either the iterator function runs out of elements or the
|
||||
// yield function tell us to stop it.
|
||||
//
|
||||
// IterateKV works very much like reflect.Value.Seq2 but hides the Go 1.23+
|
||||
// specific parts behind a facade which is empty for Go versions before 1.23, in
|
||||
// order to simplify code maintenance for matchers when using older Go versions.
|
||||
func IterateKV(it any, yield func(k, v reflect.Value) bool) {
|
||||
if isNilly(it) {
|
||||
return
|
||||
}
|
||||
// reject all non-iterator-func values, even if they're range-able.
|
||||
t := reflect.TypeOf(it)
|
||||
if t.Kind() != reflect.Func || !t.CanSeq2() {
|
||||
return
|
||||
}
|
||||
// Call the specified iterator function, handing it our adaptor to call the
|
||||
// specified generic reflection yield function.
|
||||
reflectedYield := reflect.MakeFunc(
|
||||
t. /*iterator fn*/ In(0),
|
||||
func(args []reflect.Value) []reflect.Value {
|
||||
return []reflect.Value{reflect.ValueOf(yield(args[0], args[1]))}
|
||||
})
|
||||
reflect.ValueOf(it).Call([]reflect.Value{reflectedYield})
|
||||
}
|
44
vendor/github.com/onsi/gomega/matchers/internal/miter/type_support_noiter.go
generated
vendored
Normal file
44
vendor/github.com/onsi/gomega/matchers/internal/miter/type_support_noiter.go
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
//go:build !go1.23
|
||||
|
||||
/*
|
||||
Gomega matchers
|
||||
|
||||
This package implements the Gomega matchers and does not typically need to be imported.
|
||||
See the docs for Gomega for documentation on the matchers
|
||||
|
||||
http://onsi.github.io/gomega/
|
||||
*/
|
||||
|
||||
package miter
|
||||
|
||||
import "reflect"
|
||||
|
||||
// HasIterators always returns false for Go versions before 1.23.
|
||||
func HasIterators() bool { return false }
|
||||
|
||||
// IsIter always returns false for Go versions before 1.23 as there is no
|
||||
// iterator (function) pattern defined yet; see also:
|
||||
// https://tip.golang.org/blog/range-functions.
|
||||
func IsIter(i any) bool { return false }
|
||||
|
||||
// IsSeq2 always returns false for Go versions before 1.23 as there is no
|
||||
// iterator (function) pattern defined yet; see also:
|
||||
// https://tip.golang.org/blog/range-functions.
|
||||
func IsSeq2(it any) bool { return false }
|
||||
|
||||
// IterKVTypes always returns nil reflection types for Go versions before 1.23
|
||||
// as there is no iterator (function) pattern defined yet; see also:
|
||||
// https://tip.golang.org/blog/range-functions.
|
||||
func IterKVTypes(i any) (k, v reflect.Type) {
|
||||
return
|
||||
}
|
||||
|
||||
// IterateV never loops over what has been passed to it as an iterator for Go
|
||||
// versions before 1.23 as there is no iterator (function) pattern defined yet;
|
||||
// see also: https://tip.golang.org/blog/range-functions.
|
||||
func IterateV(it any, yield func(v reflect.Value) bool) {}
|
||||
|
||||
// IterateKV never loops over what has been passed to it as an iterator for Go
|
||||
// versions before 1.23 as there is no iterator (function) pattern defined yet;
|
||||
// see also: https://tip.golang.org/blog/range-functions.
|
||||
func IterateKV(it any, yield func(k, v reflect.Value) bool) {}
|
13
vendor/github.com/onsi/gomega/matchers/type_support.go
generated
vendored
13
vendor/github.com/onsi/gomega/matchers/type_support.go
generated
vendored
@ -15,6 +15,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/matchers/internal/miter"
|
||||
)
|
||||
|
||||
type omegaMatcher interface {
|
||||
@ -152,6 +154,17 @@ func lengthOf(a interface{}) (int, bool) {
|
||||
switch reflect.TypeOf(a).Kind() {
|
||||
case reflect.Map, reflect.Array, reflect.String, reflect.Chan, reflect.Slice:
|
||||
return reflect.ValueOf(a).Len(), true
|
||||
case reflect.Func:
|
||||
if !miter.IsIter(a) {
|
||||
return 0, false
|
||||
}
|
||||
var l int
|
||||
if miter.IsSeq2(a) {
|
||||
miter.IterateKV(a, func(k, v reflect.Value) bool { l++; return true })
|
||||
} else {
|
||||
miter.IterateV(a, func(v reflect.Value) bool { l++; return true })
|
||||
}
|
||||
return l, true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
|
Reference in New Issue
Block a user