-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuuid_validator_test.go
56 lines (46 loc) · 1.17 KB
/
uuid_validator_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
// Copyright 2021 Hyperscale. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package validator
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestUUIDValidator(t *testing.T) {
v := NewUUIDValidator()
assert.EqualError(t, v.Validate(124), "invalid input type \"int\" for UUID validator")
assert.Error(t, v.Validate("bad"))
assert.Error(t, v.Validate([]byte{
0x7d, 0x44, 0x48, 0x40,
0x9d, 0xc0,
0x11, 0xd1,
0xb2, 0x45,
0x5f, 0xfd, 0xce, 0x74, 0xfa,
}))
assert.NoError(t, v.Validate("9D2C8507-5F9D-4CB0-A098-2E307B39DC91"))
assert.NoError(t, v.Validate([]byte{
0x7d, 0x44, 0x48, 0x40,
0x9d, 0xc0,
0x11, 0xd1,
0xb2, 0x45,
0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2,
}))
}
func BenchmarkUUIDValidatorString(b *testing.B) {
v := NewUUIDValidator()
for i := 0; i < b.N; i++ {
v.Validate("9D2C8507-5F9D-4CB0-A098-2E307B39DC91")
}
}
func BenchmarkUUIDValidatorBytes(b *testing.B) {
v := NewUUIDValidator()
for i := 0; i < b.N; i++ {
v.Validate([]byte{
0x7d, 0x44, 0x48, 0x40,
0x9d, 0xc0,
0x11, 0xd1,
0xb2, 0x45,
0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2,
})
}
}