1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/cmd/mavenBuild_test.go

69 lines
1.9 KiB
Go
Raw Normal View History

2020-03-13 14:32:37 +02:00
package cmd
import (
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/stretchr/testify/assert"
"testing"
)
func TestMavenBuild(t *testing.T) {
t.Run("mavenBuild should install the artifact", func(t *testing.T) {
execMockRunner := mock.ExecMockRunner{}
2020-03-26 09:23:21 +02:00
mockedUtils := mock.FilesMock{}
2020-03-13 14:32:37 +02:00
config := mavenBuildOptions{}
2020-03-26 09:23:21 +02:00
err := runMavenBuild(&config, nil, &execMockRunner, &mockedUtils)
2020-03-13 14:32:37 +02:00
assert.Nil(t, err)
assert.Equal(t, execMockRunner.Calls[0].Exec, "mvn")
assert.Contains(t, execMockRunner.Calls[0].Params, "install")
})
2020-03-26 09:23:21 +02:00
t.Run("mavenBuild should skip integration tests", func(t *testing.T) {
execMockRunner := mock.ExecMockRunner{}
mockedUtils := mock.FilesMock{}
mockedUtils.Files = []string{"integration-tests/pom.xml"}
config := mavenBuildOptions{}
err := runMavenBuild(&config, nil, &execMockRunner, &mockedUtils)
assert.Nil(t, err)
assert.Equal(t, execMockRunner.Calls[0].Exec, "mvn")
assert.Contains(t, execMockRunner.Calls[0].Params, "-pl", "!integration-tests")
})
2020-03-13 14:32:37 +02:00
t.Run("mavenBuild should flatten", func(t *testing.T) {
execMockRunner := mock.ExecMockRunner{}
2020-03-26 09:23:21 +02:00
mockedUtils := mock.FilesMock{}
2020-03-13 14:32:37 +02:00
config := mavenBuildOptions{Flatten: true}
2020-03-26 09:23:21 +02:00
err := runMavenBuild(&config, nil, &execMockRunner, &mockedUtils)
2020-03-13 14:32:37 +02:00
assert.Nil(t, err)
assert.Contains(t, execMockRunner.Calls[0].Params, "flatten:flatten")
assert.Contains(t, execMockRunner.Calls[0].Params, "-Dflatten.mode=resolveCiFriendliesOnly")
assert.Contains(t, execMockRunner.Calls[0].Params, "-DupdatePomFile=true")
})
t.Run("mavenBuild should run only verify", func(t *testing.T) {
execMockRunner := mock.ExecMockRunner{}
2020-03-26 09:23:21 +02:00
mockedUtils := mock.FilesMock{}
2020-03-13 14:32:37 +02:00
config := mavenBuildOptions{Verify: true}
2020-03-26 09:23:21 +02:00
err := runMavenBuild(&config, nil, &execMockRunner, &mockedUtils)
2020-03-13 14:32:37 +02:00
assert.Nil(t, err)
assert.Contains(t, execMockRunner.Calls[0].Params, "verify")
assert.NotContains(t, execMockRunner.Calls[0].Params, "install")
})
}