-
Notifications
You must be signed in to change notification settings - Fork 428
/
Copy pathmock_client_test.go
72 lines (55 loc) · 1.62 KB
/
mock_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
package memcache
import (
"bytes"
. "gopkg.in/check.v1"
. "github.com/dropbox/godropbox/gocheck2"
)
type MockClientSuite struct {
client *MockClient
}
var _ = Suite(&MockClientSuite{})
func (s *MockClientSuite) SetUpTest(c *C) {
s.client = NewMockClient().(*MockClient)
}
func (s *MockClientSuite) TestAddSimple(c *C) {
item := createTestItem()
resp := s.client.Add(item)
c.Assert(resp.Error(), IsNil)
c.Assert(resp.Key(), Equals, item.Key)
c.Assert(resp.DataVersionId(), Equals, uint64(1))
gresp := s.client.Get(item.Key)
c.Assert(gresp.Error(), IsNil)
c.Assert(bytes.Equal(gresp.Value(), item.Value), IsTrue)
c.Assert(gresp.DataVersionId(), Equals, uint64(1))
}
func (s *MockClientSuite) TestAddExists(c *C) {
item := createTestItem()
resp := s.client.Add(item)
resp = s.client.Add(item)
c.Assert(resp.Error(), Not(IsNil))
c.Assert(resp.Status(), Equals, StatusItemNotStored)
}
func (s *MockClientSuite) TestAddMultiSimple(c *C) {
item1 := createTestItem()
item2 := createTestItem()
item2.Key = "foo"
items := []*Item{item1, item2}
resps := s.client.AddMulti(items)
c.Assert(resps, HasLen, 2)
for i := 0; i < 2; i++ {
item := items[i]
resp := resps[i]
c.Assert(resp.Error(), IsNil)
c.Assert(resp.Key(), Equals, item.Key)
c.Assert(resp.DataVersionId(), Equals, uint64(1+i))
gresp := s.client.Get(item.Key)
c.Assert(gresp.Error(), IsNil)
c.Assert(bytes.Equal(gresp.Value(), item.Value), IsTrue)
c.Assert(gresp.DataVersionId(), Equals, uint64(1+i))
}
}
func (s *MockClientSuite) TestAddMultiEmpty(c *C) {
items := make([]*Item, 0)
resps := s.client.AddMulti(items)
c.Assert(resps, HasLen, 0)
}