test(agentcompat): add evidence validation

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
naiba
2026-07-20 04:50:03 +00:00
co-authored by naiba/CloudCode
parent 1c3e926819
commit b3b3d92895
16 changed files with 1901 additions and 0 deletions
@@ -0,0 +1,46 @@
package evidence
import "encoding/xml"
type junitSuite struct {
XMLName xml.Name `xml:"testsuite"`
Name string `xml:"name,attr"`
Tests int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Cases []junitCase `xml:"testcase"`
}
type junitCase struct {
Name string `xml:"name,attr"`
Failure *junitFailure `xml:"failure,omitempty"`
}
type junitFailure struct {
Message string `xml:"message,attr"`
}
func JUnit(results Results) ([]byte, error) {
if err := results.Validate(); err != nil {
return nil, err
}
suite := junitSuite{Name: results.Profile, Tests: len(results.Scenarios)}
for _, scenario := range results.Scenarios {
caseResult := junitCase{Name: scenario.Name}
if !scenario.Passed {
suite.Failures++
caseResult.Failure = &junitFailure{Message: Redact(scenario.Error)}
}
suite.Cases = append(suite.Cases, caseResult)
}
return xml.Marshal(suite)
}
func countFailedScenarios(scenarios []ScenarioResult) int {
failed := 0
for _, scenario := range scenarios {
if !scenario.Passed {
failed++
}
}
return failed
}