forked from SAP/jenkins-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmavenExecuteIntegration_test.go
146 lines (128 loc) · 3.59 KB
/
mavenExecuteIntegration_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package cmd
import (
"errors"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/stretchr/testify/assert"
"net/http"
"path/filepath"
"testing"
)
type mavenExecuteIntegrationTestUtilsBundle struct {
*mock.ExecMockRunner
*mock.FilesMock
}
func (m mavenExecuteIntegrationTestUtilsBundle) DownloadFile(url, filename string, header http.Header, cookies []*http.Cookie) error {
return errors.New("Test should not download files.")
}
func TestIntegrationTestModuleDoesNotExist(t *testing.T) {
t.Parallel()
utils := newMavenIntegrationTestsUtilsBundle()
config := mavenExecuteIntegrationOptions{}
err := runMavenExecuteIntegration(&config, utils)
assert.EqualError(t, err, "maven module 'integration-tests' does not exist in project structure")
}
func TestHappyPathIntegrationTests(t *testing.T) {
t.Parallel()
utils := newMavenIntegrationTestsUtilsBundle()
utils.FilesMock.AddFile("integration-tests/pom.xml", []byte(`<project> </project>`))
config := mavenExecuteIntegrationOptions{
Retry: 2,
ForkCount: "1C",
Goal: "post-integration-test",
}
err := runMavenExecuteIntegration(&config, utils)
if err != nil {
t.Fatalf("Error %s", err)
}
expectedParameters1 := []string{
"--file",
filepath.Join(".", "integration-tests", "pom.xml"),
"-Dsurefire.rerunFailingTestsCount=2",
"-Dsurefire.forkCount=1C",
"-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn",
"--batch-mode",
"org.jacoco:jacoco-maven-plugin:prepare-agent",
"post-integration-test",
}
assert.Equal(t, mock.ExecCall{Exec: "mvn", Params: expectedParameters1}, utils.ExecMockRunner.Calls[0])
}
func TestInvalidForkCountParam(t *testing.T) {
t.Parallel()
// init
utils := newMavenIntegrationTestsUtilsBundle()
utils.FilesMock.AddFile("integration-tests/pom.xml", []byte(`<project> </project>`))
// test
err := runMavenExecuteIntegration(&mavenExecuteIntegrationOptions{ForkCount: "4.2"}, utils)
// assert
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "invalid forkCount parameter")
}
}
func TestValidateForkCount(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
testValue string
expectedError string
}{
{
name: "valid integer",
testValue: "2",
expectedError: "",
},
{
name: "zero is valid",
testValue: "0",
expectedError: "",
},
{
name: "valid floating point",
testValue: "2.5C",
expectedError: "",
},
{
name: "valid integer with C",
testValue: "2C",
expectedError: "",
},
{
name: "invalid floating point",
testValue: "1.2",
expectedError: "invalid forkCount parameter",
},
{
name: "invalid",
testValue: "C1",
expectedError: "invalid forkCount parameter",
},
{
name: "another invalid",
testValue: "1 C",
expectedError: "invalid forkCount parameter",
},
{
name: "invalid float",
testValue: "1..2C",
expectedError: "invalid forkCount parameter",
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
err := validateForkCount(testCase.testValue)
if testCase.expectedError == "" {
assert.NoError(t, err)
} else if assert.Error(t, err) {
assert.Contains(t, err.Error(), testCase.expectedError)
}
})
}
}
func newMavenIntegrationTestsUtilsBundle() *mavenExecuteIntegrationTestUtilsBundle {
utilsBundle := mavenExecuteIntegrationTestUtilsBundle{
ExecMockRunner: &mock.ExecMockRunner{},
FilesMock: &mock.FilesMock{},
}
return &utilsBundle
}