2022-01-11 11:01:15 +02:00
|
|
|
package cnbutils_test
|
2021-09-14 16:14:50 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-01-11 11:01:15 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/cnbutils"
|
2021-09-14 16:14:50 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
2022-08-18 10:03:24 +02:00
|
|
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
|
|
|
fakeImage "github.com/google/go-containerregistry/pkg/v1/fake"
|
2021-09-14 16:14:50 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuildpackDownload(t *testing.T) {
|
2022-01-11 11:01:15 +02:00
|
|
|
var mockUtils = &cnbutils.MockUtils{
|
|
|
|
ExecMockRunner: &mock.ExecMockRunner{},
|
|
|
|
FilesMock: &mock.FilesMock{},
|
2022-08-18 10:03:24 +02:00
|
|
|
DownloadMock: &mock.DownloadMock{},
|
2022-01-11 11:01:15 +02:00
|
|
|
}
|
|
|
|
|
2022-03-30 13:58:16 +02:00
|
|
|
t.Run("it creates an order object", func(t *testing.T) {
|
2022-08-18 10:03:24 +02:00
|
|
|
fakeImg := &fakeImage.FakeImage{}
|
|
|
|
fakeImg.ConfigFileReturns(&v1.ConfigFile{
|
|
|
|
Config: v1.Config{
|
|
|
|
Labels: map[string]string{
|
|
|
|
"io.buildpacks.buildpackage.metadata": "{\"id\": \"testbuildpack\", \"version\": \"0.0.1\"}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil)
|
|
|
|
mockUtils.ReturnImage = fakeImg
|
|
|
|
mockUtils.RemoteImageInfo = fakeImg
|
|
|
|
|
2022-03-30 13:58:16 +02:00
|
|
|
order, err := cnbutils.DownloadBuildpacks("/destination", []string{"buildpack"}, "/tmp/config.json", mockUtils)
|
2022-08-18 10:03:24 +02:00
|
|
|
|
2021-09-14 16:14:50 +02:00
|
|
|
assert.NoError(t, err)
|
2022-03-30 13:58:16 +02:00
|
|
|
assert.Equal(t, 1, len(order.Order))
|
2021-09-14 16:14:50 +02:00
|
|
|
})
|
|
|
|
}
|