2021-12-22 16:34:36 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-04-14 14:59:09 +02:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2021-12-22 16:34:36 +02:00
|
|
|
"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
|
|
|
}
|
|
|
|
|
2022-04-14 14:59:09 +02:00
|
|
|
func (f gradleExecuteBuildMockUtils) DownloadFile(url, filename string, header http.Header, cookies []*http.Cookie) error {
|
|
|
|
return fmt.Errorf("not implemented")
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2022-04-14 14:59:09 +02:00
|
|
|
u := newGradleExecuteBuildTestsUtils()
|
2021-12-22 16:34:36 +02:00
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|