-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchers.go
35 lines (29 loc) · 980 Bytes
/
matchers.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
package matchers
import (
"github.com/onsi/gomega/format"
"github.com/onsi/gomega/types"
"google.golang.org/protobuf/proto"
)
// ProtoEqualMatcher is a custom Gomega matcher for protocol buffers
type ProtoEqualMatcher struct {
Expected proto.Message
}
func (matcher *ProtoEqualMatcher) Match(actual interface{}) (success bool, err error) {
actualMessage, ok := actual.(proto.Message)
if !ok {
return false, nil
}
return proto.Equal(actualMessage, matcher.Expected), nil
}
func (matcher *ProtoEqualMatcher) FailureMessage(actual interface{}) (message string) {
return format.Message(actual, "to equal", matcher.Expected)
}
func (matcher *ProtoEqualMatcher) NegatedFailureMessage(actual interface{}) (message string) {
return format.Message(actual, "not to equal", matcher.Expected)
}
// ProtoEqual is a convenience function to create the matcher
func ProtoEqual(expected proto.Message) types.GomegaMatcher {
return &ProtoEqualMatcher{
Expected: expected,
}
}