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,35 +43,49 @@ 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
- Name : event .Test ,
51
- Status : ctrf .TestPassed ,
52
- Duration : secondsToMillis (event .Elapsed ),
53
- })
54
- } else if event .Action == "fail" {
55
- report .Results .Summary .Tests ++
56
- report .Results .Summary .Failed ++
57
- report .Results .Tests = append (report .Results .Tests , & ctrf.TestResult {
58
- Name : event .Test ,
59
- Status : ctrf .TestFailed ,
60
- Duration : secondsToMillis (event .Elapsed ),
61
- })
62
- } else if event .Action == "skip" {
63
- report .Results .Summary .Tests ++
64
- report .Results .Summary .Skipped ++
65
- report .Results .Tests = append (report .Results .Tests , & ctrf.TestResult {
66
- Name : event .Test ,
67
- Status : ctrf .TestSkipped ,
68
- Duration : secondsToMillis (event .Elapsed ),
69
- })
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
70
60
}
71
61
}
72
- }
73
62
63
+ if event .Action == "pass" {
64
+ report .Results .Summary .Tests ++
65
+ report .Results .Summary .Passed ++
66
+ report .Results .Tests = append (report .Results .Tests , & ctrf.TestResult {
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
+ Name : event .Test ,
76
+ Status : ctrf .TestFailed ,
77
+ Duration : duration ,
78
+ })
79
+ } else if event .Action == "skip" {
80
+ report .Results .Summary .Tests ++
81
+ report .Results .Summary .Skipped ++
82
+ report .Results .Tests = append (report .Results .Tests , & ctrf.TestResult {
83
+ Name : event .Test ,
84
+ Status : ctrf .TestSkipped ,
85
+ Duration : duration ,
86
+ })
87
+ }
88
+ }
74
89
return report , nil
75
90
}
76
91
@@ -87,3 +102,17 @@ func WriteReportToFile(filename string, report *ctrf.Report) error {
87
102
func secondsToMillis (seconds float64 ) int64 {
88
103
return int64 (seconds * 1000 )
89
104
}
105
+ func parseTimeString (timeString string ) (int64 , error ) {
106
+ // Define the layout for parsing the time string
107
+ layout := time .RFC3339Nano
108
+
109
+ // Parse the time string
110
+ t , err := time .Parse (layout , timeString )
111
+ if err != nil {
112
+ return 0 , err
113
+ }
114
+
115
+ // Convert the time to Unix timestamp in milliseconds
116
+ timestamp := t .UnixNano () / int64 (time .Millisecond )
117
+ return timestamp , nil
118
+ }
0 commit comments