-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules_test.go
106 lines (99 loc) · 1.69 KB
/
rules_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package namegrind
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestValidateName(t *testing.T) {
tests := []struct {
name string
input string
errStr string
}{
{
"cannot have zero length",
"",
"must have nonzero length",
},
{
"cannot be over MaxNameLen characters",
"longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong",
"over maximum length",
},
{
"cannot start with a hyphen",
"-startswithhyphen",
"cannot start with a hyphen",
},
{
"cannot end with a hyphen",
"endwithhyphen-",
"cannot end with a hyphen",
},
{
"cannot have consecutive hyphens",
"consecutive--hyphens",
"cannot contain consecutive hyphens",
},
{
"cannot contain unicode",
"我叫鸣字",
"invalid character",
},
{
"can only contain certain characters",
"hello!",
"invalid character",
},
{
"can only contain certain characters",
"hello@",
"invalid character",
},
{
"works with valid names",
"heres-a-valid-name",
"",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.errStr == "" {
require.Nil(t, ValidateName(tt.input))
return
}
err := ValidateName(tt.input)
require.Error(t, err)
require.Contains(t, err.Error(), tt.errStr)
})
}
}
func TestRollout(t *testing.T) {
in := []struct {
name string
week int
height int
}{
{
"honk",
13,
15120,
},
{
"beep",
15,
17136,
},
{
"farb",
36,
38304,
},
}
for _, tt := range in {
hash, err := HashName(tt.name)
require.NoError(t, err)
height, week := Rollout(hash)
require.Equal(t, tt.height, height)
require.Equal(t, tt.week, week)
}
}