1 package storage
2
3
4
5
6 import chk "gopkg.in/check.v1"
7
8 type LeaseBlobSuite struct{}
9
10 var _ = chk.Suite(&LeaseBlobSuite{})
11
12 func (s *LeaseBlobSuite) TestAcquireLeaseWithNoProposedLeaseID(c *chk.C) {
13 cli := getBlobClient(c)
14 rec := cli.client.appendRecorder(c)
15 defer rec.Stop()
16
17 cnt := cli.GetContainerReference(containerName(c))
18 b := cnt.GetBlobReference(blobName(c))
19 c.Assert(cnt.Create(nil), chk.IsNil)
20 defer cnt.Delete(nil)
21
22 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
23
24 _, err := b.AcquireLease(30, "", nil)
25 c.Assert(err, chk.IsNil)
26 }
27
28 func (s *LeaseBlobSuite) TestAcquireLeaseWithProposedLeaseID(c *chk.C) {
29 cli := getBlobClient(c)
30 rec := cli.client.appendRecorder(c)
31 defer rec.Stop()
32
33 cnt := cli.GetContainerReference(containerName(c))
34 b := cnt.GetBlobReference(blobName(c))
35 c.Assert(cnt.Create(nil), chk.IsNil)
36 defer cnt.Delete(nil)
37
38 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
39
40 proposedLeaseID := "dfe6dde8-68d5-4910-9248-c97c61768fea"
41 leaseID, err := b.AcquireLease(30, proposedLeaseID, nil)
42 c.Assert(err, chk.IsNil)
43 c.Assert(leaseID, chk.Equals, proposedLeaseID)
44 }
45
46 func (s *LeaseBlobSuite) TestAcquireLeaseWithBadProposedLeaseID(c *chk.C) {
47 cli := getBlobClient(c)
48 rec := cli.client.appendRecorder(c)
49 defer rec.Stop()
50
51 cnt := cli.GetContainerReference(containerName(c))
52 b := cnt.GetBlobReference(blobName(c))
53 c.Assert(cnt.Create(nil), chk.IsNil)
54 defer cnt.Delete(nil)
55
56 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
57
58 proposedLeaseID := "badbadbad"
59 _, err := b.AcquireLease(30, proposedLeaseID, nil)
60 c.Assert(err, chk.NotNil)
61 }
62
63 func (s *LeaseBlobSuite) TestAcquireInfiniteLease(c *chk.C) {
64 cli := getBlobClient(c)
65 rec := cli.client.appendRecorder(c)
66 defer rec.Stop()
67
68 cnt := cli.GetContainerReference(containerName(c))
69 b := cnt.GetBlobReference(blobName(c))
70 c.Assert(cnt.Create(nil), chk.IsNil)
71 defer cnt.Delete(nil)
72
73 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
74
75 proposedLeaseID := "dfe6dde8-68d5-4910-9248-c97c61768fea"
76 _, err := b.AcquireLease(-1, proposedLeaseID, nil)
77 c.Assert(err, chk.IsNil)
78 }
79
80 func (s *LeaseBlobSuite) TestRenewLeaseSuccessful(c *chk.C) {
81 cli := getBlobClient(c)
82 rec := cli.client.appendRecorder(c)
83 defer rec.Stop()
84
85 cnt := cli.GetContainerReference(containerName(c))
86 b := cnt.GetBlobReference(blobName(c))
87 c.Assert(cnt.Create(nil), chk.IsNil)
88 defer cnt.Delete(nil)
89
90 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
91
92 proposedLeaseID := "dfe6dde8-68d5-4910-9248-c97c61768fea"
93 leaseID, err := b.AcquireLease(30, proposedLeaseID, nil)
94 c.Assert(err, chk.IsNil)
95
96 err = b.RenewLease(leaseID, nil)
97 c.Assert(err, chk.IsNil)
98 }
99
100 func (s *LeaseBlobSuite) TestRenewLeaseAgainstNoCurrentLease(c *chk.C) {
101 cli := getBlobClient(c)
102 rec := cli.client.appendRecorder(c)
103 defer rec.Stop()
104
105 cnt := cli.GetContainerReference(containerName(c))
106 b := cnt.GetBlobReference(blobName(c))
107 c.Assert(cnt.Create(nil), chk.IsNil)
108 defer cnt.Delete(nil)
109
110 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
111
112 badLeaseID := "Golang rocks on Azure"
113 err := b.RenewLease(badLeaseID, nil)
114 c.Assert(err, chk.NotNil)
115 }
116
117 func (s *LeaseBlobSuite) TestChangeLeaseSuccessful(c *chk.C) {
118 cli := getBlobClient(c)
119 rec := cli.client.appendRecorder(c)
120 defer rec.Stop()
121
122 cnt := cli.GetContainerReference(containerName(c))
123 b := cnt.GetBlobReference(blobName(c))
124 c.Assert(cnt.Create(nil), chk.IsNil)
125 defer cnt.Delete(nil)
126
127 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
128 proposedLeaseID := "dfe6dde8-68d5-4910-9248-c97c61768fea"
129 leaseID, err := b.AcquireLease(30, proposedLeaseID, nil)
130 c.Assert(err, chk.IsNil)
131
132 newProposedLeaseID := "dfe6dde8-68d5-4910-9248-c97c61768fbb"
133 newLeaseID, err := b.ChangeLease(leaseID, newProposedLeaseID, nil)
134 c.Assert(err, chk.IsNil)
135 c.Assert(newLeaseID, chk.Equals, newProposedLeaseID)
136 }
137
138 func (s *LeaseBlobSuite) TestChangeLeaseNotSuccessfulbadProposedLeaseID(c *chk.C) {
139 cli := getBlobClient(c)
140 rec := cli.client.appendRecorder(c)
141 defer rec.Stop()
142
143 cnt := cli.GetContainerReference(containerName(c))
144 b := cnt.GetBlobReference(blobName(c))
145 c.Assert(cnt.Create(nil), chk.IsNil)
146 defer cnt.Delete(nil)
147
148 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
149 proposedLeaseID := "dfe6dde8-68d5-4910-9248-c97c61768fea"
150 leaseID, err := b.AcquireLease(30, proposedLeaseID, nil)
151 c.Assert(err, chk.IsNil)
152
153 newProposedLeaseID := "1f812371-a41d-49e6-b123-f4b542e"
154 _, err = b.ChangeLease(leaseID, newProposedLeaseID, nil)
155 c.Assert(err, chk.NotNil)
156 }
157
158 func (s *LeaseBlobSuite) TestReleaseLeaseSuccessful(c *chk.C) {
159 cli := getBlobClient(c)
160 rec := cli.client.appendRecorder(c)
161 defer rec.Stop()
162
163 cnt := cli.GetContainerReference(containerName(c))
164 b := cnt.GetBlobReference(blobName(c))
165 c.Assert(cnt.Create(nil), chk.IsNil)
166 defer cnt.Delete(nil)
167
168 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
169 proposedLeaseID := "dfe6dde8-68d5-4910-9248-c97c61768fea"
170 leaseID, err := b.AcquireLease(30, proposedLeaseID, nil)
171 c.Assert(err, chk.IsNil)
172
173 err = b.ReleaseLease(leaseID, nil)
174 c.Assert(err, chk.IsNil)
175 }
176
177 func (s *LeaseBlobSuite) TestReleaseLeaseNotSuccessfulBadLeaseID(c *chk.C) {
178 cli := getBlobClient(c)
179 rec := cli.client.appendRecorder(c)
180 defer rec.Stop()
181
182 cnt := cli.GetContainerReference(containerName(c))
183 b := cnt.GetBlobReference(blobName(c))
184 c.Assert(cnt.Create(nil), chk.IsNil)
185 defer cnt.Delete(nil)
186
187 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
188 proposedLeaseID := "dfe6dde8-68d5-4910-9248-c97c61768fea"
189 _, err := b.AcquireLease(30, proposedLeaseID, nil)
190 c.Assert(err, chk.IsNil)
191
192 err = b.ReleaseLease("badleaseid", nil)
193 c.Assert(err, chk.NotNil)
194 }
195
196 func (s *LeaseBlobSuite) TestBreakLeaseSuccessful(c *chk.C) {
197 cli := getBlobClient(c)
198 rec := cli.client.appendRecorder(c)
199 defer rec.Stop()
200
201 cnt := cli.GetContainerReference(containerName(c))
202 b := cnt.GetBlobReference(blobName(c))
203 c.Assert(cnt.Create(nil), chk.IsNil)
204 defer cnt.Delete(nil)
205
206 c.Assert(b.putSingleBlockBlob([]byte("Hello!")), chk.IsNil)
207
208 proposedLeaseID := "dfe6dde8-68d5-4910-9248-c97c61768fea"
209 _, err := b.AcquireLease(30, proposedLeaseID, nil)
210 c.Assert(err, chk.IsNil)
211
212 _, err = b.BreakLease(nil)
213 c.Assert(err, chk.IsNil)
214 }
215
View as plain text