2020-03-13 14:32:37 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-02-25 16:01:19 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-03-13 14:32:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMavenBuild(t *testing.T) {
|
|
|
|
t.Run("mavenBuild should install the artifact", func(t *testing.T) {
|
2020-11-10 18:14:55 +02:00
|
|
|
mockedUtils := newMavenMockUtils()
|
2020-03-26 09:23:21 +02:00
|
|
|
|
2020-03-13 14:32:37 +02:00
|
|
|
config := mavenBuildOptions{}
|
|
|
|
|
2020-11-10 18:14:55 +02:00
|
|
|
err := runMavenBuild(&config, nil, &mockedUtils)
|
2020-03-13 14:32:37 +02:00
|
|
|
|
|
|
|
assert.Nil(t, err)
|
2020-11-10 18:14:55 +02:00
|
|
|
assert.Equal(t, mockedUtils.Calls[0].Exec, "mvn")
|
|
|
|
assert.Contains(t, mockedUtils.Calls[0].Params, "install")
|
2020-03-13 14:32:37 +02:00
|
|
|
})
|
|
|
|
|
2020-03-26 09:23:21 +02:00
|
|
|
t.Run("mavenBuild should skip integration tests", func(t *testing.T) {
|
2020-11-10 18:14:55 +02:00
|
|
|
mockedUtils := newMavenMockUtils()
|
2020-06-15 09:47:33 +02:00
|
|
|
mockedUtils.AddFile("integration-tests/pom.xml", []byte{})
|
2020-03-26 09:23:21 +02:00
|
|
|
|
|
|
|
config := mavenBuildOptions{}
|
|
|
|
|
2020-11-10 18:14:55 +02:00
|
|
|
err := runMavenBuild(&config, nil, &mockedUtils)
|
2020-03-26 09:23:21 +02:00
|
|
|
|
|
|
|
assert.Nil(t, err)
|
2020-11-10 18:14:55 +02:00
|
|
|
assert.Equal(t, mockedUtils.Calls[0].Exec, "mvn")
|
|
|
|
assert.Contains(t, mockedUtils.Calls[0].Params, "-pl", "!integration-tests")
|
2020-03-26 09:23:21 +02:00
|
|
|
})
|
|
|
|
|
2020-03-13 14:32:37 +02:00
|
|
|
t.Run("mavenBuild should flatten", func(t *testing.T) {
|
2020-11-10 18:14:55 +02:00
|
|
|
mockedUtils := newMavenMockUtils()
|
2020-03-26 09:23:21 +02:00
|
|
|
|
2020-03-13 14:32:37 +02:00
|
|
|
config := mavenBuildOptions{Flatten: true}
|
|
|
|
|
2020-11-10 18:14:55 +02:00
|
|
|
err := runMavenBuild(&config, nil, &mockedUtils)
|
2020-03-13 14:32:37 +02:00
|
|
|
|
|
|
|
assert.Nil(t, err)
|
2020-11-10 18:14:55 +02:00
|
|
|
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")
|
2020-03-13 14:32:37 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("mavenBuild should run only verify", func(t *testing.T) {
|
2020-11-10 18:14:55 +02:00
|
|
|
mockedUtils := newMavenMockUtils()
|
2020-03-26 09:23:21 +02:00
|
|
|
|
2020-03-13 14:32:37 +02:00
|
|
|
config := mavenBuildOptions{Verify: true}
|
|
|
|
|
2020-11-10 18:14:55 +02:00
|
|
|
err := runMavenBuild(&config, nil, &mockedUtils)
|
2020-03-13 14:32:37 +02:00
|
|
|
|
|
|
|
assert.Nil(t, err)
|
2020-11-10 18:14:55 +02:00
|
|
|
assert.Contains(t, mockedUtils.Calls[0].Params, "verify")
|
|
|
|
assert.NotContains(t, mockedUtils.Calls[0].Params, "install")
|
2020-03-13 14:32:37 +02:00
|
|
|
})
|
|
|
|
|
2021-02-25 16:01:19 +02:00
|
|
|
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")
|
|
|
|
})
|
|
|
|
|
2021-06-01 09:24:36 +02:00
|
|
|
t.Run("mavenBuild include install and deploy when publish is true", func(t *testing.T) {
|
|
|
|
mockedUtils := newMavenMockUtils()
|
|
|
|
|
|
|
|
config := mavenBuildOptions{Publish: true, Verify: false}
|
|
|
|
|
|
|
|
err := runMavenBuild(&config, nil, &mockedUtils)
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Contains(t, mockedUtils.Calls[0].Params, "install")
|
|
|
|
assert.NotContains(t, mockedUtils.Calls[0].Params, "verify")
|
|
|
|
assert.Contains(t, mockedUtils.Calls[1].Params, "deploy")
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("mavenBuild with deploy must skip build, install and test", func(t *testing.T) {
|
|
|
|
mockedUtils := newMavenMockUtils()
|
|
|
|
|
|
|
|
config := mavenBuildOptions{Publish: true, Verify: false}
|
|
|
|
|
|
|
|
err := runMavenBuild(&config, nil, &mockedUtils)
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Contains(t, mockedUtils.Calls[1].Params, "-Dmaven.main.skip=true")
|
|
|
|
assert.Contains(t, mockedUtils.Calls[1].Params, "-Dmaven.test.skip=true")
|
|
|
|
assert.Contains(t, mockedUtils.Calls[1].Params, "-Dmaven.install.skip=true")
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("mavenBuild with deploy must include alt repo id and url when passed as parameter", func(t *testing.T) {
|
|
|
|
mockedUtils := newMavenMockUtils()
|
|
|
|
|
|
|
|
config := mavenBuildOptions{Publish: true, Verify: false, AltDeploymentRepositoryID: "ID", AltDeploymentRepositoryURL: "http://sampleRepo.com"}
|
|
|
|
|
|
|
|
err := runMavenBuild(&config, nil, &mockedUtils)
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Contains(t, mockedUtils.Calls[1].Params, "-DaltDeploymentRepository=ID::default::http://sampleRepo.com")
|
|
|
|
})
|
|
|
|
|
2021-06-18 11:57:00 +02:00
|
|
|
t.Run("mavenBuild accepts profiles", func(t *testing.T) {
|
|
|
|
mockedUtils := newMavenMockUtils()
|
|
|
|
|
|
|
|
config := mavenBuildOptions{Profiles: []string{"profile1", "profile2"}}
|
|
|
|
|
|
|
|
err := runMavenBuild(&config, nil, &mockedUtils)
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Contains(t, mockedUtils.Calls[0].Params, "--activate-profiles")
|
|
|
|
assert.Contains(t, mockedUtils.Calls[0].Params, "profile1,profile2")
|
|
|
|
})
|
|
|
|
|
2020-03-13 14:32:37 +02:00
|
|
|
}
|