-
Notifications
You must be signed in to change notification settings - Fork 1
/
diffmatcher_test.go
48 lines (45 loc) · 962 Bytes
/
diffmatcher_test.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
47
48
package cmpmock
import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
func Test_DiffEq(t *testing.T) {
type Foo struct{ CreateAt time.Time }
t1 := time.Now()
t2 := t1.Add(100 * time.Millisecond)
type args struct {
want interface{}
opts cmp.Options
}
tests := []struct {
name string
args args
x Foo
wantMatch bool
wantDiff string
}{
{
name: "diff less than a second with default option",
args: args{
want: Foo{CreateAt: t1},
opts: nil,
},
x: Foo{CreateAt: t2},
wantMatch: true,
wantDiff: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sut := DiffEq(tt.args.want, tt.args.opts...)
x := Foo{CreateAt: t2}
if got := sut.Matches(x); got != tt.wantMatch {
t.Errorf("Matches() = %v, want %v", got, tt.wantMatch)
}
if got := sut.String(); got != tt.wantDiff {
t.Errorf("String() = %q, want %q", got, tt.wantDiff)
}
})
}
}