2023-05-03 18:02:11 +02:00
|
|
|
//go:build unit
|
|
|
|
// +build unit
|
|
|
|
|
2021-11-16 16:02:57 +02:00
|
|
|
package buildsettings
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateBuildSettingsInfo(t *testing.T) {
|
|
|
|
|
|
|
|
t.Run("test build settings cpe with no previous and existing values", func(t *testing.T) {
|
|
|
|
testTableConfig := []struct {
|
|
|
|
config BuildOptions
|
|
|
|
buildTool string
|
|
|
|
expected string
|
|
|
|
}{
|
2022-02-21 10:16:48 +02:00
|
|
|
{
|
|
|
|
config: BuildOptions{CreateBOM: true},
|
|
|
|
buildTool: "golangBuild",
|
|
|
|
expected: "{\"golangBuild\":[{\"createBOM\":true}]}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
config: BuildOptions{DockerImage: "golang:latest"},
|
|
|
|
buildTool: "golangBuild",
|
|
|
|
expected: "{\"golangBuild\":[{\"dockerImage\":\"golang:latest\"}]}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
config: BuildOptions{CreateBOM: true},
|
|
|
|
buildTool: "gradleBuild",
|
|
|
|
expected: "{\"gradleBuild\":[{\"createBOM\":true}]}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
config: BuildOptions{Publish: true},
|
|
|
|
buildTool: "helmExecute",
|
|
|
|
expected: "{\"helmExecute\":[{\"publish\":true}]}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
config: BuildOptions{Publish: true},
|
|
|
|
buildTool: "kanikoExecute",
|
|
|
|
expected: "{\"kanikoExecute\":[{\"publish\":true}]}",
|
|
|
|
},
|
2021-11-16 16:02:57 +02:00
|
|
|
{
|
|
|
|
config: BuildOptions{Profiles: []string{"profile1", "profile2"}, CreateBOM: true},
|
|
|
|
buildTool: "mavenBuild",
|
|
|
|
expected: "{\"mavenBuild\":[{\"profiles\":[\"profile1\",\"profile2\"],\"createBOM\":true}]}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
config: BuildOptions{Profiles: []string{"profile1", "profile2"}, CreateBOM: true, BuildSettingsInfo: "{\"mavenBuild\":[{\"createBOM\":true}]}"},
|
|
|
|
buildTool: "mavenBuild",
|
|
|
|
expected: "{\"mavenBuild\":[{\"createBOM\":true},{\"profiles\":[\"profile1\",\"profile2\"],\"createBOM\":true}]}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
config: BuildOptions{Profiles: []string{"release.build"}, Publish: true, GlobalSettingsFile: "http://nexus.test:8081/nexus/"},
|
|
|
|
buildTool: "mtaBuild",
|
|
|
|
expected: "{\"mtaBuild\":[{\"profiles\":[\"release.build\"],\"publish\":true,\"globalSettingsFile\":\"http://nexus.test:8081/nexus/\"}]}",
|
|
|
|
},
|
2022-02-21 10:16:48 +02:00
|
|
|
{
|
|
|
|
config: BuildOptions{CreateBOM: true},
|
|
|
|
buildTool: "pythonBuild",
|
|
|
|
expected: "{\"pythonBuild\":[{\"createBOM\":true}]}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
config: BuildOptions{CreateBOM: true},
|
|
|
|
buildTool: "npmExecuteScripts",
|
|
|
|
expected: "{\"npmExecuteScripts\":[{\"createBOM\":true}]}",
|
|
|
|
},
|
2022-06-14 15:14:44 +02:00
|
|
|
{
|
|
|
|
config: BuildOptions{DockerImage: "builder:latest"},
|
|
|
|
buildTool: "cnbBuild",
|
|
|
|
expected: "{\"cnbBuild\":[{\"dockerImage\":\"builder:latest\"}]}",
|
|
|
|
},
|
2021-11-16 16:02:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testTableConfig {
|
2022-02-21 10:16:48 +02:00
|
|
|
buildSettings, err := CreateBuildSettingsInfo(&testCase.config, testCase.buildTool)
|
2021-11-16 16:02:57 +02:00
|
|
|
assert.Nil(t, err)
|
2022-02-21 10:16:48 +02:00
|
|
|
assert.Equal(t, buildSettings, testCase.expected)
|
2021-11-16 16:02:57 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|