-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_test.go
56 lines (47 loc) · 983 Bytes
/
create_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 client
import (
"github.com/coreos/etcd/clientv3"
. "gopkg.in/check.v1"
)
const (
TEST_CREATE_KEY = "/create_dir"
)
type CreateSuite struct{}
func (s *CreateSuite) TearDownTest(c *C) {
_, err := client.client.Delete(client.ctx, TEST_ROOT_KEY+TEST_CREATE_KEY, clientv3.WithPrefix())
if err != nil {
c.Error(err)
}
}
func (s *CreateSuite) TestCreate1(c *C) {
_, err := client.client.Put(client.ctx, TEST_ROOT_KEY+TEST_CREATE_KEY, "")
if err != nil {
c.Error(err)
}
// key has existed
c.Assert(
client.Create(TEST_CREATE_KEY, ""),
Equals,
ErrorPutKey,
)
}
func (s *CreateSuite) TestCreate2(c *C) {
_, err := client.client.Put(client.ctx, TEST_ROOT_KEY+TEST_CREATE_KEY, "")
if err != nil {
c.Error(err)
}
// parentKey is directory
c.Assert(
client.Create(TEST_CREATE_KEY+"/abc", ""),
Equals,
ErrorPutKey,
)
}
func (s *CreateSuite) TestCreate3(c *C) {
// success
c.Assert(
client.Create(TEST_CREATE_KEY, ""),
Equals,
nil,
)
}