mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
f855658e06
* Flesh out piperutils.Files and mock.FilesMock functionality * Avoid a lot of code-duplication via embedding
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
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{}
|
|
|
|
mockedUtils := mock.FilesMock{}
|
|
|
|
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, "install")
|
|
})
|
|
|
|
t.Run("mavenBuild should skip integration tests", func(t *testing.T) {
|
|
execMockRunner := mock.ExecMockRunner{}
|
|
|
|
mockedUtils := mock.FilesMock{}
|
|
mockedUtils.AddFile("integration-tests/pom.xml", []byte{})
|
|
|
|
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")
|
|
})
|
|
|
|
t.Run("mavenBuild should flatten", func(t *testing.T) {
|
|
execMockRunner := mock.ExecMockRunner{}
|
|
|
|
mockedUtils := mock.FilesMock{}
|
|
|
|
config := mavenBuildOptions{Flatten: true}
|
|
|
|
err := runMavenBuild(&config, nil, &execMockRunner, &mockedUtils)
|
|
|
|
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{}
|
|
|
|
mockedUtils := mock.FilesMock{}
|
|
|
|
config := mavenBuildOptions{Verify: true}
|
|
|
|
err := runMavenBuild(&config, nil, &execMockRunner, &mockedUtils)
|
|
|
|
assert.Nil(t, err)
|
|
assert.Contains(t, execMockRunner.Calls[0].Params, "verify")
|
|
assert.NotContains(t, execMockRunner.Calls[0].Params, "install")
|
|
})
|
|
|
|
}
|