2021-07-16 22:53:05 -05:00
|
|
|
package s3_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
_ "crypto/sha256"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2021-12-13 14:23:31 -05:00
|
|
|
"time"
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
"github.com/docker/distribution/registry/storage/driver"
|
|
|
|
"github.com/docker/distribution/registry/storage/driver/factory"
|
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/s3-aws"
|
2021-07-16 22:53:05 -05:00
|
|
|
guuid "github.com/gofrs/uuid"
|
2021-12-13 14:23:31 -05:00
|
|
|
godigest "github.com/opencontainers/go-digest"
|
2021-07-16 22:53:05 -05:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2021-12-13 14:23:31 -05:00
|
|
|
"gopkg.in/resty.v1"
|
2021-12-03 22:50:58 -05:00
|
|
|
zerr "zotregistry.io/zot/errors"
|
|
|
|
"zotregistry.io/zot/pkg/extensions/monitoring"
|
|
|
|
"zotregistry.io/zot/pkg/log"
|
|
|
|
"zotregistry.io/zot/pkg/storage"
|
|
|
|
"zotregistry.io/zot/pkg/storage/s3"
|
2021-07-16 22:53:05 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// nolint: gochecknoglobals
|
|
|
|
var (
|
|
|
|
testImage = "test"
|
|
|
|
fileWriterSize = 12
|
|
|
|
fileInfoSize = 10
|
|
|
|
errorText = "new s3 error"
|
|
|
|
errS3 = errors.New(errorText)
|
|
|
|
)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
func cleanupStorage(store driver.StorageDriver, name string) {
|
2021-07-16 22:53:05 -05:00
|
|
|
_ = store.Delete(context.Background(), name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func skipIt(t *testing.T) {
|
2021-12-13 14:23:31 -05:00
|
|
|
t.Helper()
|
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
if os.Getenv("S3MOCK_ENDPOINT") == "" {
|
|
|
|
t.Skip("Skipping testing without AWS S3 mock server")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
func createMockStorage(rootDir string, store driver.StorageDriver) storage.ImageStore {
|
2021-07-16 22:53:05 -05:00
|
|
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
2022-02-09 19:51:35 -05:00
|
|
|
il := s3.NewImageStore(rootDir, false, storage.DefaultGCDelay, false, false, log, metrics, store)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
return il
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
func createObjectsStore(rootDir string) (driver.StorageDriver, storage.ImageStore, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
bucket := "zot-storage-test"
|
|
|
|
endpoint := os.Getenv("S3MOCK_ENDPOINT")
|
|
|
|
storageDriverParams := map[string]interface{}{
|
|
|
|
"rootDir": rootDir,
|
|
|
|
"name": "s3",
|
|
|
|
"region": "us-east-2",
|
|
|
|
"bucket": bucket,
|
|
|
|
"regionendpoint": endpoint,
|
|
|
|
"secure": false,
|
|
|
|
"skipverify": false,
|
|
|
|
}
|
|
|
|
|
|
|
|
storeName := fmt.Sprintf("%v", storageDriverParams["name"])
|
|
|
|
|
|
|
|
store, err := factory.Create(storeName, storageDriverParams)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// create bucket if it doesn't exists
|
|
|
|
_, err = resty.R().Put("http://" + endpoint + "/" + bucket)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
2022-02-09 19:51:35 -05:00
|
|
|
il := s3.NewImageStore(rootDir, false, storage.DefaultGCDelay, false, false, log, metrics, store)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
return store, il, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type FileInfoMock struct {
|
|
|
|
isDirFn func() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FileInfoMock) Path() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FileInfoMock) Size() int64 {
|
|
|
|
return int64(fileInfoSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FileInfoMock) ModTime() time.Time {
|
|
|
|
return time.Now()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FileInfoMock) IsDir() bool {
|
|
|
|
if f != nil && f.isDirFn != nil {
|
|
|
|
return f.isDirFn()
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
type FileWriterMock struct {
|
|
|
|
writeFn func([]byte) (int, error)
|
|
|
|
cancelFn func() error
|
|
|
|
commitFn func() error
|
|
|
|
closeFn func() error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FileWriterMock) Size() int64 {
|
|
|
|
return int64(fileWriterSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FileWriterMock) Cancel() error {
|
|
|
|
if f != nil && f.cancelFn != nil {
|
|
|
|
return f.cancelFn()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FileWriterMock) Commit() error {
|
|
|
|
if f != nil && f.commitFn != nil {
|
|
|
|
return f.commitFn()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FileWriterMock) Write(p []byte) (int, error) {
|
|
|
|
if f != nil && f.writeFn != nil {
|
|
|
|
return f.writeFn(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
return 10, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FileWriterMock) Close() error {
|
|
|
|
if f != nil && f.closeFn != nil {
|
|
|
|
return f.closeFn()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type StorageDriverMock struct {
|
|
|
|
nameFn func() string
|
|
|
|
getContentFn func(ctx context.Context, path string) ([]byte, error)
|
|
|
|
putContentFn func(ctx context.Context, path string, content []byte) error
|
|
|
|
readerFn func(ctx context.Context, path string, offset int64) (io.ReadCloser, error)
|
2021-12-13 14:23:31 -05:00
|
|
|
writerFn func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error)
|
|
|
|
statFn func(ctx context.Context, path string) (driver.FileInfo, error)
|
2021-07-16 22:53:05 -05:00
|
|
|
listFn func(ctx context.Context, path string) ([]string, error)
|
2022-03-21 12:37:23 -05:00
|
|
|
moveFn func(ctx context.Context, sourcePath, destPath string) error
|
2021-07-16 22:53:05 -05:00
|
|
|
deleteFn func(ctx context.Context, path string) error
|
2021-12-13 14:23:31 -05:00
|
|
|
walkFn func(ctx context.Context, path string, f driver.WalkFn) error
|
2021-07-16 22:53:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StorageDriverMock) Name() string {
|
|
|
|
if s != nil && s.nameFn != nil {
|
|
|
|
return s.nameFn()
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StorageDriverMock) GetContent(ctx context.Context, path string) ([]byte, error) {
|
|
|
|
if s != nil && s.getContentFn != nil {
|
|
|
|
return s.getContentFn(ctx, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StorageDriverMock) PutContent(ctx context.Context, path string, content []byte) error {
|
|
|
|
if s != nil && s.putContentFn != nil {
|
|
|
|
return s.putContentFn(ctx, path, content)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StorageDriverMock) Reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
|
|
|
|
if s != nil && s.readerFn != nil {
|
|
|
|
return s.readerFn(ctx, path, offset)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ioutil.NopCloser(strings.NewReader("")), nil
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
func (s *StorageDriverMock) Writer(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
if s != nil && s.writerFn != nil {
|
2021-12-13 14:23:31 -05:00
|
|
|
return s.writerFn(ctx, path, isAppend)
|
2021-07-16 22:53:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return &FileWriterMock{}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
func (s *StorageDriverMock) Stat(ctx context.Context, path string) (driver.FileInfo, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
if s != nil && s.statFn != nil {
|
|
|
|
return s.statFn(ctx, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &FileInfoMock{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StorageDriverMock) List(ctx context.Context, path string) ([]string, error) {
|
|
|
|
if s != nil && s.listFn != nil {
|
|
|
|
return s.listFn(ctx, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return []string{"a"}, nil
|
|
|
|
}
|
|
|
|
|
2022-03-21 12:37:23 -05:00
|
|
|
func (s *StorageDriverMock) Move(ctx context.Context, sourcePath, destPath string) error {
|
2021-07-16 22:53:05 -05:00
|
|
|
if s != nil && s.moveFn != nil {
|
|
|
|
return s.moveFn(ctx, sourcePath, destPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StorageDriverMock) Delete(ctx context.Context, path string) error {
|
|
|
|
if s != nil && s.deleteFn != nil {
|
|
|
|
return s.deleteFn(ctx, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StorageDriverMock) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
func (s *StorageDriverMock) Walk(ctx context.Context, path string, f driver.WalkFn) error {
|
2021-07-16 22:53:05 -05:00
|
|
|
if s != nil && s.walkFn != nil {
|
|
|
|
return s.walkFn(ctx, path, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-18 04:24:24 -05:00
|
|
|
func TestStorageDriverStatFunction(t *testing.T) {
|
|
|
|
skipIt(t)
|
|
|
|
|
|
|
|
uuid, err := guuid.NewV4()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testDir := path.Join("/oci-repo-test", uuid.String())
|
|
|
|
|
|
|
|
storeDriver, imgStore, _ := createObjectsStore(testDir)
|
|
|
|
defer cleanupStorage(storeDriver, testDir)
|
|
|
|
|
|
|
|
/* There is an issue with storageDriver.Stat() that returns a storageDriver.FileInfo()
|
|
|
|
which falsely reports isDir() as true for paths under certain circumstances
|
|
|
|
for example:
|
|
|
|
1) create a file, eg: repo/testImageA/file
|
|
|
|
2) run storageDriver.Stat() on a partial path, eg: storageDriver.Stat("repo/testImage") - without 'A' char
|
|
|
|
3) the returned storageDriver.FileInfo will report that isDir() is true.
|
|
|
|
*/
|
|
|
|
Convey("Validate storageDriver.Stat() and isDir() functions with zot storage API", t, func(c C) {
|
|
|
|
repo1 := "repo/testImageA"
|
|
|
|
repo2 := "repo/testImage"
|
|
|
|
|
|
|
|
So(imgStore, ShouldNotBeNil)
|
|
|
|
|
|
|
|
err = imgStore.InitRepo(repo1)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
isValid, err := imgStore.ValidateRepo(repo1)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(isValid, ShouldBeTrue)
|
|
|
|
|
|
|
|
err = imgStore.InitRepo(repo2)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
isValid, err = imgStore.ValidateRepo(repo2)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(isValid, ShouldBeTrue)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Validate storageDriver.Stat() and isDir() functions with storageDriver API", t, func(c C) {
|
|
|
|
testFile := "/ab/cd/file"
|
|
|
|
|
|
|
|
shouldBeDirectoryPath1 := "/ab/cd"
|
|
|
|
shouldBeDirectoryPath2 := "/ab"
|
|
|
|
|
|
|
|
shouldNotBeDirectoryPath1 := "/ab/c"
|
|
|
|
shouldNotBeDirectoryPath2 := "/a"
|
|
|
|
|
|
|
|
err := storeDriver.PutContent(context.Background(), testFile, []byte("file contents"))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
fileInfo, err := storeDriver.Stat(context.Background(), testFile)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
So(fileInfo.IsDir(), ShouldBeFalse)
|
|
|
|
|
|
|
|
fileInfo, err = storeDriver.Stat(context.Background(), shouldBeDirectoryPath1)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(fileInfo.IsDir(), ShouldBeTrue)
|
|
|
|
|
|
|
|
fileInfo, err = storeDriver.Stat(context.Background(), shouldBeDirectoryPath2)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(fileInfo.IsDir(), ShouldBeTrue)
|
|
|
|
|
|
|
|
fileInfo, err = storeDriver.Stat(context.Background(), shouldNotBeDirectoryPath1)
|
|
|
|
// err should actually be storageDriver.PathNotFoundError but it's nil
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
// should be false instead
|
|
|
|
So(fileInfo.IsDir(), ShouldBeTrue)
|
|
|
|
|
|
|
|
fileInfo, err = storeDriver.Stat(context.Background(), shouldNotBeDirectoryPath2)
|
|
|
|
// err should actually be storageDriver.PathNotFoundError but it's nils
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
// should be false instead
|
|
|
|
So(fileInfo.IsDir(), ShouldBeTrue)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
func TestNegativeCasesObjectsStorage(t *testing.T) {
|
|
|
|
skipIt(t)
|
|
|
|
|
|
|
|
uuid, err := guuid.NewV4()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testDir := path.Join("/oci-repo-test", uuid.String())
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
storeDriver, imgStore, _ := createObjectsStore(testDir)
|
|
|
|
defer cleanupStorage(storeDriver, testDir)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
Convey("Invalid validate repo", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
So(imgStore, ShouldNotBeNil)
|
|
|
|
So(imgStore.InitRepo(testImage), ShouldBeNil)
|
|
|
|
objects, err := storeDriver.List(context.Background(), path.Join(imgStore.RootDir(), testImage))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
for _, object := range objects {
|
|
|
|
t.Logf("Removing object: %s", object)
|
2021-12-13 14:23:31 -05:00
|
|
|
err := storeDriver.Delete(context.Background(), object)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
}
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.ValidateRepo(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.GetRepositories()
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Invalid get image tags", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
storeDriver, imgStore, err := createObjectsStore(testDir)
|
|
|
|
defer cleanupStorage(storeDriver, testDir)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(imgStore.InitRepo(testImage), ShouldBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
So(storeDriver.Move(context.Background(), path.Join(testDir, testImage, "index.json"),
|
2021-07-16 22:53:05 -05:00
|
|
|
path.Join(testDir, testImage, "blobs")), ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
ok, _ := imgStore.ValidateRepo(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(ok, ShouldBeFalse)
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.GetImageTags(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
So(storeDriver.Delete(context.Background(), path.Join(testDir, testImage)), ShouldBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
So(imgStore.InitRepo(testImage), ShouldBeNil)
|
|
|
|
So(storeDriver.PutContent(context.Background(), path.Join(testDir, testImage, "index.json"), []byte{}), ShouldBeNil)
|
|
|
|
_, err = imgStore.GetImageTags(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Invalid get image manifest", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
storeDriver, imgStore, err := createObjectsStore(testDir)
|
|
|
|
defer cleanupStorage(storeDriver, testDir)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(imgStore, ShouldNotBeNil)
|
|
|
|
So(imgStore.InitRepo(testImage), ShouldBeNil)
|
|
|
|
So(storeDriver.Delete(context.Background(), path.Join(testDir, testImage, "index.json")), ShouldBeNil)
|
|
|
|
_, _, _, err = imgStore.GetImageManifest(testImage, "")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(storeDriver.Delete(context.Background(), path.Join(testDir, testImage)), ShouldBeNil)
|
|
|
|
So(imgStore.InitRepo(testImage), ShouldBeNil)
|
|
|
|
So(storeDriver.PutContent(context.Background(), path.Join(testDir, testImage, "index.json"), []byte{}), ShouldBeNil)
|
|
|
|
_, _, _, err = imgStore.GetImageManifest(testImage, "")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Invalid validate repo", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
storeDriver, imgStore, err := createObjectsStore(testDir)
|
|
|
|
defer cleanupStorage(storeDriver, testDir)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(imgStore, ShouldNotBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
So(imgStore.InitRepo(testImage), ShouldBeNil)
|
|
|
|
So(storeDriver.Delete(context.Background(), path.Join(testDir, testImage, "index.json")), ShouldBeNil)
|
|
|
|
_, err = imgStore.ValidateRepo(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(storeDriver.Delete(context.Background(), path.Join(testDir, testImage)), ShouldBeNil)
|
|
|
|
So(imgStore.InitRepo(testImage), ShouldBeNil)
|
|
|
|
So(storeDriver.Move(context.Background(), path.Join(testDir, testImage, "index.json"),
|
2021-07-16 22:53:05 -05:00
|
|
|
path.Join(testDir, testImage, "_index.json")), ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
ok, err := imgStore.ValidateRepo(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(ok, ShouldBeFalse)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Invalid finish blob upload", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
storeDriver, imgStore, err := createObjectsStore(testDir)
|
|
|
|
defer cleanupStorage(storeDriver, testDir)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(imgStore, ShouldNotBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
So(imgStore.InitRepo(testImage), ShouldBeNil)
|
|
|
|
upload, err := imgStore.NewBlobUpload(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(upload, ShouldNotBeEmpty)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
content := []byte("test-data1")
|
|
|
|
buf := bytes.NewBuffer(content)
|
2021-12-13 14:23:31 -05:00
|
|
|
buflen := buf.Len()
|
|
|
|
digest := godigest.FromBytes(content)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
blob, err := imgStore.PutBlobChunk(testImage, upload, 0, int64(buflen), buf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(blob, ShouldEqual, buflen)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
src := imgStore.BlobUploadPath(testImage, upload)
|
|
|
|
stwr, err := storeDriver.Writer(context.Background(), src, true)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = stwr.Write([]byte("another-chunk-of-data"))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = stwr.Close()
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.FinishBlobUpload(testImage, upload, buf, digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test storage driver errors", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
listFn: func(ctx context.Context, path string) ([]string, error) {
|
|
|
|
return []string{testImage}, errS3
|
|
|
|
},
|
|
|
|
moveFn: func(ctx context.Context, sourcePath, destPath string) error {
|
|
|
|
return errS3
|
|
|
|
},
|
|
|
|
getContentFn: func(ctx context.Context, path string) ([]byte, error) {
|
|
|
|
return []byte{}, errS3
|
|
|
|
},
|
|
|
|
putContentFn: func(ctx context.Context, path string, content []byte) error {
|
|
|
|
return errS3
|
|
|
|
},
|
2021-12-13 14:23:31 -05:00
|
|
|
writerFn: func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileWriterMock{}, errS3
|
|
|
|
},
|
|
|
|
readerFn: func(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
|
|
|
|
return ioutil.NopCloser(strings.NewReader("")), errS3
|
|
|
|
},
|
2021-12-13 14:23:31 -05:00
|
|
|
walkFn: func(ctx context.Context, path string, f driver.WalkFn) error {
|
2021-07-16 22:53:05 -05:00
|
|
|
return errS3
|
|
|
|
},
|
2021-12-13 14:23:31 -05:00
|
|
|
statFn: func(ctx context.Context, path string) (driver.FileInfo, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileInfoMock{}, errS3
|
|
|
|
},
|
|
|
|
deleteFn: func(ctx context.Context, path string) error {
|
|
|
|
return errS3
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
So(imgStore, ShouldNotBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
So(imgStore.InitRepo(testImage), ShouldNotBeNil)
|
|
|
|
_, err := imgStore.ValidateRepo(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
upload, err := imgStore.NewBlobUpload(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
content := []byte("test-data1")
|
|
|
|
buf := bytes.NewBuffer(content)
|
2021-12-13 14:23:31 -05:00
|
|
|
buflen := buf.Len()
|
|
|
|
digest := godigest.FromBytes(content)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutBlobChunk(testImage, upload, 0, int64(buflen), buf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.FinishBlobUpload(testImage, upload, buf, digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteBlob(testImage, digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteBlobUpload(testImage, upload)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteImageManifest(testImage, "1.0")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutImageManifest(testImage, "1.0", "application/json", []byte{})
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutBlobChunkStreamed(testImage, upload, bytes.NewBuffer([]byte(testImage)))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err = imgStore.FullBlobUpload(testImage, bytes.NewBuffer([]byte{}), "inexistent")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err = imgStore.CheckBlob(testImage, digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test ValidateRepo", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
listFn: func(ctx context.Context, path string) ([]string, error) {
|
|
|
|
return []string{testImage, testImage}, errS3
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.ValidateRepo(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test ValidateRepo2", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
listFn: func(ctx context.Context, path string) ([]string, error) {
|
|
|
|
return []string{"test/test/oci-layout", "test/test/index.json"}, nil
|
|
|
|
},
|
2021-12-13 14:23:31 -05:00
|
|
|
statFn: func(ctx context.Context, path string) (driver.FileInfo, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileInfoMock{}, nil
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.ValidateRepo(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test ValidateRepo3", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
listFn: func(ctx context.Context, path string) ([]string, error) {
|
|
|
|
return []string{"test/test/oci-layout", "test/test/index.json"}, nil
|
|
|
|
},
|
2021-12-13 14:23:31 -05:00
|
|
|
statFn: func(ctx context.Context, path string) (driver.FileInfo, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileInfoMock{}, nil
|
|
|
|
},
|
|
|
|
getContentFn: func(ctx context.Context, path string) ([]byte, error) {
|
|
|
|
return []byte{}, errS3
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.ValidateRepo(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test ValidateRepo4", t, func(c C) {
|
|
|
|
ociLayout := []byte(`{"imageLayoutVersion": "9.9.9"}`)
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
listFn: func(ctx context.Context, path string) ([]string, error) {
|
|
|
|
return []string{"test/test/oci-layout", "test/test/index.json"}, nil
|
|
|
|
},
|
2021-12-13 14:23:31 -05:00
|
|
|
statFn: func(ctx context.Context, path string) (driver.FileInfo, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileInfoMock{}, nil
|
|
|
|
},
|
|
|
|
getContentFn: func(ctx context.Context, path string) ([]byte, error) {
|
|
|
|
return ociLayout, nil
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.ValidateRepo(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test GetRepositories", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
|
|
|
walkFn: func(ctx context.Context, path string, f driver.WalkFn) error {
|
2021-07-16 22:53:05 -05:00
|
|
|
return f(new(FileInfoMock))
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
repos, err := imgStore.GetRepositories()
|
2021-07-16 22:53:05 -05:00
|
|
|
So(repos, ShouldBeEmpty)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test DeleteImageManifest", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
getContentFn: func(ctx context.Context, path string) ([]byte, error) {
|
|
|
|
return []byte{}, errS3
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
err := imgStore.DeleteImageManifest(testImage, "1.0")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test DeleteImageManifest2", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{})
|
|
|
|
err := imgStore.DeleteImageManifest(testImage, "1.0")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test NewBlobUpload", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
putContentFn: func(ctx context.Context, path string, content []byte) error {
|
|
|
|
return errS3
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.NewBlobUpload(testImage)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test GetBlobUpload", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
|
|
|
statFn: func(ctx context.Context, path string) (driver.FileInfo, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileInfoMock{}, errS3
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.GetBlobUpload(testImage, "uuid")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test PutBlobChunkStreamed", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
|
|
|
writerFn: func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileWriterMock{}, errS3
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.PutBlobChunkStreamed(testImage, "uuid", ioutil.NopCloser(strings.NewReader("")))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test PutBlobChunkStreamed2", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
|
|
|
writerFn: func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileWriterMock{writeFn: func(b []byte) (int, error) {
|
|
|
|
return 0, errS3
|
|
|
|
}}, nil
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.PutBlobChunkStreamed(testImage, "uuid", ioutil.NopCloser(strings.NewReader("")))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test PutBlobChunk", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
|
|
|
writerFn: func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileWriterMock{}, errS3
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.PutBlobChunk(testImage, "uuid", 0, 100, ioutil.NopCloser(strings.NewReader("")))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test PutBlobChunk2", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
|
|
|
writerFn: func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileWriterMock{
|
|
|
|
writeFn: func(b []byte) (int, error) {
|
|
|
|
return 0, errS3
|
|
|
|
},
|
|
|
|
cancelFn: func() error {
|
|
|
|
return errS3
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.PutBlobChunk(testImage, "uuid", 0, 100, ioutil.NopCloser(strings.NewReader("")))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test PutBlobChunk3", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
|
|
|
writerFn: func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileWriterMock{
|
|
|
|
writeFn: func(b []byte) (int, error) {
|
|
|
|
return 0, errS3
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
})
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.PutBlobChunk(testImage, "uuid", 12, 100, ioutil.NopCloser(strings.NewReader("")))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test FinishBlobUpload", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
|
|
|
writerFn: func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileWriterMock{
|
|
|
|
commitFn: func() error {
|
|
|
|
return errS3
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
d := godigest.FromBytes([]byte("test"))
|
2021-12-13 14:23:31 -05:00
|
|
|
err := imgStore.FinishBlobUpload(testImage, "uuid", ioutil.NopCloser(strings.NewReader("")), d.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test FinishBlobUpload2", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
|
|
|
writerFn: func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileWriterMock{
|
|
|
|
closeFn: func() error {
|
|
|
|
return errS3
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
d := godigest.FromBytes([]byte("test"))
|
2021-12-13 14:23:31 -05:00
|
|
|
err := imgStore.FinishBlobUpload(testImage, "uuid", ioutil.NopCloser(strings.NewReader("")), d.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test FinishBlobUpload3", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
readerFn: func(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
|
|
|
|
return nil, errS3
|
|
|
|
},
|
|
|
|
})
|
|
|
|
d := godigest.FromBytes([]byte("test"))
|
2021-12-13 14:23:31 -05:00
|
|
|
err := imgStore.FinishBlobUpload(testImage, "uuid", ioutil.NopCloser(strings.NewReader("")), d.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test FinishBlobUpload4", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
moveFn: func(ctx context.Context, sourcePath, destPath string) error {
|
|
|
|
return errS3
|
|
|
|
},
|
|
|
|
})
|
|
|
|
d := godigest.FromBytes([]byte(""))
|
2021-12-13 14:23:31 -05:00
|
|
|
err := imgStore.FinishBlobUpload(testImage, "uuid", ioutil.NopCloser(strings.NewReader("")), d.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test FullBlobUpload", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
|
|
|
writerFn: func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
return &FileWriterMock{}, errS3
|
|
|
|
},
|
|
|
|
})
|
|
|
|
d := godigest.FromBytes([]byte(""))
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err := imgStore.FullBlobUpload(testImage, ioutil.NopCloser(strings.NewReader("")), d.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test FullBlobUpload2", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{})
|
2021-07-16 22:53:05 -05:00
|
|
|
d := godigest.FromBytes([]byte(" "))
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err := imgStore.FullBlobUpload(testImage, ioutil.NopCloser(strings.NewReader("")), d.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test FullBlobUpload3", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
moveFn: func(ctx context.Context, sourcePath, destPath string) error {
|
|
|
|
return errS3
|
|
|
|
},
|
|
|
|
})
|
|
|
|
d := godigest.FromBytes([]byte(""))
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err := imgStore.FullBlobUpload(testImage, ioutil.NopCloser(strings.NewReader("")), d.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test GetBlob", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
readerFn: func(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
|
|
|
|
return ioutil.NopCloser(strings.NewReader("")), errS3
|
|
|
|
},
|
|
|
|
})
|
|
|
|
d := godigest.FromBytes([]byte(""))
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err := imgStore.GetBlob(testImage, d.String(), "")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test DeleteBlob", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-07-16 22:53:05 -05:00
|
|
|
deleteFn: func(ctx context.Context, path string) error {
|
|
|
|
return errS3
|
|
|
|
},
|
|
|
|
})
|
|
|
|
d := godigest.FromBytes([]byte(""))
|
2021-12-13 14:23:31 -05:00
|
|
|
err := imgStore.DeleteBlob(testImage, d.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2021-10-29 21:10:55 -05:00
|
|
|
|
|
|
|
Convey("Test GetReferrers", t, func(c C) {
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = createMockStorage(testDir, &StorageDriverMock{
|
2021-10-29 21:10:55 -05:00
|
|
|
deleteFn: func(ctx context.Context, path string) error {
|
|
|
|
return errS3
|
|
|
|
},
|
|
|
|
})
|
|
|
|
d := godigest.FromBytes([]byte(""))
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err := imgStore.GetReferrers(testImage, d.String(), "application/image")
|
2021-10-29 21:10:55 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
So(err, ShouldEqual, zerr.ErrMethodNotSupported)
|
|
|
|
})
|
2021-07-16 22:53:05 -05:00
|
|
|
}
|