-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
48 lines (41 loc) · 964 Bytes
/
report.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
package uistrategy
import (
"encoding/json"
"os"
)
func (web *Web) buildReport(allActions []*ViewAction) {
vrs := make(ViewReport)
for _, v := range allActions {
actions := make(ActionsReport)
vrs[v.Name] = ViewReportItem{
Message: v.message,
Actions: actions,
}
for _, ap := range v.ElementActions {
vrs[v.Name].Actions[ap.Name] = ActionReportItem{
Message: ap.message,
Screenshot: ap.screenshot,
Errored: ap.errored,
Output: ap.capturedOutput,
}
}
}
web.flushReport(vrs)
}
func (web *Web) flushReport(report ViewReport) error {
file := `.report/report.json`
w, err := os.OpenFile(file, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
web.log.Debugf("unable to get a writer: %v", err)
return err
}
b, err := json.Marshal(report)
if err != nil {
return err
}
if _, err := w.Write(b); err != nil {
web.log.Errorf("failed to write report: %v", err)
return err
}
return nil
}