Correctly attribute some datastructures from gotestsum repository

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas
2022-03-30 21:27:21 -04:00
parent 978d9683f5
commit 108e3e28a9
6 changed files with 490 additions and 51 deletions

View File

@@ -22,55 +22,10 @@ import (
"fmt"
"io"
"os"
"k8s.io/kubernetes/third_party/forked/gotestsum/junitxml"
)
// JUnitTestSuites is a collection of JUnit test suites.
type JUnitTestSuites struct {
XMLName xml.Name `xml:"testsuites"`
Suites []JUnitTestSuite `xml:"testsuite"`
}
// JUnitTestSuite is a single JUnit test suite which may contain many
// testcases.
type JUnitTestSuite struct {
XMLName xml.Name `xml:"testsuite"`
Tests int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Time string `xml:"time,attr"`
Name string `xml:"name,attr"`
Properties []JUnitProperty `xml:"properties>property,omitempty"`
TestCases []JUnitTestCase `xml:"testcase"`
Timestamp string `xml:"timestamp,attr"`
}
// JUnitTestCase is a single test case with its result.
type JUnitTestCase struct {
XMLName xml.Name `xml:"testcase"`
Classname string `xml:"classname,attr"`
Name string `xml:"name,attr"`
Time string `xml:"time,attr"`
SkipMessage *JUnitSkipMessage `xml:"skipped,omitempty"`
Failure *JUnitFailure `xml:"failure,omitempty"`
}
// JUnitSkipMessage contains the reason why a testcase was skipped.
type JUnitSkipMessage struct {
Message string `xml:"message,attr"`
}
// JUnitProperty represents a key/value pair used to define properties.
type JUnitProperty struct {
Name string `xml:"name,attr"`
Value string `xml:"value,attr"`
}
// JUnitFailure contains data related to a failed test.
type JUnitFailure struct {
Message string `xml:"message,attr"`
Type string `xml:"type,attr"`
Contents string `xml:",chardata"`
}
func main() {
maxTextSize := flag.Int("max-text-size", 1, "maximum size of attribute or text (in MB)")
flag.Parse()
@@ -104,7 +59,7 @@ func main() {
}
}
func pruneXML(suites *JUnitTestSuites, maxBytes int) {
func pruneXML(suites *junitxml.JUnitTestSuites, maxBytes int) {
for _, suite := range suites.Suites {
for _, testcase := range suite.TestCases {
if testcase.SkipMessage != nil {
@@ -125,9 +80,9 @@ func pruneXML(suites *JUnitTestSuites, maxBytes int) {
}
}
func fetchXML(xmlReader io.Reader) (*JUnitTestSuites, error) {
func fetchXML(xmlReader io.Reader) (*junitxml.JUnitTestSuites, error) {
decoder := xml.NewDecoder(xmlReader)
var suites JUnitTestSuites
var suites junitxml.JUnitTestSuites
err := decoder.Decode(&suites)
if err != nil {
return nil, err
@@ -135,7 +90,7 @@ func fetchXML(xmlReader io.Reader) (*JUnitTestSuites, error) {
return &suites, nil
}
func streamXML(writer io.Writer, in *JUnitTestSuites) error {
func streamXML(writer io.Writer, in *junitxml.JUnitTestSuites) error {
_, err := writer.Write([]byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"))
if err != nil {
return err