-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsistent.go
46 lines (39 loc) · 933 Bytes
/
consistent.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
44
45
46
package gomml
import (
"fmt"
"reflect"
"github.com/golang/mock/gomock"
)
type consistentMatcher struct {
m gomock.Matcher
decided bool
val interface{}
}
// Consistent is a Matcher that matches with consistent.
//
// The value must be the time between the constructor was called and
// it is validated.
//
// Example usage:
//
// consistentNow := gomml.Consistent(gomml.Now())
// dbMock.EXPECT().
// Insert(consistentNow, consistentNow).
//
func Consistent(m gomock.Matcher) gomock.Matcher {
return &consistentMatcher{m: m}
}
func (m *consistentMatcher) Matches(x interface{}) bool {
if m.decided {
return reflect.DeepEqual(m.val, x)
}
m.decided = true
m.val = x
return m.m.Matches(x)
}
func (m *consistentMatcher) String() string {
if m.decided {
return fmt.Sprintf("%v and must be consistent with %v", m.m.String(), m.val)
}
return fmt.Sprintf("%v and must be consistent", m.m.String())
}