5 "github.com/onsi/gomega/format"
9 type HaveKeyMatcher struct {
13 func (matcher *HaveKeyMatcher) Match(actual interface{}) (success bool, err error) {
15 return false, fmt.Errorf("HaveKey matcher expects a map. Got:%s", format.Object(actual, 1))
18 keyMatcher, keyIsMatcher := matcher.Key.(omegaMatcher)
20 keyMatcher = &EqualMatcher{Expected: matcher.Key}
23 keys := reflect.ValueOf(actual).MapKeys()
24 for i := 0; i < len(keys); i++ {
25 success, err := keyMatcher.Match(keys[i].Interface())
27 return false, fmt.Errorf("HaveKey's key matcher failed with:\n%s%s", format.Indent, err.Error())
37 func (matcher *HaveKeyMatcher) FailureMessage(actual interface{}) (message string) {
38 switch matcher.Key.(type) {
40 return format.Message(actual, "to have key matching", matcher.Key)
42 return format.Message(actual, "to have key", matcher.Key)
46 func (matcher *HaveKeyMatcher) NegatedFailureMessage(actual interface{}) (message string) {
47 switch matcher.Key.(type) {
49 return format.Message(actual, "not to have key matching", matcher.Key)
51 return format.Message(actual, "not to have key", matcher.Key)