-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuuid_test.go
More file actions
67 lines (59 loc) · 1.31 KB
/
suuid_test.go
File metadata and controls
67 lines (59 loc) · 1.31 KB
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
package suuid
import (
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)
func TestMarshalUUID(t *testing.T) {
t.Parallel()
tests := []struct {
name string
in uuid.UUID
out string
}{
{
name: "valid v7",
in: uuid.MustParse("019011ec-eadd-76d0-8347-df0d7c38d19c"),
out: "MDE5MDExZWMtZWFkZC03NmQwLTgzNDctZGYwZDdjMzhkMTlj",
},
{
name: "valid v4",
in: uuid.MustParse("540f9987-b0b2-421b-ac56-e3942ccea1c2"),
out: "NTQwZjk5ODctYjBiMi00MjFiLWFjNTYtZTM5NDJjY2VhMWMy",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var s SUUID
require.NoError(t, s.MarshalUUID(tt.in))
require.Equal(t, tt.out, s.String())
})
}
}
func TestUnmarshalUUID(t *testing.T) {
t.Parallel()
tests := []struct {
name string
in string
out uuid.UUID
}{
{
name: "valid v7",
in: "MDE5MDExZWMtZWFkZC03NmQwLTgzNDctZGYwZDdjMzhkMTlj",
out: uuid.MustParse("019011ec-eadd-76d0-8347-df0d7c38d19c"),
},
{
name: "valid v4",
in: "NTQwZjk5ODctYjBiMi00MjFiLWFjNTYtZTM5NDJjY2VhMWMy",
out: uuid.MustParse("540f9987-b0b2-421b-ac56-e3942ccea1c2"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := Parse(tt.in)
u, err := s.UnmarshalUUID()
require.NoError(t, err)
require.Equal(t, tt.out, u)
})
}
}