github.com/anuvu/zot@v1.3.4/pkg/storage/s3/s3_test.go (about) 1 package s3_test 2 3 import ( 4 "bytes" 5 "context" 6 _ "crypto/sha256" 7 "errors" 8 "fmt" 9 "io" 10 "io/ioutil" 11 "os" 12 "path" 13 "strings" 14 "time" 15 16 godigest "github.com/opencontainers/go-digest" 17 //"strings" 18 19 "testing" 20 21 zerr "github.com/anuvu/zot/errors" 22 "github.com/anuvu/zot/pkg/extensions/monitoring" 23 "github.com/anuvu/zot/pkg/log" 24 "github.com/anuvu/zot/pkg/storage" 25 "github.com/anuvu/zot/pkg/storage/s3" 26 guuid "github.com/gofrs/uuid" 27 "github.com/rs/zerolog" 28 . "github.com/smartystreets/goconvey/convey" 29 30 // Add s3 support 31 storageDriver "github.com/docker/distribution/registry/storage/driver" 32 "github.com/docker/distribution/registry/storage/driver/factory" 33 _ "github.com/docker/distribution/registry/storage/driver/s3-aws" 34 35 "gopkg.in/resty.v1" 36 ) 37 38 // nolint: gochecknoglobals 39 var ( 40 testImage = "test" 41 fileWriterSize = 12 42 fileInfoSize = 10 43 errorText = "new s3 error" 44 errS3 = errors.New(errorText) 45 ) 46 47 func cleanupStorage(store storageDriver.StorageDriver, name string) { 48 _ = store.Delete(context.Background(), name) 49 } 50 51 func skipIt(t *testing.T) { 52 if os.Getenv("S3MOCK_ENDPOINT") == "" { 53 t.Skip("Skipping testing without AWS S3 mock server") 54 } 55 } 56 57 func createMockStorage(rootDir string, store storageDriver.StorageDriver) storage.ImageStore { 58 log := log.Logger{Logger: zerolog.New(os.Stdout)} 59 metrics := monitoring.NewMetricsServer(false, log) 60 il := s3.NewImageStore(rootDir, false, false, log, metrics, store) 61 62 return il 63 } 64 65 func createObjectsStore(rootDir string) (storageDriver.StorageDriver, storage.ImageStore, error) { 66 bucket := "zot-storage-test" 67 endpoint := os.Getenv("S3MOCK_ENDPOINT") 68 storageDriverParams := map[string]interface{}{ 69 "rootDir": rootDir, 70 "name": "s3", 71 "region": "us-east-2", 72 "bucket": bucket, 73 "regionendpoint": endpoint, 74 "secure": false, 75 "skipverify": false, 76 } 77 78 storeName := fmt.Sprintf("%v", storageDriverParams["name"]) 79 80 store, err := factory.Create(storeName, storageDriverParams) 81 if err != nil { 82 panic(err) 83 } 84 85 // create bucket if it doesn't exists 86 _, err = resty.R().Put("http://" + endpoint + "/" + bucket) 87 if err != nil { 88 panic(err) 89 } 90 91 log := log.Logger{Logger: zerolog.New(os.Stdout)} 92 metrics := monitoring.NewMetricsServer(false, log) 93 il := s3.NewImageStore(rootDir, false, false, log, metrics, store) 94 95 return store, il, err 96 } 97 98 type FileInfoMock struct { 99 isDirFn func() bool 100 } 101 102 func (f *FileInfoMock) Path() string { 103 return "" 104 } 105 106 func (f *FileInfoMock) Size() int64 { 107 return int64(fileInfoSize) 108 } 109 110 func (f *FileInfoMock) ModTime() time.Time { 111 return time.Now() 112 } 113 114 func (f *FileInfoMock) IsDir() bool { 115 if f != nil && f.isDirFn != nil { 116 return f.isDirFn() 117 } 118 119 return true 120 } 121 122 type FileWriterMock struct { 123 writeFn func([]byte) (int, error) 124 cancelFn func() error 125 commitFn func() error 126 closeFn func() error 127 } 128 129 func (f *FileWriterMock) Size() int64 { 130 return int64(fileWriterSize) 131 } 132 133 func (f *FileWriterMock) Cancel() error { 134 if f != nil && f.cancelFn != nil { 135 return f.cancelFn() 136 } 137 138 return nil 139 } 140 141 func (f *FileWriterMock) Commit() error { 142 if f != nil && f.commitFn != nil { 143 return f.commitFn() 144 } 145 146 return nil 147 } 148 149 func (f *FileWriterMock) Write(p []byte) (int, error) { 150 if f != nil && f.writeFn != nil { 151 return f.writeFn(p) 152 } 153 154 return 10, nil 155 } 156 157 func (f *FileWriterMock) Close() error { 158 if f != nil && f.closeFn != nil { 159 return f.closeFn() 160 } 161 162 return nil 163 } 164 165 type StorageDriverMock struct { 166 nameFn func() string 167 getContentFn func(ctx context.Context, path string) ([]byte, error) 168 putContentFn func(ctx context.Context, path string, content []byte) error 169 readerFn func(ctx context.Context, path string, offset int64) (io.ReadCloser, error) 170 writerFn func(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) 171 statFn func(ctx context.Context, path string) (storageDriver.FileInfo, error) 172 listFn func(ctx context.Context, path string) ([]string, error) 173 moveFn func(ctx context.Context, sourcePath string, destPath string) error 174 deleteFn func(ctx context.Context, path string) error 175 walkFn func(ctx context.Context, path string, f storageDriver.WalkFn) error 176 } 177 178 func (s *StorageDriverMock) Name() string { 179 if s != nil && s.nameFn != nil { 180 return s.nameFn() 181 } 182 183 return "" 184 } 185 186 func (s *StorageDriverMock) GetContent(ctx context.Context, path string) ([]byte, error) { 187 if s != nil && s.getContentFn != nil { 188 return s.getContentFn(ctx, path) 189 } 190 191 return []byte{}, nil 192 } 193 194 func (s *StorageDriverMock) PutContent(ctx context.Context, path string, content []byte) error { 195 if s != nil && s.putContentFn != nil { 196 return s.putContentFn(ctx, path, content) 197 } 198 199 return nil 200 } 201 202 func (s *StorageDriverMock) Reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error) { 203 if s != nil && s.readerFn != nil { 204 return s.readerFn(ctx, path, offset) 205 } 206 207 return ioutil.NopCloser(strings.NewReader("")), nil 208 } 209 210 func (s *StorageDriverMock) Writer(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) { 211 if s != nil && s.writerFn != nil { 212 return s.writerFn(ctx, path, append) 213 } 214 215 return &FileWriterMock{}, nil 216 } 217 218 func (s *StorageDriverMock) Stat(ctx context.Context, path string) (storageDriver.FileInfo, error) { 219 if s != nil && s.statFn != nil { 220 return s.statFn(ctx, path) 221 } 222 223 return &FileInfoMock{}, nil 224 } 225 226 func (s *StorageDriverMock) List(ctx context.Context, path string) ([]string, error) { 227 if s != nil && s.listFn != nil { 228 return s.listFn(ctx, path) 229 } 230 231 return []string{"a"}, nil 232 } 233 234 func (s *StorageDriverMock) Move(ctx context.Context, sourcePath string, destPath string) error { 235 if s != nil && s.moveFn != nil { 236 return s.moveFn(ctx, sourcePath, destPath) 237 } 238 239 return nil 240 } 241 242 func (s *StorageDriverMock) Delete(ctx context.Context, path string) error { 243 if s != nil && s.deleteFn != nil { 244 return s.deleteFn(ctx, path) 245 } 246 247 return nil 248 } 249 250 func (s *StorageDriverMock) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) { 251 return "", nil 252 } 253 254 func (s *StorageDriverMock) Walk(ctx context.Context, path string, f storageDriver.WalkFn) error { 255 if s != nil && s.walkFn != nil { 256 return s.walkFn(ctx, path, f) 257 } 258 259 return nil 260 } 261 262 func TestNegativeCasesObjectsStorage(t *testing.T) { 263 skipIt(t) 264 265 uuid, err := guuid.NewV4() 266 if err != nil { 267 panic(err) 268 } 269 270 testDir := path.Join("/oci-repo-test", uuid.String()) 271 272 store, il, _ := createObjectsStore(testDir) 273 defer cleanupStorage(store, testDir) 274 275 Convey("Invalid validate repo", t, func(c C) { 276 So(il, ShouldNotBeNil) 277 So(il.InitRepo(testImage), ShouldBeNil) 278 objects, err := store.List(context.Background(), path.Join(il.RootDir(), testImage)) 279 So(err, ShouldBeNil) 280 for _, object := range objects { 281 t.Logf("Removing object: %s", object) 282 err := store.Delete(context.Background(), object) 283 So(err, ShouldBeNil) 284 } 285 _, err = il.ValidateRepo(testImage) 286 So(err, ShouldNotBeNil) 287 _, err = il.GetRepositories() 288 So(err, ShouldBeNil) 289 }) 290 291 Convey("Invalid get image tags", t, func(c C) { 292 store, il, err := createObjectsStore(testDir) 293 defer cleanupStorage(store, testDir) 294 So(err, ShouldBeNil) 295 So(il.InitRepo(testImage), ShouldBeNil) 296 297 So(store.Move(context.Background(), path.Join(testDir, testImage, "index.json"), 298 path.Join(testDir, testImage, "blobs")), ShouldBeNil) 299 ok, _ := il.ValidateRepo(testImage) 300 So(ok, ShouldBeFalse) 301 _, err = il.GetImageTags(testImage) 302 So(err, ShouldNotBeNil) 303 304 So(store.Delete(context.Background(), path.Join(testDir, testImage)), ShouldBeNil) 305 306 So(il.InitRepo(testImage), ShouldBeNil) 307 So(store.PutContent(context.Background(), path.Join(testDir, testImage, "index.json"), []byte{}), ShouldBeNil) 308 _, err = il.GetImageTags(testImage) 309 So(err, ShouldNotBeNil) 310 }) 311 312 Convey("Invalid get image manifest", t, func(c C) { 313 store, il, err := createObjectsStore(testDir) 314 defer cleanupStorage(store, testDir) 315 So(err, ShouldBeNil) 316 So(il, ShouldNotBeNil) 317 So(il.InitRepo(testImage), ShouldBeNil) 318 So(store.Delete(context.Background(), path.Join(testDir, testImage, "index.json")), ShouldBeNil) 319 _, _, _, err = il.GetImageManifest(testImage, "") 320 So(err, ShouldNotBeNil) 321 So(store.Delete(context.Background(), path.Join(testDir, testImage)), ShouldBeNil) 322 So(il.InitRepo(testImage), ShouldBeNil) 323 So(store.PutContent(context.Background(), path.Join(testDir, testImage, "index.json"), []byte{}), ShouldBeNil) 324 _, _, _, err = il.GetImageManifest(testImage, "") 325 So(err, ShouldNotBeNil) 326 }) 327 328 Convey("Invalid validate repo", t, func(c C) { 329 store, il, err := createObjectsStore(testDir) 330 defer cleanupStorage(store, testDir) 331 So(err, ShouldBeNil) 332 So(il, ShouldNotBeNil) 333 334 So(il.InitRepo(testImage), ShouldBeNil) 335 So(store.Delete(context.Background(), path.Join(testDir, testImage, "index.json")), ShouldBeNil) 336 _, err = il.ValidateRepo(testImage) 337 So(err, ShouldNotBeNil) 338 So(store.Delete(context.Background(), path.Join(testDir, testImage)), ShouldBeNil) 339 So(il.InitRepo(testImage), ShouldBeNil) 340 So(store.Move(context.Background(), path.Join(testDir, testImage, "index.json"), 341 path.Join(testDir, testImage, "_index.json")), ShouldBeNil) 342 ok, err := il.ValidateRepo(testImage) 343 So(err, ShouldBeNil) 344 So(ok, ShouldBeFalse) 345 }) 346 347 Convey("Invalid finish blob upload", t, func(c C) { 348 store, il, err := createObjectsStore(testDir) 349 defer cleanupStorage(store, testDir) 350 So(err, ShouldBeNil) 351 So(il, ShouldNotBeNil) 352 353 So(il.InitRepo(testImage), ShouldBeNil) 354 v, err := il.NewBlobUpload(testImage) 355 So(err, ShouldBeNil) 356 So(v, ShouldNotBeEmpty) 357 358 content := []byte("test-data1") 359 buf := bytes.NewBuffer(content) 360 l := buf.Len() 361 d := godigest.FromBytes(content) 362 363 b, err := il.PutBlobChunk(testImage, v, 0, int64(l), buf) 364 So(err, ShouldBeNil) 365 So(b, ShouldEqual, l) 366 367 src := il.BlobUploadPath(testImage, v) 368 fw, err := store.Writer(context.Background(), src, true) 369 So(err, ShouldBeNil) 370 371 _, err = fw.Write([]byte("another-chunk-of-data")) 372 So(err, ShouldBeNil) 373 374 err = fw.Close() 375 So(err, ShouldBeNil) 376 377 err = il.FinishBlobUpload(testImage, v, buf, d.String()) 378 So(err, ShouldNotBeNil) 379 }) 380 381 Convey("Test storage driver errors", t, func(c C) { 382 il = createMockStorage(testDir, &StorageDriverMock{ 383 listFn: func(ctx context.Context, path string) ([]string, error) { 384 return []string{testImage}, errS3 385 }, 386 moveFn: func(ctx context.Context, sourcePath, destPath string) error { 387 return errS3 388 }, 389 getContentFn: func(ctx context.Context, path string) ([]byte, error) { 390 return []byte{}, errS3 391 }, 392 putContentFn: func(ctx context.Context, path string, content []byte) error { 393 return errS3 394 }, 395 writerFn: func(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) { 396 return &FileWriterMock{}, errS3 397 }, 398 readerFn: func(ctx context.Context, path string, offset int64) (io.ReadCloser, error) { 399 return ioutil.NopCloser(strings.NewReader("")), errS3 400 }, 401 walkFn: func(ctx context.Context, path string, f storageDriver.WalkFn) error { 402 return errS3 403 }, 404 statFn: func(ctx context.Context, path string) (storageDriver.FileInfo, error) { 405 return &FileInfoMock{}, errS3 406 }, 407 deleteFn: func(ctx context.Context, path string) error { 408 return errS3 409 }, 410 }) 411 So(il, ShouldNotBeNil) 412 413 So(il.InitRepo(testImage), ShouldNotBeNil) 414 _, err := il.ValidateRepo(testImage) 415 So(err, ShouldNotBeNil) 416 417 v, err := il.NewBlobUpload(testImage) 418 So(err, ShouldNotBeNil) 419 420 content := []byte("test-data1") 421 buf := bytes.NewBuffer(content) 422 l := buf.Len() 423 d := godigest.FromBytes(content) 424 425 _, err = il.PutBlobChunk(testImage, v, 0, int64(l), buf) 426 So(err, ShouldNotBeNil) 427 428 err = il.FinishBlobUpload(testImage, v, buf, d.String()) 429 So(err, ShouldNotBeNil) 430 431 err = il.DeleteBlob(testImage, d.String()) 432 So(err, ShouldNotBeNil) 433 434 err = il.DeleteBlobUpload(testImage, v) 435 So(err, ShouldNotBeNil) 436 437 err = il.DeleteImageManifest(testImage, "1.0") 438 So(err, ShouldNotBeNil) 439 440 _, err = il.PutImageManifest(testImage, "1.0", "application/json", []byte{}) 441 So(err, ShouldNotBeNil) 442 443 _, err = il.PutBlobChunkStreamed(testImage, v, bytes.NewBuffer([]byte(testImage))) 444 So(err, ShouldNotBeNil) 445 446 _, _, err = il.FullBlobUpload(testImage, bytes.NewBuffer([]byte{}), "inexistent") 447 So(err, ShouldNotBeNil) 448 449 _, _, err = il.CheckBlob(testImage, d.String()) 450 So(err, ShouldNotBeNil) 451 }) 452 453 Convey("Test ValidateRepo", t, func(c C) { 454 il = createMockStorage(testDir, &StorageDriverMock{ 455 listFn: func(ctx context.Context, path string) ([]string, error) { 456 return []string{testImage, testImage}, errS3 457 }, 458 }) 459 _, err := il.ValidateRepo(testImage) 460 So(err, ShouldNotBeNil) 461 }) 462 463 Convey("Test ValidateRepo2", t, func(c C) { 464 il = createMockStorage(testDir, &StorageDriverMock{ 465 listFn: func(ctx context.Context, path string) ([]string, error) { 466 return []string{"test/test/oci-layout", "test/test/index.json"}, nil 467 }, 468 statFn: func(ctx context.Context, path string) (storageDriver.FileInfo, error) { 469 return &FileInfoMock{}, nil 470 }, 471 }) 472 _, err := il.ValidateRepo(testImage) 473 So(err, ShouldNotBeNil) 474 }) 475 476 Convey("Test ValidateRepo3", t, func(c C) { 477 il = createMockStorage(testDir, &StorageDriverMock{ 478 listFn: func(ctx context.Context, path string) ([]string, error) { 479 return []string{"test/test/oci-layout", "test/test/index.json"}, nil 480 }, 481 statFn: func(ctx context.Context, path string) (storageDriver.FileInfo, error) { 482 return &FileInfoMock{}, nil 483 }, 484 getContentFn: func(ctx context.Context, path string) ([]byte, error) { 485 return []byte{}, errS3 486 }, 487 }) 488 _, err := il.ValidateRepo(testImage) 489 So(err, ShouldNotBeNil) 490 }) 491 492 Convey("Test ValidateRepo4", t, func(c C) { 493 ociLayout := []byte(`{"imageLayoutVersion": "9.9.9"}`) 494 il = createMockStorage(testDir, &StorageDriverMock{ 495 listFn: func(ctx context.Context, path string) ([]string, error) { 496 return []string{"test/test/oci-layout", "test/test/index.json"}, nil 497 }, 498 statFn: func(ctx context.Context, path string) (storageDriver.FileInfo, error) { 499 return &FileInfoMock{}, nil 500 }, 501 getContentFn: func(ctx context.Context, path string) ([]byte, error) { 502 return ociLayout, nil 503 }, 504 }) 505 _, err := il.ValidateRepo(testImage) 506 So(err, ShouldNotBeNil) 507 }) 508 509 Convey("Test GetRepositories", t, func(c C) { 510 il = createMockStorage(testDir, &StorageDriverMock{ 511 walkFn: func(ctx context.Context, path string, f storageDriver.WalkFn) error { 512 return f(new(FileInfoMock)) 513 }, 514 }) 515 repos, err := il.GetRepositories() 516 So(repos, ShouldBeEmpty) 517 So(err, ShouldBeNil) 518 }) 519 520 Convey("Test DeleteImageManifest", t, func(c C) { 521 il = createMockStorage(testDir, &StorageDriverMock{ 522 getContentFn: func(ctx context.Context, path string) ([]byte, error) { 523 return []byte{}, errS3 524 }, 525 }) 526 err := il.DeleteImageManifest(testImage, "1.0") 527 So(err, ShouldNotBeNil) 528 }) 529 530 Convey("Test DeleteImageManifest2", t, func(c C) { 531 il = createMockStorage(testDir, &StorageDriverMock{}) 532 err := il.DeleteImageManifest(testImage, "1.0") 533 So(err, ShouldNotBeNil) 534 }) 535 536 Convey("Test NewBlobUpload", t, func(c C) { 537 il = createMockStorage(testDir, &StorageDriverMock{ 538 putContentFn: func(ctx context.Context, path string, content []byte) error { 539 return errS3 540 }, 541 }) 542 _, err := il.NewBlobUpload(testImage) 543 So(err, ShouldNotBeNil) 544 }) 545 546 Convey("Test GetBlobUpload", t, func(c C) { 547 il = createMockStorage(testDir, &StorageDriverMock{ 548 statFn: func(ctx context.Context, path string) (storageDriver.FileInfo, error) { 549 return &FileInfoMock{}, errS3 550 }, 551 }) 552 _, err := il.GetBlobUpload(testImage, "uuid") 553 So(err, ShouldNotBeNil) 554 }) 555 556 Convey("Test PutBlobChunkStreamed", t, func(c C) { 557 il = createMockStorage(testDir, &StorageDriverMock{ 558 writerFn: func(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) { 559 return &FileWriterMock{}, errS3 560 }, 561 }) 562 _, err := il.PutBlobChunkStreamed(testImage, "uuid", ioutil.NopCloser(strings.NewReader(""))) 563 So(err, ShouldNotBeNil) 564 }) 565 566 Convey("Test PutBlobChunkStreamed2", t, func(c C) { 567 il = createMockStorage(testDir, &StorageDriverMock{ 568 writerFn: func(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) { 569 return &FileWriterMock{writeFn: func(b []byte) (int, error) { 570 return 0, errS3 571 }}, nil 572 }, 573 }) 574 _, err := il.PutBlobChunkStreamed(testImage, "uuid", ioutil.NopCloser(strings.NewReader(""))) 575 So(err, ShouldNotBeNil) 576 }) 577 578 Convey("Test PutBlobChunk", t, func(c C) { 579 il = createMockStorage(testDir, &StorageDriverMock{ 580 writerFn: func(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) { 581 return &FileWriterMock{}, errS3 582 }, 583 }) 584 _, err := il.PutBlobChunk(testImage, "uuid", 0, 100, ioutil.NopCloser(strings.NewReader(""))) 585 So(err, ShouldNotBeNil) 586 }) 587 588 Convey("Test PutBlobChunk2", t, func(c C) { 589 il = createMockStorage(testDir, &StorageDriverMock{ 590 writerFn: func(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) { 591 return &FileWriterMock{ 592 writeFn: func(b []byte) (int, error) { 593 return 0, errS3 594 }, 595 cancelFn: func() error { 596 return errS3 597 }, 598 }, nil 599 }, 600 }) 601 _, err := il.PutBlobChunk(testImage, "uuid", 0, 100, ioutil.NopCloser(strings.NewReader(""))) 602 So(err, ShouldNotBeNil) 603 }) 604 605 Convey("Test PutBlobChunk3", t, func(c C) { 606 il = createMockStorage(testDir, &StorageDriverMock{ 607 writerFn: func(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) { 608 return &FileWriterMock{ 609 writeFn: func(b []byte) (int, error) { 610 return 0, errS3 611 }, 612 }, nil 613 }, 614 }) 615 _, err := il.PutBlobChunk(testImage, "uuid", 12, 100, ioutil.NopCloser(strings.NewReader(""))) 616 So(err, ShouldNotBeNil) 617 }) 618 619 Convey("Test FinishBlobUpload", t, func(c C) { 620 il = createMockStorage(testDir, &StorageDriverMock{ 621 writerFn: func(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) { 622 return &FileWriterMock{ 623 commitFn: func() error { 624 return errS3 625 }, 626 }, nil 627 }, 628 }) 629 d := godigest.FromBytes([]byte("test")) 630 err := il.FinishBlobUpload(testImage, "uuid", ioutil.NopCloser(strings.NewReader("")), d.String()) 631 So(err, ShouldNotBeNil) 632 }) 633 634 Convey("Test FinishBlobUpload2", t, func(c C) { 635 il = createMockStorage(testDir, &StorageDriverMock{ 636 writerFn: func(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) { 637 return &FileWriterMock{ 638 closeFn: func() error { 639 return errS3 640 }, 641 }, nil 642 }, 643 }) 644 d := godigest.FromBytes([]byte("test")) 645 err := il.FinishBlobUpload(testImage, "uuid", ioutil.NopCloser(strings.NewReader("")), d.String()) 646 So(err, ShouldNotBeNil) 647 }) 648 649 Convey("Test FinishBlobUpload3", t, func(c C) { 650 il = createMockStorage(testDir, &StorageDriverMock{ 651 readerFn: func(ctx context.Context, path string, offset int64) (io.ReadCloser, error) { 652 return nil, errS3 653 }, 654 }) 655 d := godigest.FromBytes([]byte("test")) 656 err := il.FinishBlobUpload(testImage, "uuid", ioutil.NopCloser(strings.NewReader("")), d.String()) 657 So(err, ShouldNotBeNil) 658 }) 659 660 Convey("Test FinishBlobUpload4", t, func(c C) { 661 il = createMockStorage(testDir, &StorageDriverMock{ 662 moveFn: func(ctx context.Context, sourcePath, destPath string) error { 663 return errS3 664 }, 665 }) 666 d := godigest.FromBytes([]byte("")) 667 err := il.FinishBlobUpload(testImage, "uuid", ioutil.NopCloser(strings.NewReader("")), d.String()) 668 So(err, ShouldNotBeNil) 669 }) 670 671 Convey("Test FullBlobUpload", t, func(c C) { 672 il = createMockStorage(testDir, &StorageDriverMock{ 673 writerFn: func(ctx context.Context, path string, append bool) (storageDriver.FileWriter, error) { 674 return &FileWriterMock{}, errS3 675 }, 676 }) 677 d := godigest.FromBytes([]byte("")) 678 _, _, err := il.FullBlobUpload(testImage, ioutil.NopCloser(strings.NewReader("")), d.String()) 679 So(err, ShouldNotBeNil) 680 }) 681 682 Convey("Test FullBlobUpload2", t, func(c C) { 683 il = createMockStorage(testDir, &StorageDriverMock{}) 684 d := godigest.FromBytes([]byte(" ")) 685 _, _, err := il.FullBlobUpload(testImage, ioutil.NopCloser(strings.NewReader("")), d.String()) 686 So(err, ShouldNotBeNil) 687 }) 688 689 Convey("Test FullBlobUpload3", t, func(c C) { 690 il = createMockStorage(testDir, &StorageDriverMock{ 691 moveFn: func(ctx context.Context, sourcePath, destPath string) error { 692 return errS3 693 }, 694 }) 695 d := godigest.FromBytes([]byte("")) 696 _, _, err := il.FullBlobUpload(testImage, ioutil.NopCloser(strings.NewReader("")), d.String()) 697 So(err, ShouldNotBeNil) 698 }) 699 700 Convey("Test GetBlob", t, func(c C) { 701 il = createMockStorage(testDir, &StorageDriverMock{ 702 readerFn: func(ctx context.Context, path string, offset int64) (io.ReadCloser, error) { 703 return ioutil.NopCloser(strings.NewReader("")), errS3 704 }, 705 }) 706 d := godigest.FromBytes([]byte("")) 707 _, _, err := il.GetBlob(testImage, d.String(), "") 708 So(err, ShouldNotBeNil) 709 }) 710 711 Convey("Test DeleteBlob", t, func(c C) { 712 il = createMockStorage(testDir, &StorageDriverMock{ 713 deleteFn: func(ctx context.Context, path string) error { 714 return errS3 715 }, 716 }) 717 d := godigest.FromBytes([]byte("")) 718 err := il.DeleteBlob(testImage, d.String()) 719 So(err, ShouldNotBeNil) 720 }) 721 722 Convey("Test GetReferrers", t, func(c C) { 723 il = createMockStorage(testDir, &StorageDriverMock{ 724 deleteFn: func(ctx context.Context, path string) error { 725 return errS3 726 }, 727 }) 728 d := godigest.FromBytes([]byte("")) 729 _, err := il.GetReferrers(testImage, d.String(), "application/image") 730 So(err, ShouldNotBeNil) 731 So(err, ShouldEqual, zerr.ErrMethodNotSupported) 732 }) 733 }