forked from SAP/jenkins-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradleExecuteBuild_test.go
62 lines (47 loc) · 1.47 KB
/
gradleExecuteBuild_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cmd
import (
"fmt"
"net/http"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/SAP/jenkins-library/pkg/mock"
)
type gradleExecuteBuildMockUtils struct {
*mock.ExecMockRunner
*mock.FilesMock
}
func (f gradleExecuteBuildMockUtils) DirExists(path string) (bool, error) {
return strings.EqualFold(path, "path/to/"), nil
}
func (f gradleExecuteBuildMockUtils) FileExists(filePath string) (bool, error) {
return strings.EqualFold(filePath, "path/to/build.gradle"), nil
}
func (f gradleExecuteBuildMockUtils) DownloadFile(url, filename string, header http.Header, cookies []*http.Cookie) error {
return fmt.Errorf("not implemented")
}
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{
Path: "path/to/project/",
}
u := newGradleExecuteBuildTestsUtils()
err := runGradleExecuteBuild(options, nil, u)
assert.EqualError(t, err, "the specified gradle build script could not be found")
})
t.Run("success case - build.gradle is present", func(t *testing.T) {
o := &gradleExecuteBuildOptions{
Path: "path/to/",
}
u := newGradleExecuteBuildTestsUtils()
err := runGradleExecuteBuild(o, nil, u)
assert.NoError(t, err)
})
}