-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_test.go
73 lines (68 loc) · 1.64 KB
/
mock_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package pulid
import (
"strings"
"testing"
"time"
"github.com/oklog/ulid/v2"
)
func Test_mockULIDGenerator_newULID(t *testing.T) {
type args struct {
prefix string
t time.Time
}
tests := []struct {
name string
args args
want ulid.ULID
}{
{
name: "AA#1",
args: args{prefix: "AA", t: time.Now()},
want: ulid.MustParseStrict("01FD7SJ7J006AFVGQT5ZYC0GEK"),
},
{
name: "AA#2",
args: args{prefix: "AA", t: time.Now()},
want: ulid.MustParseStrict("01FD7SJ7J0ZW908PVKS1Q4ZYAZ"),
},
{
name: "AA#3",
args: args{prefix: "AA", t: time.Now()},
want: ulid.MustParseStrict("01FD7SJ7J0YSHABVQ85AYZ8JHD"),
},
{
name: "BB#1",
args: args{prefix: "BB", t: time.Now()},
want: ulid.MustParseStrict("01FD7SJ7J006AFVGQT5ZYC0GEK"),
},
{
name: "BB#1",
args: args{prefix: "BB", t: time.Now()},
want: ulid.MustParseStrict("01FD7SJ7J0ZW908PVKS1Q4ZYAZ"),
},
{
name: "BB#3",
args: args{prefix: "BB", t: time.Now()},
want: ulid.MustParseStrict("01FD7SJ7J0YSHABVQ85AYZ8JHD"),
},
}
g := &MockULIDGenerator{}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := g.newULID(tt.args.prefix, tt.args.t); got.Compare(tt.want) != 0 {
t.Errorf("MockULIDGenerator.newULID() = %v, want %v, %v", got, tt.want, got.Compare(tt.want))
}
})
}
g = &MockULIDGenerator{}
SetULIDGenerator(g)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pu := MustNew(tt.args.prefix)
got := ulid.MustParseStrict(strings.Split(pu.String(), ":")[1])
if got.Compare(tt.want) != 0 {
t.Errorf("MustNew() = %v, want %v, %v", got, tt.want, got.Compare(tt.want))
}
})
}
}