5
5
"fmt"
6
6
"io"
7
7
"os"
8
+ "time"
8
9
9
10
"github.com/ctrf-io/go-ctrf-json-reporter/ctrf"
10
11
)
@@ -33,7 +34,7 @@ func ParseTestResults(r io.Reader, verbose bool, env *ctrf.Environment) (*ctrf.R
33
34
}
34
35
35
36
report := ctrf .NewReport ("gotest" , env )
36
-
37
+ report . Results . Summary . Start = time . Now (). UnixNano () / int64 ( time . Millisecond )
37
38
for _ , event := range testEvents {
38
39
if verbose {
39
40
jsonEvent , err := json .Marshal (event )
@@ -42,38 +43,52 @@ func ParseTestResults(r io.Reader, verbose bool, env *ctrf.Environment) (*ctrf.R
42
43
}
43
44
fmt .Println (string (jsonEvent ))
44
45
}
45
- if event .Test != "" {
46
- if event .Action == "pass" {
47
- report .Results .Summary .Tests ++
48
- report .Results .Summary .Passed ++
49
- report .Results .Tests = append (report .Results .Tests , & ctrf.TestResult {
50
- Suite : event .Package ,
51
- Name : event .Test ,
52
- Status : ctrf .TestPassed ,
53
- Duration : secondsToMillis (event .Elapsed ),
54
- })
55
- } else if event .Action == "fail" {
56
- report .Results .Summary .Tests ++
57
- report .Results .Summary .Failed ++
58
- report .Results .Tests = append (report .Results .Tests , & ctrf.TestResult {
59
- Suite : event .Package ,
60
- Name : event .Test ,
61
- Status : ctrf .TestFailed ,
62
- Duration : secondsToMillis (event .Elapsed ),
63
- })
64
- } else if event .Action == "skip" {
65
- report .Results .Summary .Tests ++
66
- report .Results .Summary .Skipped ++
67
- report .Results .Tests = append (report .Results .Tests , & ctrf.TestResult {
68
- Suite : event .Package ,
69
- Name : event .Test ,
70
- Status : ctrf .TestSkipped ,
71
- Duration : secondsToMillis (event .Elapsed ),
72
- })
46
+ if event .Test == "" {
47
+ continue
48
+ }
49
+ startTime , err := parseTimeString (event .Time )
50
+ duration := secondsToMillis (event .Elapsed )
51
+ if err != nil {
52
+ fmt .Fprintf (os .Stderr , "error parsing test event start time '%s' : %v\n " , event .Time , err )
53
+ } else {
54
+ if report .Results .Summary .Start > startTime {
55
+ report .Results .Summary .Start = startTime
56
+ }
57
+ endTime := startTime + duration
58
+ if report .Results .Summary .Stop < endTime {
59
+ report .Results .Summary .Stop = endTime
73
60
}
74
61
}
75
- }
62
+ if event .Action == "pass" {
63
+ report .Results .Summary .Tests ++
64
+ report .Results .Summary .Passed ++
65
+ report .Results .Tests = append (report .Results .Tests , & ctrf.TestResult {
66
+ Suite : event .Package ,
67
+ Name : event .Test ,
68
+ Status : ctrf .TestPassed ,
69
+ Duration : duration ,
70
+ })
71
+ } else if event .Action == "fail" {
72
+ report .Results .Summary .Tests ++
73
+ report .Results .Summary .Failed ++
74
+ report .Results .Tests = append (report .Results .Tests , & ctrf.TestResult {
75
+ Suite : event .Package ,
76
+ Name : event .Test ,
77
+ Status : ctrf .TestFailed ,
78
+ Duration : duration ,
79
+ })
80
+ } else if event .Action == "skip" {
81
+ report .Results .Summary .Tests ++
82
+ report .Results .Summary .Skipped ++
83
+ report .Results .Tests = append (report .Results .Tests , & ctrf.TestResult {
84
+ Suite : event .Package ,
85
+ Name : event .Test ,
86
+ Status : ctrf .TestSkipped ,
87
+ Duration : duration ,
88
+ })
89
+ }
76
90
91
+ }
77
92
return report , nil
78
93
}
79
94
@@ -82,11 +97,18 @@ func WriteReportToFile(filename string, report *ctrf.Report) error {
82
97
if err != nil {
83
98
return err
84
99
}
85
-
86
100
fmt .Println ("go-ctrf-json-reporter: successfully written ctrf json to" , filename )
87
101
return nil
88
102
}
89
103
90
104
func secondsToMillis (seconds float64 ) int64 {
91
105
return int64 (seconds * 1000 )
92
106
}
107
+
108
+ func parseTimeString (timeString string ) (int64 , error ) {
109
+ t , err := time .Parse (time .RFC3339Nano , timeString )
110
+ if err != nil {
111
+ return 0 , err
112
+ }
113
+ return t .UnixNano () / int64 (time .Millisecond ), nil
114
+ }
0 commit comments