-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathput_test.go
62 lines (52 loc) · 1.05 KB
/
put_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
package client
import (
"github.com/coreos/etcd/clientv3"
. "gopkg.in/check.v1"
)
const (
TEST_PUT_KEY = "/put_dir"
)
type PutSuite struct{}
func (s *PutSuite) TearDownTest(c *C) {
_, err := client.client.Delete(client.ctx, TEST_ROOT_KEY+TEST_PUT_KEY, clientv3.WithPrefix())
if err != nil {
c.Error(err)
}
}
func (s *PutSuite) TestPut1(c *C) {
_, err := client.client.Put(client.ctx, TEST_ROOT_KEY+TEST_PUT_KEY, client.dirValue)
if err != nil {
c.Error(err)
}
// key is directory
c.Assert(
client.Put(TEST_PUT_KEY, ""),
Equals,
ErrorPutKey,
)
}
func (s *PutSuite) TestPut2(c *C) {
_, err := client.client.Put(client.ctx, TEST_ROOT_KEY+TEST_PUT_KEY, "")
if err != nil {
c.Error(err)
}
// parentKey is not a directory
c.Assert(
client.Put(TEST_PUT_KEY+"/abc", ""),
Equals,
ErrorPutKey,
)
}
func (s *PutSuite) TestPut3(c *C) {
// has been set
_, err := client.client.Put(client.ctx, TEST_ROOT_KEY+TEST_PUT_KEY, "")
if err != nil {
c.Error(err)
}
// success
c.Assert(
client.Put(TEST_PUT_KEY, ""),
Equals,
nil,
)
}