5
5
"fmt"
6
6
"io"
7
7
"os"
8
+ "strings"
8
9
"time"
9
10
10
11
"github.com/ctrf-io/go-ctrf-json-reporter/ctrf"
@@ -35,7 +36,7 @@ func ParseTestResults(r io.Reader, verbose bool, env *ctrf.Environment) (*ctrf.R
35
36
36
37
report := ctrf .NewReport ("gotest" , env )
37
38
report .Results .Summary .Start = time .Now ().UnixNano () / int64 (time .Millisecond )
38
- for _ , event := range testEvents {
39
+ for i , event := range testEvents {
39
40
if verbose {
40
41
jsonEvent , err := json .Marshal (event )
41
42
if err != nil {
@@ -76,6 +77,7 @@ func ParseTestResults(r io.Reader, verbose bool, env *ctrf.Environment) (*ctrf.R
76
77
Name : event .Test ,
77
78
Status : ctrf .TestFailed ,
78
79
Duration : duration ,
80
+ Message : getMessagesForTest (testEvents , i , event .Package , event .Test ),
79
81
})
80
82
} else if event .Action == "skip" {
81
83
report .Results .Summary .Tests ++
@@ -91,6 +93,20 @@ func ParseTestResults(r io.Reader, verbose bool, env *ctrf.Environment) (*ctrf.R
91
93
}
92
94
return report , nil
93
95
}
96
+ func getMessagesForTest (testEvents []TestEvent , index int , packageName , testName string ) string {
97
+ var messages []string
98
+ for i := index ; i >= 0 ; i -- {
99
+ if testEvents [i ].Package == packageName && testEvents [i ].Test == testName {
100
+ if testEvents [i ].Action == "output" {
101
+ messages = append (messages , testEvents [i ].Output )
102
+ }
103
+ } else {
104
+ break
105
+ }
106
+ }
107
+ reverse (messages )
108
+ return strings .Join (messages , "" )
109
+ }
94
110
95
111
func WriteReportToFile (filename string , report * ctrf.Report ) error {
96
112
err := report .WriteFile (filename )
@@ -105,10 +121,16 @@ func secondsToMillis(seconds float64) int64 {
105
121
return int64 (seconds * 1000 )
106
122
}
107
123
108
- func parseTimeString (timeString string ) (int64 , error ) {
124
+ func parseTimeString (timeString string ) (int64 , error ) {
109
125
t , err := time .Parse (time .RFC3339Nano , timeString )
110
126
if err != nil {
111
127
return 0 , err
112
128
}
113
129
return t .UnixNano () / int64 (time .Millisecond ), nil
114
130
}
131
+
132
+ func reverse (s []string ) {
133
+ for i , j := 0 , len (s )- 1 ; i < j ; i , j = i + 1 , j - 1 {
134
+ s [i ], s [j ] = s [j ], s [i ]
135
+ }
136
+ }
0 commit comments