2022-01-11 11:01:15 +02:00
|
|
|
//go:build !release
|
2021-09-14 16:14:50 +02:00
|
|
|
// +build !release
|
|
|
|
|
|
|
|
package cnbutils
|
|
|
|
|
|
|
|
import (
|
2022-03-23 11:02:00 +02:00
|
|
|
"fmt"
|
2022-01-11 11:01:15 +02:00
|
|
|
"path/filepath"
|
2021-09-14 16:14:50 +02:00
|
|
|
|
|
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/piperutils"
|
|
|
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
|
|
|
fakeImage "github.com/google/go-containerregistry/pkg/v1/fake"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MockUtils struct {
|
|
|
|
*mock.ExecMockRunner
|
|
|
|
*mock.FilesMock
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockUtils) GetFileUtils() piperutils.FileUtils {
|
|
|
|
return c.FilesMock
|
|
|
|
}
|
|
|
|
|
2022-03-23 11:02:00 +02:00
|
|
|
func (c *MockUtils) DownloadImageContent(bpack, targetDir string) (v1.Image, error) {
|
2021-09-14 16:14:50 +02:00
|
|
|
fakeImage := fakeImage.FakeImage{}
|
|
|
|
fakeImage.ConfigFileReturns(&v1.ConfigFile{
|
|
|
|
Config: v1.Config{
|
|
|
|
Labels: map[string]string{
|
|
|
|
"io.buildpacks.buildpackage.metadata": "{\"id\": \"testbuildpack\", \"version\": \"0.0.1\"}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil)
|
2022-01-11 11:01:15 +02:00
|
|
|
|
2022-03-23 11:02:00 +02:00
|
|
|
c.AddDir(filepath.Join(targetDir, "cnb/buildpacks", bpack))
|
|
|
|
c.AddDir(filepath.Join(targetDir, "cnb/buildpacks", bpack, "0.0.1"))
|
|
|
|
return &fakeImage, nil
|
2021-09-14 16:14:50 +02:00
|
|
|
}
|
|
|
|
|
2022-03-23 11:02:00 +02:00
|
|
|
func (c *MockUtils) DownloadImage(src, dst string) (v1.Image, error) {
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
2021-09-14 16:14:50 +02:00
|
|
|
}
|
|
|
|
|
2022-03-23 11:02:00 +02:00
|
|
|
func (c *MockUtils) GetImageSource() (string, error) {
|
|
|
|
return "imageSource", nil
|
2021-09-14 16:14:50 +02:00
|
|
|
}
|
2022-03-30 13:58:16 +02:00
|
|
|
|
|
|
|
func (c *MockUtils) GetRemoteImageInfo(imageSource string) (v1.Image, error) {
|
|
|
|
fakeImage := fakeImage.FakeImage{}
|
|
|
|
fakeImage.ConfigFileReturns(&v1.ConfigFile{
|
|
|
|
Config: v1.Config{
|
|
|
|
Labels: map[string]string{
|
|
|
|
"io.buildpacks.buildpackage.metadata": "{\"id\": \"testbuildpack\", \"version\": \"0.0.1\"}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil)
|
|
|
|
fakeImage.DigestReturns(v1.Hash{}, nil)
|
|
|
|
|
|
|
|
return &fakeImage, nil
|
|
|
|
}
|