-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_test.go
94 lines (79 loc) · 1.58 KB
/
list_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
package client
import (
"encoding/json"
"github.com/coreos/etcd/clientv3"
. "gopkg.in/check.v1"
"strconv"
)
const (
TEST_LIST_KEY1 = "/list_dir1"
TEST_LIST_KEY2 = "/list_dir2"
TEST_LIST_COUNT = 5
)
type ListSuite struct{}
func (s *ListSuite) SetUpSuite(c *C) {
_, err := client.client.Put(client.ctx, TEST_ROOT_KEY+TEST_LIST_KEY1, client.dirValue)
if err != nil {
c.Error(err)
}
_, err = client.client.Put(client.ctx, TEST_ROOT_KEY+TEST_LIST_KEY2, client.dirValue)
if err != nil {
c.Error(err)
}
for i := 0; i < TEST_LIST_COUNT; i++ {
value := "value"
if i%2 == 0 {
value = client.dirValue
}
_, err = client.client.Put(client.ctx, TEST_ROOT_KEY+TEST_LIST_KEY2+"/"+strconv.Itoa(i), value)
if err != nil {
c.Error(err)
}
}
}
func (s *ListSuite) TearDownSuite(c *C) {
_, err := client.client.Delete(client.ctx, TEST_ROOT_KEY+TEST_LIST_KEY1, clientv3.WithPrefix())
if err != nil {
c.Error(err)
}
_, err = client.client.Delete(client.ctx, TEST_ROOT_KEY+TEST_LIST_KEY2, clientv3.WithPrefix())
if err != nil {
c.Error(err)
}
}
func (s *ListSuite) TestList1(c *C) {
_, err := client.List(TEST_LIST_KEY1 + "a")
c.Assert(
err,
Equals,
ErrorListKey,
)
}
func (s *ListSuite) TestList2(c *C) {
nodes, err := client.List(TEST_LIST_KEY1)
c.Assert(
err,
Equals,
nil,
)
c.Assert(
len(nodes),
Equals,
0,
)
}
func (s *ListSuite) TestList3(c *C) {
nodes, err := client.List(TEST_LIST_KEY2)
c.Assert(
err,
Equals,
nil,
)
c.Assert(
len(nodes),
Equals,
TEST_LIST_COUNT,
)
b, _ := json.MarshalIndent(nodes, "", " ")
c.Log(string(b))
}