-
Notifications
You must be signed in to change notification settings - Fork 0
/
uuidv7_test.go
59 lines (57 loc) · 1.4 KB
/
uuidv7_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
package uuid
import (
"reflect"
"testing"
)
func TestNewV7(t *testing.T) {
tests := []struct {
name string
fakeRandom []byte
fakeTime int64
wantUUID UUID
wantErr bool
}{
{
"Default",
[]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
testVecTimeCustom,
UUID{0x01, 0x79, 0x75, 0x56, 0x0F, 0xBB, 0x70, 0x00, 0x81, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
false,
},
{
"Sequence",
[]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
testVecTimeCustom,
UUID{0x01, 0x79, 0x75, 0x56, 0x0F, 0xBB, 0x70, 0x01, 0x81, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
false,
},
{
"NextTime",
[]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
testVecTimeCustom + 1000000000,
UUID{0x01, 0x79, 0x75, 0x56, 0x13, 0xA3, 0x70, 0x00, 0x81, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
false,
},
{
"NoRandom",
nil,
testVecTimeCustom,
UUID{0x01, 0x79, 0x75, 0x56, 0x0F, 0xBB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
testTime(tt.fakeTime)
testRand(tt.fakeRandom...)
gotUUID, err := NewV7()
if (err != nil) != tt.wantErr {
t.Errorf("NewV7() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(gotUUID, tt.wantUUID) {
t.Errorf("NewV7() = %v, want %v", gotUUID, tt.wantUUID)
}
})
}
}