daveshanley / vacuum

vacuum is the worlds fastest OpenAPI 3, OpenAPI 2 / Swagger linter and quality analysis tool. Built in go, it tears through API specs faster than you can think. vacuum is compatible with Spectral rulesets and generates compatible reports.
https://quobix.com/vacuum
MIT License
577 stars 48 forks source link

JUnit report's root attributes are always zero #501

Closed ksinica closed 2 months ago

ksinica commented 4 months ago

Thanks for the fantastic work on this project. I just wanted to report that the JUnit generator has some missing bits that could be interpreted as false negatives by some parsers. The root element has "tests" and "failures" attributes set to zero always, regardless of the results. It could be easily fixed, though: 

diff --git a/vacuum-report/junit.go b/vacuum-report/junit.go
index 3aa78ca..95019d1 100644
--- a/vacuum-report/junit.go
+++ b/vacuum-report/junit.go
@@ -60,6 +61,8 @@ func BuildJUnitReport(resultSet *model.RuleResultSet, t time.Time) []byte {

        parsedTemplate, _ := template.New("failure").Parse(tmpl)

+       gf, gtc := 0, 0 // global failure count, global test cases count.
+
        // try a category print out.
        for _, val := range cats {
                categoryResults := resultSet.GetResultsByRuleCategory(val.Id)
@@ -72,6 +75,7 @@ func BuildJUnitReport(resultSet *model.RuleResultSet, t time.Time) []byte {
                        _ = parsedTemplate.Execute(&sb, r)
                        if r.Rule.Severity == model.SeverityError || r.Rule.Severity == model.SeverityWarn {
                                f++
+                               gf++
                        }
                        tc = append(tc, &TestCase{
                                Name:      fmt.Sprintf("Category: %s", val.Id),
@@ -96,10 +100,14 @@ func BuildJUnitReport(resultSet *model.RuleResultSet, t time.Time) []byte {

                        suites = append(suites, ts)
                }
+
+               gtc += len(tc)
        }

        allSuites := &TestSuites{
                TestSuites: suites,
+               Tests:      gtc,
+               Failures:   gf,
        }
daveshanley commented 4 months ago

All PRs are welcome! Please feel free to submit this change and become part of the community!

daveshanley commented 2 months ago

Fixed in v0.11.0. This patch was applied manually.