Documentation
¶
Overview ¶
Package junit models JUnit XML test reports and provides encoding, decoding, and a markdown renderer. Aside from the repo-wide perf tracking helper it has no Atmos dependencies, so it can be reused by any producer of test results (terraform/opentofu test, the `junit` workflow step, etc.).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMarshal indicates the report could not be encoded to XML. ErrMarshal = errors.New("failed to encode JUnit XML") // ErrParse indicates the input could not be decoded as JUnit XML. ErrParse = errors.New("failed to parse JUnit XML") )
Static errors (the repo bans dynamic errors; these keep the package dependency-free).
Functions ¶
Types ¶
type Case ¶
type Case struct {
Name string `xml:"name,attr"`
Classname string `xml:"classname,attr,omitempty"`
File string `xml:"file,attr,omitempty"`
Line int `xml:"line,attr,omitempty"`
Time float64 `xml:"time,attr,omitempty"`
Failure *Detail `xml:"failure,omitempty"`
Error *Detail `xml:"error,omitempty"`
Skipped *Detail `xml:"skipped,omitempty"`
}
Case is a JUnit `<testcase>` — one per test/run. Exactly one of Failure, Error, or Skipped is set for non-passing cases; all nil means the case passed. File/Line are optional attributes many CI test reporters and editors honor.
type Detail ¶
type Detail struct {
Message string `xml:"message,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
Text string `xml:",chardata"`
}
Detail is the body of a `<failure>`, `<error>`, or `<skipped>` element: a short Message attribute plus optional Text content.
type FailureRef ¶
FailureRef is a flattened reference to a failing/errored case, for callers that build CI annotations (which live outside this dependency-free package).
type Options ¶
type Options struct {
// Title is the heading shown above the report (e.g. "Terraform tests").
// Defaults to "Test results" when empty.
Title string
}
Options controls how Markdown renders a report.
type Report ¶
type Report struct {
XMLName xml.Name `xml:"testsuites"`
Name string `xml:"name,attr,omitempty"`
Tests int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Errors int `xml:"errors,attr"`
Skipped int `xml:"skipped,attr"`
Time float64 `xml:"time,attr,omitempty"`
Suites []Suite `xml:"testsuite"`
}
Report is the JUnit `<testsuites>` root: a collection of suites with rolled-up counts.
func Parse ¶
Parse decodes JUnit XML into a Report. It accepts both a `<testsuites>` root and a bare `<testsuite>` root (which is wrapped into a single-suite report), since test runners differ on which they emit.
func (*Report) Aggregate ¶
func (r *Report) Aggregate()
Aggregate recomputes each suite's counts from its cases and the report's totals from its suites, so callers can build a Report by appending cases and let the library fill in the attribute counts.
func (*Report) FailedCases ¶
func (r *Report) FailedCases() []FailureRef
FailedCases returns one FailureRef per failing or errored case across all suites (named to avoid colliding with the Failures count field).
type Suite ¶
type Suite struct {
Name string `xml:"name,attr"`
Tests int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Errors int `xml:"errors,attr"`
Skipped int `xml:"skipped,attr"`
Time float64 `xml:"time,attr,omitempty"`
Cases []Case `xml:"testcase"`
}
Suite is a JUnit `<testsuite>` — typically one per test file.