diff options
author | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-08-05 15:56:10 -0500 |
---|---|---|
committer | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-08-05 15:56:10 -0500 |
commit | 72a70b127636ae8a83e2a2bd53b69143e3c5ded0 (patch) | |
tree | fdddf5cccdb487d63909f97074d111e67c79ded7 /adapters/gtest/results.go | |
parent | f90a14d5d723c5d2b87f2eaa19f441dec33bb9b2 (diff) | |
download | deb-planr-72a70b127636ae8a83e2a2bd53b69143e3c5ded0.tar.xz deb-planr-72a70b127636ae8a83e2a2bd53b69143e3c5ded0.zip |
Runtime & reorganziation
Diffstat (limited to 'adapters/gtest/results.go')
-rw-r--r-- | adapters/gtest/results.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/adapters/gtest/results.go b/adapters/gtest/results.go new file mode 100644 index 0000000..f8c8a23 --- /dev/null +++ b/adapters/gtest/results.go @@ -0,0 +1,75 @@ +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"` +} + +func decodeResults(r io.Reader) []planr.TestResult { + 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([]planr.TestResult, 0) + for _, suite := range results.Testsuites { + for _, test := range suite.Testsuite { + n := len(test.Failures) + + decoded = append(decoded, planr.TestResult { + Id: suite.Name + "_" + test.Name, + Pass: n == 0, + }) + } + } + + return decoded +} |