@@ -54,6 +54,7 @@ func main() {
54
54
}
55
55
56
56
const coverageDir = ".build/coverage"
57
+ const junitDir = ".build/junit-xml"
57
58
58
59
type builder struct {
59
60
thisDir string
@@ -117,7 +118,7 @@ func (b *builder) integrationTest() error {
117
118
runFlag := flagSet .String ("run" , "" , "Passed to go test as -run" )
118
119
devServerFlag := flagSet .Bool ("dev-server" , false , "Use an embedded dev server" )
119
120
coverageFileFlag := flagSet .String ("coverage-file" , "" , "If set, enables coverage output to this filename" )
120
- junitFileFlag := flagSet .String ("junitfile " , "junit-xml " , "If set, a path prefix to which junit-style xml files should be written " )
121
+ junitFileStem := flagSet .String ("junit-file-stem " , "" , "If set, an identifier to be used to construct junit xml output file names " )
121
122
if err := flagSet .Parse (os .Args [2 :]); err != nil {
122
123
return fmt .Errorf ("failed parsing flags: %w" , err )
123
124
}
@@ -138,6 +139,13 @@ func (b *builder) integrationTest() error {
138
139
}
139
140
}
140
141
142
+ // Create junit XML output dir if junit XML output requested
143
+ if * junitFileStem != "" {
144
+ if err := os .MkdirAll (filepath .Join (b .rootDir , junitDir ), 0777 ); err != nil {
145
+ return fmt .Errorf ("failed creating junit xml dir: %w" , err )
146
+ }
147
+ }
148
+
141
149
// Start dev server if wanted
142
150
if * devServerFlag {
143
151
devServer , err := testsuite .StartDevServer (context .Background (), testsuite.DevServerOptions {
@@ -178,10 +186,12 @@ func (b *builder) integrationTest() error {
178
186
// Run integration test
179
187
args := []string {
180
188
gotestsum ,
181
- "--junitfile" , * junitFileFlag + "-integration-test.xml" ,
182
- "--" ,
183
- "-tags" , "protolegacy" , "-count" , "1" , "-race" , "-v" , "-timeout" , "10m" ,
184
189
}
190
+ if * junitFileStem != "" {
191
+ args = append (args , "--junitfile" , filepath .Join (b .rootDir , junitDir , * junitFileStem + "-integration-test.xml" ))
192
+ }
193
+ args = append (args , "--" , "-tags" , "protolegacy" , "-count" , "1" , "-race" , "-v" , "-timeout" , "10m" )
194
+
185
195
if * runFlag != "" {
186
196
args = append (args , "-run" , * runFlag )
187
197
}
@@ -244,7 +254,7 @@ func (b *builder) unitTest() error {
244
254
flagSet := flag .NewFlagSet ("unit-test" , flag .ContinueOnError )
245
255
runFlag := flagSet .String ("run" , "" , "Passed to go test as -run" )
246
256
coverageFlag := flagSet .Bool ("coverage" , false , "If set, enables coverage output" )
247
- junitFileFlag := flagSet .String ("junitfile " , "junit-xml " , "If set, a path prefix to which junit-style xml files should be written " )
257
+ junitFileStem := flagSet .String ("junit-file-stem " , "" , "If set, an identifier to be used to construct junit xml output file names " )
248
258
if err := flagSet .Parse (os .Args [2 :]); err != nil {
249
259
return fmt .Errorf ("failed parsing flags: %w" , err )
250
260
}
@@ -278,16 +288,24 @@ func (b *builder) unitTest() error {
278
288
}
279
289
}
280
290
291
+ // Create junit XML output dir if junit XML output requested
292
+ if * junitFileStem != "" {
293
+ if err := os .MkdirAll (filepath .Join (b .rootDir , junitDir ), 0777 ); err != nil {
294
+ return fmt .Errorf ("failed creating junit xml dir: %w" , err )
295
+ }
296
+ }
297
+
281
298
// Run unit test for each dir
282
299
log .Printf ("Running unit tests in dirs: %v" , testDirs )
283
300
for _ , testDir := range testDirs {
284
301
// Run unit test
285
302
args := []string {
286
303
gotestsum ,
287
- "--junitfile" , * junitFileFlag + strings .ReplaceAll (testDir , "/" , "-" ) + "unit-test.xml" ,
288
- "--" ,
289
- "-tags" , "protolegacy" , "-count" , "1" , "-race" , "-v" , "-timeout" , "15m" ,
290
304
}
305
+ if * junitFileStem != "" {
306
+ args = append (args , "--junitfile" , filepath .Join (b .rootDir , junitDir , * junitFileStem + "-" + strings .ReplaceAll (testDir , "/" , "-" )+ "-unit-test.xml" ))
307
+ }
308
+ args = append (args , "--" , "-tags" , "protolegacy" , "-count" , "1" , "-race" , "-v" , "-timeout" , "15m" )
291
309
if * runFlag != "" {
292
310
args = append (args , "-run" , * runFlag )
293
311
}
0 commit comments