mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
610e212306
* Add pre and post buildpacks Co-authored-by: Johannes Dillmann <j.dillmann@sap.com> Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com> Co-authored-by: Pavel Busko <pavel.busko@sap.com> * fix integration tests Co-authored-by: Pavel Busko <pavel.busko@sap.com> Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com> * simplify if clauses Co-authored-by: Pavel Busko <pavel.busko@sap.com> --------- Co-authored-by: Johannes Dillmann <j.dillmann@sap.com> Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
//go:build unit
|
|
// +build unit
|
|
|
|
package cnbutils_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/cnbutils"
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestDigestFromReport(t *testing.T) {
|
|
t.Run("return a digest from the report.toml", func(t *testing.T) {
|
|
mockUtils := &cnbutils.MockUtils{
|
|
FilesMock: &mock.FilesMock{},
|
|
}
|
|
mockUtils.AddFile("/layers/report.toml", []byte(`[build]
|
|
[image]
|
|
digest = "sha256:52eac630560210e5ae13eb10797c4246d6f02d425f32b9430ca00bde697c79ec"
|
|
`))
|
|
digest, err := cnbutils.DigestFromReport(mockUtils)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "sha256:52eac630560210e5ae13eb10797c4246d6f02d425f32b9430ca00bde697c79ec", digest)
|
|
})
|
|
|
|
t.Run("fails if digest is empty", func(t *testing.T) {
|
|
mockUtils := &cnbutils.MockUtils{
|
|
ExecMockRunner: &mock.ExecMockRunner{},
|
|
FilesMock: &mock.FilesMock{},
|
|
}
|
|
mockUtils.AddFile("/layers/report.toml", []byte(``))
|
|
|
|
digest, err := cnbutils.DigestFromReport(mockUtils)
|
|
assert.Empty(t, digest)
|
|
assert.EqualError(t, err, "image digest is empty")
|
|
})
|
|
|
|
t.Run("fails to unmarshal corrupted file", func(t *testing.T) {
|
|
mockUtils := &cnbutils.MockUtils{
|
|
ExecMockRunner: &mock.ExecMockRunner{},
|
|
FilesMock: &mock.FilesMock{},
|
|
}
|
|
mockUtils.AddFile("/layers/report.toml", []byte(`{}`))
|
|
|
|
digest, err := cnbutils.DigestFromReport(mockUtils)
|
|
assert.Empty(t, digest)
|
|
assert.EqualError(t, err, "toml: line 1: expected '.' or '=', but got '{' instead")
|
|
})
|
|
}
|