|
5 | 5 | "io" |
6 | 6 | "os" |
7 | 7 | "strings" |
| 8 | + "time" |
8 | 9 |
|
9 | 10 | "github.com/cloudfoundry/storage-cli/dav/client" |
10 | 11 | "github.com/cloudfoundry/storage-cli/dav/client/clientfakes" |
@@ -124,4 +125,193 @@ var _ = Describe("Client", func() { |
124 | 125 | Expect(exists).To(BeFalse()) |
125 | 126 | }) |
126 | 127 | }) |
| 128 | + |
| 129 | + Context("Sign", func() { |
| 130 | + var expiry = 100 * time.Second |
| 131 | + |
| 132 | + It("returns a signed URL for action 'get'", func() { |
| 133 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 134 | + fakeStorageClient.SignReturns("https://the-signed-url", nil) |
| 135 | + |
| 136 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 137 | + url, err := davBlobstore.Sign("blob/path", "get", expiry) |
| 138 | + |
| 139 | + Expect(err).NotTo(HaveOccurred()) |
| 140 | + Expect(url).To(Equal("https://the-signed-url")) |
| 141 | + |
| 142 | + Expect(fakeStorageClient.SignCallCount()).To(Equal(1)) |
| 143 | + object, action, expiration := fakeStorageClient.SignArgsForCall(0) |
| 144 | + Expect(object).To(Equal("blob/path")) |
| 145 | + Expect(action).To(Equal("GET")) |
| 146 | + Expect(expiration).To(Equal(expiry)) |
| 147 | + }) |
| 148 | + |
| 149 | + It("returns a signed URL for action 'put'", func() { |
| 150 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 151 | + fakeStorageClient.SignReturns("https://the-signed-url", nil) |
| 152 | + |
| 153 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 154 | + url, err := davBlobstore.Sign("blob/path", "put", expiry) |
| 155 | + |
| 156 | + Expect(err).NotTo(HaveOccurred()) |
| 157 | + Expect(url).To(Equal("https://the-signed-url")) |
| 158 | + |
| 159 | + _, action, _ := fakeStorageClient.SignArgsForCall(0) |
| 160 | + Expect(action).To(Equal("PUT")) |
| 161 | + }) |
| 162 | + |
| 163 | + It("fails on unknown action without calling the storage client", func() { |
| 164 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 165 | + |
| 166 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 167 | + url, err := davBlobstore.Sign("blob/path", "unknown", expiry) |
| 168 | + |
| 169 | + Expect(err).To(HaveOccurred()) |
| 170 | + Expect(err.Error()).To(ContainSubstring("action not implemented")) |
| 171 | + Expect(url).To(Equal("")) |
| 172 | + Expect(fakeStorageClient.SignCallCount()).To(Equal(0)) |
| 173 | + }) |
| 174 | + |
| 175 | + It("propagates errors from the storage client", func() { |
| 176 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 177 | + fakeStorageClient.SignReturns("", fmt.Errorf("boom")) |
| 178 | + |
| 179 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 180 | + url, err := davBlobstore.Sign("blob/path", "get", expiry) |
| 181 | + |
| 182 | + Expect(err).To(HaveOccurred()) |
| 183 | + Expect(err.Error()).To(ContainSubstring("boom")) |
| 184 | + Expect(url).To(Equal("")) |
| 185 | + }) |
| 186 | + }) |
| 187 | + |
| 188 | + Context("Copy", func() { |
| 189 | + It("forwards source and destination to the storage client", func() { |
| 190 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 191 | + fakeStorageClient.CopyReturns(nil) |
| 192 | + |
| 193 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 194 | + err := davBlobstore.Copy("src/blob", "dst/blob") |
| 195 | + |
| 196 | + Expect(err).NotTo(HaveOccurred()) |
| 197 | + Expect(fakeStorageClient.CopyCallCount()).To(Equal(1)) |
| 198 | + |
| 199 | + src, dst := fakeStorageClient.CopyArgsForCall(0) |
| 200 | + Expect(src).To(Equal("src/blob")) |
| 201 | + Expect(dst).To(Equal("dst/blob")) |
| 202 | + }) |
| 203 | + |
| 204 | + It("propagates errors from the storage client", func() { |
| 205 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 206 | + fakeStorageClient.CopyReturns(fmt.Errorf("copy failed")) |
| 207 | + |
| 208 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 209 | + err := davBlobstore.Copy("src/blob", "dst/blob") |
| 210 | + |
| 211 | + Expect(err).To(HaveOccurred()) |
| 212 | + Expect(err.Error()).To(ContainSubstring("copy failed")) |
| 213 | + }) |
| 214 | + }) |
| 215 | + |
| 216 | + Context("List", func() { |
| 217 | + It("returns the blobs reported by the storage client", func() { |
| 218 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 219 | + fakeStorageClient.ListReturns([]string{"a/b/c", "a/b/d"}, nil) |
| 220 | + |
| 221 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 222 | + blobs, err := davBlobstore.List("a/b") |
| 223 | + |
| 224 | + Expect(err).NotTo(HaveOccurred()) |
| 225 | + Expect(blobs).To(ConsistOf("a/b/c", "a/b/d")) |
| 226 | + |
| 227 | + Expect(fakeStorageClient.ListCallCount()).To(Equal(1)) |
| 228 | + Expect(fakeStorageClient.ListArgsForCall(0)).To(Equal("a/b")) |
| 229 | + }) |
| 230 | + |
| 231 | + It("propagates errors from the storage client", func() { |
| 232 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 233 | + fakeStorageClient.ListReturns(nil, fmt.Errorf("list failed")) |
| 234 | + |
| 235 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 236 | + blobs, err := davBlobstore.List("any/prefix") |
| 237 | + |
| 238 | + Expect(err).To(HaveOccurred()) |
| 239 | + Expect(err.Error()).To(ContainSubstring("list failed")) |
| 240 | + Expect(blobs).To(BeNil()) |
| 241 | + }) |
| 242 | + }) |
| 243 | + |
| 244 | + Context("DeleteRecursive", func() { |
| 245 | + It("forwards the prefix to the storage client", func() { |
| 246 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 247 | + fakeStorageClient.DeleteRecursiveReturns(nil) |
| 248 | + |
| 249 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 250 | + err := davBlobstore.DeleteRecursive("some/prefix") |
| 251 | + |
| 252 | + Expect(err).NotTo(HaveOccurred()) |
| 253 | + Expect(fakeStorageClient.DeleteRecursiveCallCount()).To(Equal(1)) |
| 254 | + Expect(fakeStorageClient.DeleteRecursiveArgsForCall(0)).To(Equal("some/prefix")) |
| 255 | + }) |
| 256 | + |
| 257 | + It("propagates errors from the storage client", func() { |
| 258 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 259 | + fakeStorageClient.DeleteRecursiveReturns(fmt.Errorf("recursive delete failed")) |
| 260 | + |
| 261 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 262 | + err := davBlobstore.DeleteRecursive("some/prefix") |
| 263 | + |
| 264 | + Expect(err).To(HaveOccurred()) |
| 265 | + Expect(err.Error()).To(ContainSubstring("recursive delete failed")) |
| 266 | + }) |
| 267 | + }) |
| 268 | + |
| 269 | + Context("Properties", func() { |
| 270 | + It("forwards the destination to the storage client", func() { |
| 271 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 272 | + fakeStorageClient.PropertiesReturns(nil) |
| 273 | + |
| 274 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 275 | + err := davBlobstore.Properties("blob/path") |
| 276 | + |
| 277 | + Expect(err).NotTo(HaveOccurred()) |
| 278 | + Expect(fakeStorageClient.PropertiesCallCount()).To(Equal(1)) |
| 279 | + Expect(fakeStorageClient.PropertiesArgsForCall(0)).To(Equal("blob/path")) |
| 280 | + }) |
| 281 | + |
| 282 | + It("propagates errors from the storage client", func() { |
| 283 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 284 | + fakeStorageClient.PropertiesReturns(fmt.Errorf("properties failed")) |
| 285 | + |
| 286 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 287 | + err := davBlobstore.Properties("blob/path") |
| 288 | + |
| 289 | + Expect(err).To(HaveOccurred()) |
| 290 | + Expect(err.Error()).To(ContainSubstring("properties failed")) |
| 291 | + }) |
| 292 | + }) |
| 293 | + |
| 294 | + Context("EnsureStorageExists", func() { |
| 295 | + It("delegates to the storage client", func() { |
| 296 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 297 | + fakeStorageClient.EnsureStorageExistsReturns(nil) |
| 298 | + |
| 299 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 300 | + err := davBlobstore.EnsureStorageExists() |
| 301 | + |
| 302 | + Expect(err).NotTo(HaveOccurred()) |
| 303 | + Expect(fakeStorageClient.EnsureStorageExistsCallCount()).To(Equal(1)) |
| 304 | + }) |
| 305 | + |
| 306 | + It("propagates errors from the storage client", func() { |
| 307 | + fakeStorageClient := &clientfakes.FakeStorageClient{} |
| 308 | + fakeStorageClient.EnsureStorageExistsReturns(fmt.Errorf("ensure failed")) |
| 309 | + |
| 310 | + davBlobstore := client.NewWithStorageClient(fakeStorageClient) |
| 311 | + err := davBlobstore.EnsureStorageExists() |
| 312 | + |
| 313 | + Expect(err).To(HaveOccurred()) |
| 314 | + Expect(err.Error()).To(ContainSubstring("ensure failed")) |
| 315 | + }) |
| 316 | + }) |
127 | 317 | }) |
0 commit comments