Created
May 20, 2019 15:09
-
-
Save kevinearls/5bb03a99835cac96d11f30587b911779 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/xml" | |
"fmt" | |
"io/ioutil" | |
"os" | |
"strconv" | |
"strings" | |
) | |
type TestSuites struct { | |
XMLName xml.Name `xml:"testsuites"` | |
Suites []TestSuite `xml:"testsuite"` | |
} | |
type TestSuite struct { | |
XMLName xml.Name `xml:"testsuite"` | |
Tests string `xml:"tests,attr"` | |
Failures string `xml:"failures,attr"` | |
Time string `xml:"time,attr"` | |
Name string `xml:"name,attr"` | |
Properties Properties `xml:"properties"` | |
TestCases []TestCase `xml:"testcase"` | |
} | |
type Properties struct { | |
XMLName xml.Name `xml:"properties"` | |
Property []Property `xml:"property"` | |
} | |
type Property struct { | |
XMLName xml.Name `xml:"property"` | |
Name string `xml:"name,attr"` | |
Value string `xml:"value,attr"` | |
} | |
type TestCase struct { | |
XMLName xml.Name `xml:"testcase"` | |
ClassName string `xml:"classname,attr"` | |
Name string `xml:"name,attr"` | |
Time string `xml:"time,attr"` | |
Failure Failure `xml:"failure"` | |
} | |
type Failure struct { | |
XMLName xml.Name `xml:"failure"` | |
Message string `xml:"message,attr"` | |
FailureType string `xml:"type,attr"` | |
FailureContent string `xml:",cdata"` | |
} | |
var testsuites TestSuites | |
func main() { | |
xmlFileName := "/Users/kearls/go/src/github.com/jaegertracing/jaeger-operator/TEST-all-tests.xml" | |
bytes, err := ioutil.ReadFile(xmlFileName) | |
if err != nil { | |
fmt.Printf("Error attempting to read file [%s]: %s\n", xmlFileName, err) | |
os.Exit(1) | |
} | |
xml.Unmarshal(bytes, &testsuites) | |
for i:=0; i < len(testsuites.Suites); i++ { | |
newTestCases := make([]TestCase, 0) | |
j := 0 | |
for _, testCase := range testsuites.Suites[i].TestCases { | |
// TODO do we need to track skipped and error too? | |
// If the test case does not contain slash, we need to remove it and adjust the result | |
if !strings.Contains(testCase.Name, "/") { | |
isFailure := len(testCase.Failure.Message) > 0 | |
if isFailure { | |
currrentFailureCount, err := strconv.Atoi(testsuites.Suites[i].Failures) | |
if err != nil { | |
fmt.Printf("%s\n", err) | |
return | |
} | |
testsuites.Suites[i].Failures = strconv.Itoa(currrentFailureCount - 1) | |
} | |
currentTestCount, err := strconv.Atoi(testsuites.Suites[i].Tests) | |
if err != nil { | |
fmt.Printf("%s\n", err) | |
return | |
} | |
testsuites.Suites[i].Tests = strconv.Itoa(currentTestCount-1) | |
} else { | |
testCaseCopy := testCase | |
newTestCases = append(newTestCases, testCaseCopy) | |
j++ | |
} | |
} | |
fmt.Printf("Size of newTestCases: %d\n", len(newTestCases)) | |
testsuites.Suites[i].TestCases = newTestCases | |
//fmt.Printf(">>>> At end test count %s, failures %s\n", testsuites.Suites[i].Tests, testsuites.Suites[i].Failures) | |
} | |
stuff, err := xml.Marshal(testsuites) | |
if err != nil { | |
fmt.Printf("Failed with %s\n", err) | |
} | |
fmt.Println(string(stuff)) | |
//fmt.Println(testsuites) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment