2021-12-22 16:34:36 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
|
|
|
)
|
|
|
|
|
|
|
|
type gradleExecuteBuildMockUtils struct {
|
|
|
|
*mock.ExecMockRunner
|
|
|
|
*mock.FilesMock
|
|
|
|
}
|
|
|
|
|
2022-03-21 11:17:03 +02:00
|
|
|
func (f gradleExecuteBuildMockUtils) DirExists(path string) (bool, error) {
|
|
|
|
return strings.EqualFold(path, "path/to/"), nil
|
2021-12-22 16:34:36 +02:00
|
|
|
}
|
|
|
|
|
2022-03-21 11:17:03 +02:00
|
|
|
func (f gradleExecuteBuildMockUtils) FileExists(filePath string) (bool, error) {
|
|
|
|
return strings.EqualFold(filePath, "path/to/build.gradle"), nil
|
2021-12-22 16:34:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func newGradleExecuteBuildTestsUtils() gradleExecuteBuildMockUtils {
|
|
|
|
utils := gradleExecuteBuildMockUtils{
|
|
|
|
ExecMockRunner: &mock.ExecMockRunner{},
|
|
|
|
FilesMock: &mock.FilesMock{},
|
|
|
|
}
|
|
|
|
return utils
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunGradleExecuteBuild(t *testing.T) {
|
|
|
|
|
|
|
|
t.Run("negative case - build.gradle isn't present", func(t *testing.T) {
|
|
|
|
options := &gradleExecuteBuildOptions{
|
2022-01-24 16:08:39 +02:00
|
|
|
Path: "path/to/project/",
|
2021-12-22 16:34:36 +02:00
|
|
|
}
|
|
|
|
u := newShellExecuteTestsUtils()
|
|
|
|
|
2022-03-21 11:17:03 +02:00
|
|
|
err := runGradleExecuteBuild(options, nil, u)
|
|
|
|
assert.EqualError(t, err, "the specified gradle build script could not be found")
|
2021-12-22 16:34:36 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("success case - build.gradle is present", func(t *testing.T) {
|
|
|
|
o := &gradleExecuteBuildOptions{
|
2022-01-24 16:08:39 +02:00
|
|
|
Path: "path/to/",
|
2021-12-22 16:34:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u := newGradleExecuteBuildTestsUtils()
|
|
|
|
|
2022-03-21 11:17:03 +02:00
|
|
|
err := runGradleExecuteBuild(o, nil, u)
|
2021-12-22 16:34:36 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|