forked from samuel/go-zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 129
/
util_test.go
53 lines (49 loc) · 1.4 KB
/
util_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
package zk
import "testing"
func TestFormatServers(t *testing.T) {
t.Parallel()
servers := []string{"127.0.0.1:2181", "127.0.0.42", "127.0.42.1:8811"}
r := []string{"127.0.0.1:2181", "127.0.0.42:2181", "127.0.42.1:8811"}
for i, s := range FormatServers(servers) {
if s != r[i] {
t.Errorf("%v should equal %v", s, r[i])
}
}
}
func TestValidatePath(t *testing.T) {
tt := []struct {
path string
seq bool
valid bool
}{
{"/this is / a valid/path", false, true},
{"/", false, true},
{"", false, false},
{"not/valid", false, false},
{"/ends/with/slash/", false, false},
{"/sequential/", true, true},
{"/test\u0000", false, false},
{"/double//slash", false, false},
{"/single/./period", false, false},
{"/double/../period", false, false},
{"/double/..ok/period", false, true},
{"/double/alsook../period", false, true},
{"/double/period/at/end/..", false, false},
{"/name/with.period", false, true},
{"/test\u0001", false, false},
{"/test\u001f", false, false},
{"/test\u0020", false, true}, // first allowable
{"/test\u007e", false, true}, // last valid ascii
{"/test\u007f", false, false},
{"/test\u009f", false, false},
{"/test\uf8ff", false, false},
{"/test\uffef", false, true},
{"/test\ufff0", false, false},
}
for _, tc := range tt {
err := validatePath(tc.path, tc.seq)
if (err != nil) == tc.valid {
t.Errorf("failed to validate path %q", tc.path)
}
}
}