forked from wvanbergen/kazoo-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkazoo_test.go
56 lines (47 loc) · 1.53 KB
/
kazoo_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
package kazoo
import (
"testing"
)
func TestBuildConnectionString(t *testing.T) {
nodes := []string{"zk1:2181", "zk2:2181", "zk3:2181"}
if str := BuildConnectionString(nodes); str != "zk1:2181,zk2:2181,zk3:2181" {
t.Errorf("The connection string was not built correctly: %s", str)
}
if str := BuildConnectionStringWithChroot(nodes, "/chroot"); str != "zk1:2181,zk2:2181,zk3:2181/chroot" {
t.Errorf("The connection string was not built correctly: %s", str)
}
}
func TestParseConnectionString(t *testing.T) {
var (
nodes []string
chroot string
)
nodes, chroot = ParseConnectionString("zookeeper/chroot")
if len(nodes) != 1 || nodes[0] != "zookeeper" {
t.Error("Parsed nodes incorrectly:", nodes)
}
if chroot != "/chroot" {
t.Error("Parsed chroot incorrectly:", chroot)
}
nodes, chroot = ParseConnectionString("zk1:2181,zk2:2181,zk3:2181")
if len(nodes) != 3 || nodes[0] != "zk1:2181" || nodes[1] != "zk2:2181" || nodes[2] != "zk3:2181" {
t.Error("Parsed nodes incorrectly:", nodes)
}
if chroot != "" {
t.Error("Parsed chroot incorrectly:", chroot)
}
nodes, chroot = ParseConnectionString("zk1:2181,zk2/nested/chroot")
if len(nodes) != 2 || nodes[0] != "zk1:2181" || nodes[1] != "zk2" {
t.Error("Parsed nodes incorrectly:", nodes)
}
if chroot != "/nested/chroot" {
t.Error("Parsed chroot incorrectly:", chroot)
}
nodes, chroot = ParseConnectionString("")
if len(nodes) != 1 || nodes[0] != "" {
t.Error("Parsed nodes incorrectly:", nodes)
}
if chroot != "" {
t.Error("Parsed chroot incorrectly:", chroot)
}
}