-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient_test.go
84 lines (70 loc) · 1.98 KB
/
client_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
package ezk
import (
"fmt"
cv "github.com/glycerine/goconvey/convey"
zook "github.com/samuel/go-zookeeper/zk"
"testing"
"time"
)
func Test001ClientRetryGetsDefault(t *testing.T) {
cv.Convey("Given that we don't configure a Retry function, we should get the DefaultRetry function in our ClientConfig", t, func() {
cli := NewClient(ClientConfig{})
cv.So(cli.Cfg.Retry, cv.ShouldEqual, DefaultRetry)
})
}
// In the example code, the goal is to set
// the value newURL into the node /chroot/service-name/config/server-url-list
func ExampleClient() {
newURL := "http://my-new-url.org:343/hello/enhanced-zookeeper-client"
base := "/chroot/"
path := "service-name/config/server-url-list"
zkCfg := ClientConfig{
Servers: []string{"127.0.0.1:2181"},
Acl: zook.WorldACL(zook.PermAll),
Chroot: base,
SessionTimeout: 10 * time.Second,
}
zk := NewClient(zkCfg)
err := zk.Connect()
if err != nil {
panic(err)
}
defer zk.Close()
err = zk.CreateDir(path, nil)
if err != nil {
panic(err)
}
err = zk.DeleteNode(path) // delete any old value
if err != nil {
panic(err)
}
err = zk.CreateNode(path)
if err != nil {
panic(err)
}
_, err = zk.Set(path, []byte(newURL), -1)
if err != nil {
panic(err)
}
}
func Test002RemoveChroot(t *testing.T) {
cv.Convey("Given an absolute Chrooted path, the RemoveChoot() function should return the relative path without the Chroot prefix", t, func() {
// map from input to expected output
m := map[string]string{
"/mybase/myservice/config": "myservice/config",
"/myroot/alist": "alist",
"/hello/": "",
"/poorlyFormedChrootPrefix": "",
"/properlyFormedChrootPrefix/": "",
"relative/path/unchanged": "relative/path/unchanged",
"/": "",
"//": "",
"abc": "abc",
"a/b/c/d/e/": "a/b/c/d/e/",
}
for k, v := range m {
fmt.Printf("\n checking '%s' -> '%s'\n", k, v)
cv.So(RemoveChroot(k), cv.ShouldEqual, v)
}
})
}