mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-18 20:07:06 +00:00
Upgraded from 99c19923, branch release-3.0. This required fetching or upgrading the following: * k8s.io/api to kubernetes-1.9.1 * k8s.io/apimachinery to kubernetes-1.9.1 * github.com/juju/ratelimit to 1.0.1 * github.com/spf13/pflag to 4c012f6d Also, update Scope's imports/function calls to be compatible with the new client.
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package matchers
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
|
|
"github.com/onsi/gomega/format"
|
|
)
|
|
|
|
type HaveKeyMatcher struct {
|
|
Key interface{}
|
|
}
|
|
|
|
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))
|
|
}
|
|
|
|
keyMatcher, keyIsMatcher := matcher.Key.(omegaMatcher)
|
|
if !keyIsMatcher {
|
|
keyMatcher = &EqualMatcher{Expected: matcher.Key}
|
|
}
|
|
|
|
keys := reflect.ValueOf(actual).MapKeys()
|
|
for i := 0; i < len(keys); i++ {
|
|
success, err := keyMatcher.Match(keys[i].Interface())
|
|
if err != nil {
|
|
return false, fmt.Errorf("HaveKey's key matcher failed with:\n%s%s", format.Indent, err.Error())
|
|
}
|
|
if success {
|
|
return true, nil
|
|
}
|
|
}
|
|
|
|
return false, nil
|
|
}
|
|
|
|
func (matcher *HaveKeyMatcher) FailureMessage(actual interface{}) (message string) {
|
|
switch matcher.Key.(type) {
|
|
case omegaMatcher:
|
|
return format.Message(actual, "to have key matching", matcher.Key)
|
|
default:
|
|
return format.Message(actual, "to have key", matcher.Key)
|
|
}
|
|
}
|
|
|
|
func (matcher *HaveKeyMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
|
switch matcher.Key.(type) {
|
|
case omegaMatcher:
|
|
return format.Message(actual, "not to have key matching", matcher.Key)
|
|
default:
|
|
return format.Message(actual, "not to have key", matcher.Key)
|
|
}
|
|
}
|