-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
70 lines (57 loc) · 1.15 KB
/
types.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
package gotestfast
import (
"encoding/json"
"os"
"sort"
)
type (
ActionType string
Test struct {
Name string `json:"Output"`
Package string `json:"Package"`
Action string `json:"Action"`
}
Tests []Test
TestRecord struct {
Package string `json:"package"`
Name string `json:"name"`
Passed bool `json:"passed"`
details string `json:"-"`
}
TestRecords []TestRecord
)
const (
ActionTypeOutput = "output"
ActionTypePass = "pass"
)
func (records TestRecords) WriteToFile(filePath string) error {
records.Sort()
file, err := os.Create(filePath)
if err != nil {
return err
}
defer file.Close()
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
if err := encoder.Encode(records); err != nil {
return err
}
return nil
}
func (records TestRecords) Sort() {
sort.SliceStable(records, func(i, j int) bool {
return !records[i].Passed && records[j].Passed
})
}
func (tests Tests) ToRecord() []TestRecord {
var records []TestRecord
for _, test := range tests {
record := TestRecord{
Package: test.Package,
Name: test.Name,
Passed: false,
}
records = append(records, record)
}
return records
}