This repository was archived by the owner on Jul 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertor.go
More file actions
100 lines (87 loc) · 1.7 KB
/
convertor.go
File metadata and controls
100 lines (87 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package parse
import (
log "github.com/Sirupsen/logrus"
"strconv"
)
// Test Status
const (
Passed = "Passed"
Skipped = "Skipped"
Failed = "Failed"
Error = "Error"
)
type TestSet struct {
Name string
Time float64
Total int
Failures int
Errors int
Skipped int
Tests []Test
}
type Test struct {
Name string
Status string
Time float64
Failure string
Error string
}
func ToTestSet(junit []byte) (*TestSet, error) {
suite, err := toJunitTestSuite(junit)
if err != nil {
log.Error("Failed to parse junit xml", err, junit)
return nil, err
}
var ret TestSet
ret.Name = suite.Name
ret.Total = toInt(suite.Total)
ret.Failures = toInt(suite.Failures)
ret.Errors = toInt(suite.Errors)
ret.Skipped = toInt(suite.Skipped)
ret.Time = toFloat(suite.Time)
if len(suite.TestCases) > 0 {
for _, currTestCase := range suite.TestCases {
test := Test{
Name: currTestCase.Name,
Time: toFloat(currTestCase.Time),
Failure: currTestCase.Failure,
Error: currTestCase.Error,
}
test.Status = getStatus(currTestCase)
ret.Tests = append(ret.Tests, test)
}
}
return &ret, nil
}
func toFloat(val string) float64 {
ret, err := strconv.ParseFloat(val, 64)
if err != nil {
log.Error(err)
return -1
}
return ret
}
func toInt(val string) int {
//property not exist - we return 0
if val == "" {
return 0
}
ret, err := strconv.Atoi(val)
if err != nil {
log.Error(err)
return -1
}
return ret
}
func getStatus(test JunitTestCase) string {
ret := Passed
if test.Skipped.Local != "" {
log.Info("local:", test.Skipped.Local)
ret = Skipped
} else if test.Failure != "" {
ret = Failed
} else if test.Error != "" {
ret = Error
}
return ret
}