mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
ffc931aad1
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files. * Added unit build tag to all unit test files. * added to new unit test unit build tag * Update verify-go.yml * small fix --------- Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.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, "(1, 1): parsing error: keys cannot contain { character")
|
|
})
|
|
}
|