forked from cloudfoundry/auctioneer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store_node_matcher.go
43 lines (35 loc) · 1.27 KB
/
store_node_matcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package storenodematchers
import (
"fmt"
"reflect"
"github.com/cloudfoundry/storeadapter"
"github.com/onsi/gomega/format"
)
type moduloIndexMatcher struct {
expected storeadapter.StoreNode
}
//MatchStoreNode matches store nodes without worrying about node.Index
//Use Equal if you want to ensure Indices line up.
func MatchStoreNode(expected storeadapter.StoreNode) *moduloIndexMatcher {
return &moduloIndexMatcher{
expected: expected,
}
}
func (matcher *moduloIndexMatcher) Match(actual interface{}) (success bool, err error) {
actualNode, ok := actual.(storeadapter.StoreNode)
if !ok {
return false, fmt.Errorf("Expected a store node. Got:\n%s", format.Object(actual, 1))
}
matcher.expected.Index = actualNode.Index
return reflect.DeepEqual(matcher.expected, actual), nil
}
func (matcher *moduloIndexMatcher) FailureMessage(actual interface{}) (message string) {
actualNode, _ := actual.(storeadapter.StoreNode)
matcher.expected.Index = actualNode.Index
return format.Message(actual, "to be", matcher.expected)
}
func (matcher *moduloIndexMatcher) NegatedFailureMessage(actual interface{}) (message string) {
actualNode, _ := actual.(storeadapter.StoreNode)
matcher.expected.Index = actualNode.Index
return format.Message(actual, "not to be", matcher.expected)
}