0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2025-01-06 22:40:28 -05:00
zot/pkg/test/mocks/cache_mock.go
2023-04-07 09:49:24 -07:00

60 lines
1.4 KiB
Go

package mocks
import godigest "github.com/opencontainers/go-digest"
type CacheMock struct {
// Returns the human-readable "name" of the driver.
NameFn func() string
// Retrieves the blob matching provided digest.
GetBlobFn func(digest godigest.Digest) (string, error)
// Uploads blob to cachedb.
PutBlobFn func(digest godigest.Digest, path string) error
// Check if blob exists in cachedb.
HasBlobFn func(digest godigest.Digest, path string) bool
// Delete a blob from the cachedb.
DeleteBlobFn func(digest godigest.Digest, path string) error
}
func (cacheMock CacheMock) Name() string {
if cacheMock.NameFn != nil {
return cacheMock.NameFn()
}
return "mock"
}
func (cacheMock CacheMock) GetBlob(digest godigest.Digest) (string, error) {
if cacheMock.GetBlobFn != nil {
return cacheMock.GetBlobFn(digest)
}
return "", nil
}
func (cacheMock CacheMock) PutBlob(digest godigest.Digest, path string) error {
if cacheMock.PutBlobFn != nil {
return cacheMock.PutBlobFn(digest, path)
}
return nil
}
func (cacheMock CacheMock) HasBlob(digest godigest.Digest, path string) bool {
if cacheMock.HasBlobFn != nil {
return cacheMock.HasBlobFn(digest, path)
}
return true
}
func (cacheMock CacheMock) DeleteBlob(digest godigest.Digest, path string) error {
if cacheMock.DeleteBlobFn != nil {
return cacheMock.DeleteBlobFn(digest, path)
}
return nil
}