package gtest import ( "bytes" "encoding/json" "io" "log" "time" "golang.flu0r1ne.net/planr" ) type gFailure struct { Failure string `json:"failure"` Type string `json:"type"` } type gTestsuite struct { Name string `json:"name"` Status string `json:"status"` Result string `json:"result"` Timestamp time.Time `json:"timestamp"` Time string `json:"time"` Classname string `json:"classname"` Failures []gFailure `json:"failures"` } type gTestsuites struct { Name string `json:"name"` Tests int `json:"tests"` Failures int `json:"failures"` Disabled int `json:"disabled"` Errors int `json:"errors"` Timestamp time.Time `json:"timestamp"` Time string `json:"time"` Testsuite []gTestsuite `json:"testsuite"` } type gResults struct { Tests int `json:"tests"` Failures int `json:"failures"` Disabled int `json:"disabled"` Errors int `json:"errors"` Timestamp time.Time `json:"timestamp"` Time string `json:"time"` Name string `json:"name"` Testsuites []gTestsuites `json:"testsuites"` } type Result struct { id string result planr.TestResult } func decodeResults(r io.Reader) []Result { var results gResults buf := bytes.Buffer{} if _, err := buf.ReadFrom(r); err != nil { log.Fatal(err) } if err := json.Unmarshal(buf.Bytes(), &results); err != nil { log.Fatal(err) } decoded := make([]Result, 0) for _, suite := range results.Testsuites { for _, test := range suite.Testsuite { n := len(test.Failures) decoded = append(decoded, Result{ id: suite.Name + "." + test.Name, result: planr.TestResult { Pass: n == 0, }, }) } } return decoded }