|
2 | 2 | package common |
3 | 3 |
|
4 | 4 | import ( |
| 5 | + "encoding/xml" |
5 | 6 | "fmt" |
6 | 7 | "io/ioutil" |
7 | 8 | "log" |
@@ -168,6 +169,40 @@ func runTestsInPhase(t *testing.T, cfg *config.Config, phase string, description |
168 | 169 | phaseReportPath := filepath.Join(phaseDirectory, fmt.Sprintf("junit_%v.xml", cfg.Suffix)) |
169 | 170 | phaseReporter := reporters.NewJUnitReporter(phaseReportPath) |
170 | 171 | ginkgo.RunSpecsWithDefaultAndCustomReporters(t, description, []ginkgo.Reporter{phaseReporter}) |
| 172 | + |
| 173 | + files, err := ioutil.ReadDir(phaseDirectory) |
| 174 | + if err != nil { |
| 175 | + t.Fatalf("error reading phase directory: %s", err.Error()) |
| 176 | + } |
| 177 | + |
| 178 | + for _, file := range files { |
| 179 | + if file != nil { |
| 180 | + // Process the jUnit XML result files |
| 181 | + if junitFileRegex.MatchString(file.Name()) { |
| 182 | + data, err := ioutil.ReadFile(filepath.Join(phaseDirectory, file.Name())) |
| 183 | + if err != nil { |
| 184 | + t.Fatalf("error opening junit file %s: %s", file.Name(), err.Error()) |
| 185 | + } |
| 186 | + // Use Ginkgo's JUnitTestSuite to unmarshal the JUnit XML file |
| 187 | + var testSuite reporters.JUnitTestSuite |
| 188 | + |
| 189 | + if err = xml.Unmarshal(data, &testSuite); err != nil { |
| 190 | + t.Fatalf("error unmarshalling junit xml: %s", err.Error()) |
| 191 | + } |
| 192 | + |
| 193 | + for i, testcase := range testSuite.TestCases { |
| 194 | + testSuite.TestCases[i].Name = fmt.Sprintf("[%s] %s", phase, testcase.Name) |
| 195 | + } |
| 196 | + |
| 197 | + data, err = xml.Marshal(&testSuite) |
| 198 | + |
| 199 | + err = ioutil.WriteFile(filepath.Join(phaseDirectory, file.Name()), data, 0644) |
| 200 | + if err != nil { |
| 201 | + t.Fatalf("error writing to junit file: %s", err.Error()) |
| 202 | + } |
| 203 | + } |
| 204 | + } |
| 205 | + } |
171 | 206 | } |
172 | 207 |
|
173 | 208 | // checkBeforeMetricsGeneration runs a variety of checks before generating metrics. |
|
0 commit comments