1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/mavenBuild_test.go
Nikolai Demidenko eb87a2c976
Add createBOM parameter to the mavenBuild step (#2639)
* Add createBOM parameter to the mavenBuild step

* update generated files

* Update resources/metadata/mavenBuild.yaml

* Update resources/metadata/mavenBuild.yaml

* update generated mavenBuild

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2021-02-25 15:01:19 +01:00

81 lines
2.6 KiB
Go

package cmd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMavenBuild(t *testing.T) {
t.Run("mavenBuild should install the artifact", func(t *testing.T) {
mockedUtils := newMavenMockUtils()
config := mavenBuildOptions{}
err := runMavenBuild(&config, nil, &mockedUtils)
assert.Nil(t, err)
assert.Equal(t, mockedUtils.Calls[0].Exec, "mvn")
assert.Contains(t, mockedUtils.Calls[0].Params, "install")
})
t.Run("mavenBuild should skip integration tests", func(t *testing.T) {
mockedUtils := newMavenMockUtils()
mockedUtils.AddFile("integration-tests/pom.xml", []byte{})
config := mavenBuildOptions{}
err := runMavenBuild(&config, nil, &mockedUtils)
assert.Nil(t, err)
assert.Equal(t, mockedUtils.Calls[0].Exec, "mvn")
assert.Contains(t, mockedUtils.Calls[0].Params, "-pl", "!integration-tests")
})
t.Run("mavenBuild should flatten", func(t *testing.T) {
mockedUtils := newMavenMockUtils()
config := mavenBuildOptions{Flatten: true}
err := runMavenBuild(&config, nil, &mockedUtils)
assert.Nil(t, err)
assert.Contains(t, mockedUtils.Calls[0].Params, "flatten:flatten")
assert.Contains(t, mockedUtils.Calls[0].Params, "-Dflatten.mode=resolveCiFriendliesOnly")
assert.Contains(t, mockedUtils.Calls[0].Params, "-DupdatePomFile=true")
})
t.Run("mavenBuild should run only verify", func(t *testing.T) {
mockedUtils := newMavenMockUtils()
config := mavenBuildOptions{Verify: true}
err := runMavenBuild(&config, nil, &mockedUtils)
assert.Nil(t, err)
assert.Contains(t, mockedUtils.Calls[0].Params, "verify")
assert.NotContains(t, mockedUtils.Calls[0].Params, "install")
})
t.Run("mavenBuild should createBOM", func(t *testing.T) {
mockedUtils := newMavenMockUtils()
config := mavenBuildOptions{CreateBOM: true}
err := runMavenBuild(&config, nil, &mockedUtils)
assert.Nil(t, err)
assert.Contains(t, mockedUtils.Calls[0].Params, "org.cyclonedx:cyclonedx-maven-plugin:makeAggregateBom")
assert.Contains(t, mockedUtils.Calls[0].Params, "-DschemaVersion=1.2")
assert.Contains(t, mockedUtils.Calls[0].Params, "-DincludeBomSerialNumber=true")
assert.Contains(t, mockedUtils.Calls[0].Params, "-DincludeCompileScope=true")
assert.Contains(t, mockedUtils.Calls[0].Params, "-DincludeProvidedScope=true")
assert.Contains(t, mockedUtils.Calls[0].Params, "-DincludeRuntimeScope=true")
assert.Contains(t, mockedUtils.Calls[0].Params, "-DincludeSystemScope=true")
assert.Contains(t, mockedUtils.Calls[0].Params, "-DincludeTestScope=false")
assert.Contains(t, mockedUtils.Calls[0].Params, "-DincludeLicenseText=false")
assert.Contains(t, mockedUtils.Calls[0].Params, "-DoutputFormat=xml")
})
}