2022-03-23 11:02:00 +02:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-03-30 13:58:16 +02:00
|
|
|
|
|
|
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
2022-03-23 11:02:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// DownloadMock .
|
|
|
|
type DownloadMock struct {
|
2022-03-30 13:58:16 +02:00
|
|
|
FilePath string
|
|
|
|
ImageRef string
|
|
|
|
RemoteImageRef string
|
|
|
|
RegistryURL string
|
2022-03-23 11:02:00 +02:00
|
|
|
|
2022-03-30 13:58:16 +02:00
|
|
|
ReturnImage v1.Image
|
|
|
|
RemoteImageInfo v1.Image
|
|
|
|
ReturnError string
|
2022-03-23 11:02:00 +02:00
|
|
|
|
2023-07-06 11:34:05 +02:00
|
|
|
Stub func(imageRef, targetDir string) (v1.Image, error)
|
|
|
|
ImageContentStub func(imageRef, targetFile string) (v1.Image, error)
|
|
|
|
ImageInfoStub func(imageRef string) (v1.Image, error)
|
2022-03-23 11:02:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// DownloadImage .
|
|
|
|
func (c *DownloadMock) DownloadImage(imageRef, targetDir string) (v1.Image, error) {
|
|
|
|
c.ImageRef = imageRef
|
|
|
|
c.FilePath = targetDir
|
|
|
|
|
|
|
|
if c.Stub != nil {
|
|
|
|
return c.Stub(imageRef, targetDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(c.ReturnError) > 0 {
|
|
|
|
return nil, fmt.Errorf(c.ReturnError)
|
|
|
|
}
|
|
|
|
return c.ReturnImage, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DownloadImageContent .
|
|
|
|
func (c *DownloadMock) DownloadImageContent(imageRef, targetFile string) (v1.Image, error) {
|
|
|
|
c.ImageRef = imageRef
|
|
|
|
c.FilePath = targetFile
|
|
|
|
|
2023-07-06 11:34:05 +02:00
|
|
|
if c.ImageContentStub != nil {
|
|
|
|
return c.ImageContentStub(imageRef, targetFile)
|
|
|
|
}
|
|
|
|
|
2022-03-23 11:02:00 +02:00
|
|
|
if len(c.ReturnError) > 0 {
|
|
|
|
return nil, fmt.Errorf(c.ReturnError)
|
|
|
|
}
|
|
|
|
return c.ReturnImage, nil
|
|
|
|
}
|
2022-03-30 13:58:16 +02:00
|
|
|
|
|
|
|
// GetRemoteImageInfo .
|
|
|
|
func (c *DownloadMock) GetRemoteImageInfo(imageRef string) (v1.Image, error) {
|
|
|
|
c.RemoteImageRef = imageRef
|
|
|
|
|
2023-07-06 11:34:05 +02:00
|
|
|
if c.ImageInfoStub != nil {
|
|
|
|
return c.ImageInfoStub(imageRef)
|
|
|
|
}
|
|
|
|
|
2022-03-30 13:58:16 +02:00
|
|
|
if len(c.ReturnError) > 0 {
|
|
|
|
return nil, fmt.Errorf(c.ReturnError)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.RemoteImageInfo, nil
|
|
|
|
}
|