-
Notifications
You must be signed in to change notification settings - Fork 3
/
uuid_test.go
64 lines (51 loc) · 1.5 KB
/
uuid_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
package validator
import (
"context"
"testing"
"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
)
type uuidStringer struct {
Value string
}
func (s uuidStringer) String() string {
return s.Value
}
func TestUUID_ValidateValue_Successfully(t *testing.T) {
ctx := context.Background()
err := NewUUID().ValidateValue(ctx, "00000000-0000-0000-0000-000000000001")
assert.NoError(t, err)
}
func TestUUID_ValidatePtrValue_Successfully(t *testing.T) {
ctx := context.Background()
value := "00000000-0000-0000-0000-000000000001"
err := NewUUID().ValidateValue(ctx, &value)
assert.NoError(t, err)
}
func TestUUID_ValidateStringerValue_Successfully(t *testing.T) {
ctx := context.Background()
value := uuidStringer{Value: "00000000-0000-0000-0000-000000000001"}
err := NewUUID().ValidateValue(ctx, &value)
assert.NoError(t, err)
}
func TestUUID_ValidateValue_InvalidValue_Failed(t *testing.T) {
ctx := context.Background()
err := NewUUID().ValidateValue(ctx, "12323435-343")
assert.Error(t, err)
}
func TestUUID_ValidateValue_ZeroUUID_Failed(t *testing.T) {
ctx := context.Background()
err := NewUUID().ValidateValue(ctx, "00000000-0000-0000-0000-000000000000")
assert.Error(t, err)
}
func TestUUID_ValidateValue_Version(t *testing.T) {
ctx := context.Background()
v4 := uuid.Must(uuid.NewV4())
v7 := uuid.Must(uuid.NewV7())
v := NewUUID().
WithVersion(UUIDVersionV7)
err := v.ValidateValue(ctx, v4.String())
assert.Error(t, err)
err = v.ValidateValue(ctx, v7.String())
assert.NoError(t, err)
}