aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/gomega/matchers/have_each_matcher.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-04-26 11:03:59 -0400
committerGitHub <noreply@github.com>2022-04-26 11:03:59 -0400
commitfc3a48232faf21b9a6450c403b814fec182d1ed3 (patch)
tree75ec0bcb89c3f60e3be3da259a6cdce427ccbd1a /vendor/github.com/onsi/gomega/matchers/have_each_matcher.go
parente7edf30a1b4b2c78a24c593c30ef393e053b4e2f (diff)
parent49264c7148c1b14203f16b79994cf1dd927fb5e0 (diff)
downloadpodman-fc3a48232faf21b9a6450c403b814fec182d1ed3.tar.gz
podman-fc3a48232faf21b9a6450c403b814fec182d1ed3.tar.bz2
podman-fc3a48232faf21b9a6450c403b814fec182d1ed3.zip
Merge pull request #14005 from rhatdan/VENDOR
vendor in containers/(common,buildah,storage)
Diffstat (limited to 'vendor/github.com/onsi/gomega/matchers/have_each_matcher.go')
-rw-r--r--vendor/github.com/onsi/gomega/matchers/have_each_matcher.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/github.com/onsi/gomega/matchers/have_each_matcher.go b/vendor/github.com/onsi/gomega/matchers/have_each_matcher.go
new file mode 100644
index 000000000..025b6e1ac
--- /dev/null
+++ b/vendor/github.com/onsi/gomega/matchers/have_each_matcher.go
@@ -0,0 +1,65 @@
+package matchers
+
+import (
+ "fmt"
+ "reflect"
+
+ "github.com/onsi/gomega/format"
+)
+
+type HaveEachMatcher struct {
+ Element interface{}
+}
+
+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",
+ format.Object(actual, 1))
+ }
+
+ elemMatcher, elementIsMatcher := matcher.Element.(omegaMatcher)
+ if !elementIsMatcher {
+ elemMatcher = &EqualMatcher{Expected: matcher.Element}
+ }
+
+ value := reflect.ValueOf(actual)
+ if value.Len() == 0 {
+ return false, fmt.Errorf("HaveEach matcher expects a non-empty array/slice/map. Got:\n%s",
+ format.Object(actual, 1))
+ }
+
+ var valueAt func(int) interface{}
+ if isMap(actual) {
+ keys := value.MapKeys()
+ valueAt = func(i int) interface{} {
+ return value.MapIndex(keys[i]).Interface()
+ }
+ } else {
+ valueAt = func(i int) interface{} {
+ return value.Index(i).Interface()
+ }
+ }
+
+ // if there are no elements, then HaveEach will match.
+ for i := 0; i < value.Len(); i++ {
+ success, err := elemMatcher.Match(valueAt(i))
+ if err != nil {
+ return false, err
+ }
+ if !success {
+ return false, nil
+ }
+ }
+
+ return true, nil
+}
+
+// FailureMessage returns a suitable failure message.
+func (matcher *HaveEachMatcher) FailureMessage(actual interface{}) (message string) {
+ return format.Message(actual, "to contain element matching", matcher.Element)
+}
+
+// NegatedFailureMessage returns a suitable negated failure message.
+func (matcher *HaveEachMatcher) NegatedFailureMessage(actual interface{}) (message string) {
+ return format.Message(actual, "not to contain element matching", matcher.Element)
+}