@@ -54,6 +54,7 @@ func main() {
5454}
5555
5656const coverageDir = ".build/coverage"
57+ const junitDir = ".build/junit-xml"
5758
5859type builder struct {
5960 thisDir string
@@ -117,7 +118,7 @@ func (b *builder) integrationTest() error {
117118 runFlag := flagSet .String ("run" , "" , "Passed to go test as -run" )
118119 devServerFlag := flagSet .Bool ("dev-server" , false , "Use an embedded dev server" )
119120 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 " )
121122 if err := flagSet .Parse (os .Args [2 :]); err != nil {
122123 return fmt .Errorf ("failed parsing flags: %w" , err )
123124 }
@@ -138,6 +139,13 @@ func (b *builder) integrationTest() error {
138139 }
139140 }
140141
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+
141149 // Start dev server if wanted
142150 if * devServerFlag {
143151 devServer , err := testsuite .StartDevServer (context .Background (), testsuite.DevServerOptions {
@@ -178,10 +186,12 @@ func (b *builder) integrationTest() error {
178186 // Run integration test
179187 args := []string {
180188 gotestsum ,
181- "--junitfile" , * junitFileFlag + "-integration-test.xml" ,
182- "--" ,
183- "-tags" , "protolegacy" , "-count" , "1" , "-race" , "-v" , "-timeout" , "10m" ,
184189 }
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+
185195 if * runFlag != "" {
186196 args = append (args , "-run" , * runFlag )
187197 }
@@ -244,7 +254,7 @@ func (b *builder) unitTest() error {
244254 flagSet := flag .NewFlagSet ("unit-test" , flag .ContinueOnError )
245255 runFlag := flagSet .String ("run" , "" , "Passed to go test as -run" )
246256 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 " )
248258 if err := flagSet .Parse (os .Args [2 :]); err != nil {
249259 return fmt .Errorf ("failed parsing flags: %w" , err )
250260 }
@@ -278,16 +288,24 @@ func (b *builder) unitTest() error {
278288 }
279289 }
280290
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+
281298 // Run unit test for each dir
282299 log .Printf ("Running unit tests in dirs: %v" , testDirs )
283300 for _ , testDir := range testDirs {
284301 // Run unit test
285302 args := []string {
286303 gotestsum ,
287- "--junitfile" , * junitFileFlag + strings .ReplaceAll (testDir , "/" , "-" ) + "unit-test.xml" ,
288- "--" ,
289- "-tags" , "protolegacy" , "-count" , "1" , "-race" , "-v" , "-timeout" , "15m" ,
290304 }
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" )
291309 if * runFlag != "" {
292310 args = append (args , "-run" , * runFlag )
293311 }
0 commit comments