mirror of
https://git.mirrors.martin98.com/https://github.com/ceph/ceph-csi.git
synced 2025-04-18 11:49:57 +08:00
![dependabot[bot]](/assets/img/avatar_default.png)
Bumps the github-dependencies group in /e2e with 2 updates: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) and [github.com/onsi/gomega](https://github.com/onsi/gomega). Updates `github.com/onsi/ginkgo/v2` from 2.23.0 to 2.23.3 - [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.23.0...v2.23.3) Updates `github.com/onsi/gomega` from 1.36.2 to 1.36.3 - [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.36.2...v1.36.3) --- updated-dependencies: - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-dependencies - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package matchers
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
|
|
"github.com/onsi/gomega/format"
|
|
)
|
|
|
|
type SatisfyMatcher struct {
|
|
Predicate any
|
|
|
|
// cached type
|
|
predicateArgType reflect.Type
|
|
}
|
|
|
|
func NewSatisfyMatcher(predicate any) *SatisfyMatcher {
|
|
if predicate == nil {
|
|
panic("predicate cannot be nil")
|
|
}
|
|
predicateType := reflect.TypeOf(predicate)
|
|
if predicateType.Kind() != reflect.Func {
|
|
panic("predicate must be a function")
|
|
}
|
|
if predicateType.NumIn() != 1 {
|
|
panic("predicate must have 1 argument")
|
|
}
|
|
if predicateType.NumOut() != 1 || predicateType.Out(0).Kind() != reflect.Bool {
|
|
panic("predicate must return bool")
|
|
}
|
|
|
|
return &SatisfyMatcher{
|
|
Predicate: predicate,
|
|
predicateArgType: predicateType.In(0),
|
|
}
|
|
}
|
|
|
|
func (m *SatisfyMatcher) Match(actual any) (success bool, err error) {
|
|
// prepare a parameter to pass to the predicate
|
|
var param reflect.Value
|
|
if actual != nil && reflect.TypeOf(actual).AssignableTo(m.predicateArgType) {
|
|
// The dynamic type of actual is compatible with the predicate argument.
|
|
param = reflect.ValueOf(actual)
|
|
|
|
} else if actual == nil && m.predicateArgType.Kind() == reflect.Interface {
|
|
// The dynamic type of actual is unknown, so there's no way to make its
|
|
// reflect.Value. Create a nil of the predicate argument, which is known.
|
|
param = reflect.Zero(m.predicateArgType)
|
|
|
|
} else {
|
|
return false, fmt.Errorf("predicate expects '%s' but we have '%T'", m.predicateArgType, actual)
|
|
}
|
|
|
|
// call the predicate with `actual`
|
|
fn := reflect.ValueOf(m.Predicate)
|
|
result := fn.Call([]reflect.Value{param})
|
|
return result[0].Bool(), nil
|
|
}
|
|
|
|
func (m *SatisfyMatcher) FailureMessage(actual any) (message string) {
|
|
return format.Message(actual, "to satisfy predicate", m.Predicate)
|
|
}
|
|
|
|
func (m *SatisfyMatcher) NegatedFailureMessage(actual any) (message string) {
|
|
return format.Message(actual, "to not satisfy predicate", m.Predicate)
|
|
}
|