-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmp.go
More file actions
40 lines (33 loc) · 748 Bytes
/
Copy pathcmp.go
File metadata and controls
40 lines (33 loc) · 748 Bytes
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
package gomml
import (
"fmt"
"testing"
"github.com/golang/mock/gomock"
"github.com/google/go-cmp/cmp"
)
type cmpMatcher struct {
t *testing.T
want interface{}
opts []cmp.Option
}
// Cmp is a Matcher that matches using go-cmp.
//
// Example usage:
//
// dbMock.EXPECT().
// Insert(gomml.Cmp(&someComplex).
//
func Cmp(t *testing.T, want interface{}, opts ...cmp.Option) gomock.Matcher {
return &cmpMatcher{t, want, opts}
}
func (m *cmpMatcher) Matches(x interface{}) bool {
diff := cmp.Diff(m.want, x, m.opts...)
if diff == "" {
return true
}
m.t.Logf("(-want +got):\n%s", diff)
return false
}
func (m *cmpMatcher) String() string {
return fmt.Sprintf("is equal to %v with %s", m.want, cmp.Options(m.opts).String())
}