-
Notifications
You must be signed in to change notification settings - Fork 0
/
uuidv6_test.go
44 lines (42 loc) · 1.84 KB
/
uuidv6_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
package uuid
import (
"reflect"
"testing"
)
func TestNewV6(t *testing.T) {
tests := []struct {
name string
fakeTime int64
fakeRandom []byte
resetMAC bool
hardwareMAC bool
wantUUID UUID
wantErr bool
}{
{"Default", testVecTimeRFC, []byte{0x33, 0xC8, 0x9E, 0x6B, 0xDE, 0xCE, 0xD8, 0x46}, true, false, UUID{0x1E, 0xC9, 0x41, 0x4C, 0x23, 0x2A, 0x6B, 0x00, 0xB3, 0xC8, 0x9F, 0x6B, 0xDE, 0xCE, 0xD8, 0x46}, false},
{"Sequence", testVecTimeRFC, []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, false, false, UUID{0x1E, 0xC9, 0x41, 0x4C, 0x23, 0x2A, 0x6B, 0x00, 0xB3, 0xC9, 0x9F, 0x6B, 0xDE, 0xCE, 0xD8, 0x46}, false},
{"SequenceNoRandom", testVecTimeRFC, nil, false, false, UUID{0x1E, 0xC9, 0x41, 0x4C, 0x23, 0x2A, 0x6B, 0x00, 0xB3, 0xCA, 0x9F, 0x6B, 0xDE, 0xCE, 0xD8, 0x46}, false},
{"DifferentTime", testVecTimeCustom, []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, false, false, UUID{0x1E, 0xBB, 0x64, 0x98, 0x54, 0x7D, 0x62, 0x3F, 0x81, 0x23, 0x9F, 0x6B, 0xDE, 0xCE, 0xD8, 0x46}, false},
{"DifferentTimeNoRandom", testVecTimeRFC, nil, false, false, UUID{}, true},
{"NewMAC", testVecTimeRFC, []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, true, false, UUID{0x1E, 0xC9, 0x41, 0x4C, 0x23, 0x2A, 0x6B, 0x00, 0x81, 0x23, 0x47, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, false},
{"NewMACNoRandom", testVecTimeRFC, nil, true, false, UUID{}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
testTime(tt.fakeTime)
testRand(tt.fakeRandom...)
if tt.resetMAC {
RandomMAC = nil
}
UseHardwareMAC = tt.hardwareMAC
gotUUID, err := NewV6()
if (err != nil) != tt.wantErr {
t.Errorf("NewV1() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err == nil && !reflect.DeepEqual(gotUUID, tt.wantUUID) {
t.Errorf("NewV1() = %v, want %v", gotUUID, tt.wantUUID)
}
})
}
}