This repository has been 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
/
Copy pathanalytics_test.go
74 lines (65 loc) · 2.38 KB
/
analytics_test.go
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
package parse
import (
log "github.com/Sirupsen/logrus"
"github.com/stretchr/testify/assert"
"testing"
)
func TestToAnalyticsTestsFailedTest(t *testing.T) {
log.Info("TestToAnalyticsTestsFailedTest")
analyticsTests, err := ToAnalyticsTests([]byte(getMockMochaXunit2()))
assert.NoError(t, err)
assert.Equal(t, 5, len(analyticsTests))
analyticsTestSet := analyticsTests[0].TestSet
assert.Equal(t, FloatNumber(0.149), analyticsTestSet.Time)
assert.Equal(t, 5, analyticsTestSet.Total, "Total")
assert.Equal(t, 1, analyticsTestSet.Failures, "Failures")
assert.Equal(t, 1, analyticsTestSet.Errors, "Errors")
assert.Equal(t, 0, analyticsTestSet.Skipped, "Skipped")
failureAnalyticsTests := getFailureAnalyticsTests(analyticsTests)
assert.Equal(t, 1, len(failureAnalyticsTests))
assert.Equal(t, 1, failureAnalyticsTests[0].NumericStatus)
assert.Equal(t, 0, getPassedAnalyticsTests(analyticsTests)[0].NumericStatus)
}
func TestToAnalyticsTestsErrorTest(t *testing.T) {
log.Info("TestToAnalyticsTestsErrorTest")
analyticsTests, err := ToAnalyticsTests([]byte(getMockMochaXunitWithErrorTest()))
assert.NoError(t, err)
assert.Equal(t, 1, len(analyticsTests))
analyticsTestSet := analyticsTests[0].TestSet
assert.Equal(t, FloatNumber(0.003), analyticsTestSet.Time)
assert.Equal(t, 1, analyticsTestSet.Total, "Total")
assert.Equal(t, 0, analyticsTestSet.Failures, "Failures")
assert.Equal(t, 1, analyticsTestSet.Errors, "Errors")
assert.Equal(t, 0, analyticsTestSet.Skipped, "Skipped")
errorAnalyticsTests := getErrorAnalyticsTests(analyticsTests)
assert.Equal(t, 1, len(errorAnalyticsTests))
assert.Equal(t, 1, errorAnalyticsTests[0].NumericStatus)
assert.Equal(t, 0, len(getPassedAnalyticsTests(analyticsTests)))
}
func getFailureAnalyticsTests(tests []AnalyticsTest) []AnalyticsTest {
var ret []AnalyticsTest
for _, currTest := range tests {
if currTest.Failure != "" && currTest.Status == Failed {
ret = append(ret, currTest)
}
}
return ret
}
func getErrorAnalyticsTests(tests []AnalyticsTest) []AnalyticsTest {
var ret []AnalyticsTest
for _, currTest := range tests {
if currTest.Error != "" && currTest.Status == Error {
ret = append(ret, currTest)
}
}
return ret
}
func getPassedAnalyticsTests(tests []AnalyticsTest) []AnalyticsTest {
var ret []AnalyticsTest
for _, currTest := range tests {
if currTest.Status == Passed {
ret = append(ret, currTest)
}
}
return ret
}