-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
90 lines (69 loc) · 1.75 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
85
86
87
88
89
90
package client
import (
"testing"
"github.com/coreos/etcd/clientv3"
. "gopkg.in/check.v1"
)
const (
TEST_ETCD_ADDR = "127.0.0.1:2379"
TEST_ROOT_KEY = "e3ch_test"
)
func Test(t *testing.T) { TestingT(t) }
var (
client *EtcdHRCHYClient
)
func init() {
clt, err := clientv3.New(clientv3.Config{Endpoints: []string{TEST_ETCD_ADDR}})
if err != nil {
panic(err)
}
client, err = New(clt, TEST_ROOT_KEY)
if err != nil {
panic(err)
}
err = client.FormatRootKey()
if err != nil {
panic(err)
}
Suite(&ClientSuite{})
Suite(&PutSuite{})
Suite(&GetSuite{})
Suite(&ListSuite{})
Suite(&DeleteSuite{})
Suite(&CreateSuite{})
Suite(&AuthSuite{})
}
type ClientSuite struct{}
func (s *ClientSuite) TestNewClient(c *C) {
clt, err := clientv3.New(clientv3.Config{Endpoints: []string{TEST_ETCD_ADDR}})
if err != nil {
c.Error(err)
}
_, err = New(clt, "")
c.Assert(err, Equals, ErrorInvalidRootKey)
_, err = New(clt, "/")
c.Assert(err, Equals, ErrorInvalidRootKey)
_, err = New(clt, "abc/")
c.Assert(err, Equals, ErrorInvalidRootKey)
_, err = New(clt, "abc")
c.Assert(err, Equals, nil)
}
func (s *ClientSuite) TestEnsureKey(c *C) {
clt, err := clientv3.New(clientv3.Config{Endpoints: []string{TEST_ETCD_ADDR}})
if err != nil {
c.Error(err)
}
client, err := New(clt, "abc")
c.Assert(err, Equals, nil)
key, parentKey, err := client.ensureKey("abd")
c.Assert(err, Equals, ErrorInvalidKey)
key, parentKey, _ = client.ensureKey("/")
c.Assert(key, Equals, "abc")
c.Assert(parentKey, Equals, "abc")
key, parentKey, _ = client.ensureKey("/def")
c.Assert(key, Equals, "abc/def")
c.Assert(parentKey, Equals, "abc")
key, parentKey, _ = client.ensureKey("/def/ghi")
c.Assert(key, Equals, "abc/def/ghi")
c.Assert(parentKey, Equals, "abc/def")
}