This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.go
222 lines (187 loc) · 5.16 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package tester
import (
"fmt"
"time"
"github.com/google/uuid"
)
// TBState represents the completion state of a `testing.TB`.
type TBState string
const (
// TBStatePassed represents a passed test.
TBStatePassed TBState = "passed"
// TBFailed represents a failed test.
TBStateFailed TBState = "failed"
// TBSkipped represents a skipped test.
TBStateSkipped TBState = "skipped"
)
// TB is the representation of the common fields of a testing.TB.
type TB struct {
Name string `json:"name"`
StartedAt time.Time `json:"started_at"`
FinishedAt time.Time `json:"finished_at"`
State TBState `json:"state"`
}
// Duration returns the run duration the Test.
func (c *TB) Duration() time.Duration {
return c.FinishedAt.Sub(c.StartedAt)
}
type TBLog struct {
Time time.Time `json:"time"`
Name string `json:"name"`
Output []byte `json:"output"`
}
// T represents the results of a `testing.T`.
type T struct {
TB
SubTs []*T `json:"sub_ts"`
}
// Test is a run of a `testing.T`.
type Test struct {
ID uuid.UUID `json:"id"`
Package string `json:"package"`
RunID uuid.UUID `json:"run_id"`
Result *T `json:"result"`
Logs []TBLog `json:"logs"`
}
// Run is the representation of a pending test or benchmark that has not
// completed.
type Run struct {
ID uuid.UUID `json:"id"`
Package string `json:"package"`
Args []string `json:"args"`
Meta RunMeta `json:"meta"`
EnqueuedAt time.Time `json:"enqueued_at"`
StartedAt time.Time `json:"started_at"`
FinishedAt time.Time `json:"finished_at"`
Tests []*Test `json:"tests"`
Error string `json:"error"`
}
// RunMeta is additional metadata associated with the run.
type RunMeta struct {
Runner string `json:"runner"`
}
func (r *Run) Duration() time.Duration {
return r.FinishedAt.Sub(r.StartedAt)
}
// Package represents a go package that can be tested or benchmarked.
type Package struct {
Name string `json:"name"`
Path string `json:"path"`
SHA256Sum string `json:"sha256sum"`
RunDelay time.Duration `json:"run_delay"`
Options []Option `json:"options"`
}
// Option represents an option for how a package can be run.
type Option struct {
Name string `json:"name"`
Value string `json:"value"`
Description string `json:"description"`
Default string `json:"default"`
}
// String returns a string representation of the option.
func (o *Option) String() string {
return fmt.Sprintf("-%s=%s", o.Name, o.Value)
}
type RunSummary struct {
Time time.Time
Duration time.Duration
PackageSummary map[string]*PackageSummary
}
func (s *RunSummary) NumRuns() int {
var total int
for _, pkgSummary := range s.PackageSummary {
total += len(pkgSummary.RunIDs)
}
return total
}
func (s *RunSummary) NumErrorRuns() int {
var total int
for _, pkgSummary := range s.PackageSummary {
total += len(pkgSummary.ErrorRunIDs)
}
return total
}
func (s *RunSummary) NumPassedTests() int {
var total int
for _, pkgSummary := range s.PackageSummary {
total += pkgSummary.NumPassedTests()
}
return total
}
func (s *RunSummary) PercentPassedTests() float64 {
return float64(s.NumPassedTests()) / float64(s.NumTotalTests())
}
func (s *RunSummary) NumFailedTests() int {
var total int
for _, pkgSummary := range s.PackageSummary {
total += pkgSummary.NumFailedTests()
}
return total
}
func (s *RunSummary) PercentFailedTests() float64 {
return float64(s.NumFailedTests()) / float64(s.NumTotalTests())
}
func (s *RunSummary) NumSkippedTests() int {
var total int
for _, pkgSummary := range s.PackageSummary {
total += pkgSummary.NumSkippedTests()
}
return total
}
func (s *RunSummary) PercentSkippedTests() float64 {
return float64(s.NumSkippedTests()) / float64(s.NumTotalTests())
}
func (s *RunSummary) NumTotalTests() int {
var (
passed int
failed int
skipped int
)
for _, pkgSummary := range s.PackageSummary {
passed += pkgSummary.NumPassedTests()
failed += pkgSummary.NumFailedTests()
skipped += pkgSummary.NumSkippedTests()
}
return passed + failed + skipped
}
type PackageSummary struct {
Package string
RunIDs []uuid.UUID
ErrorRunIDs []uuid.UUID
PassedTests map[string][]uuid.UUID
FailedTests map[string][]uuid.UUID
SkippedTests map[string][]uuid.UUID
}
func (s *PackageSummary) NumPassedTests() int {
var total int
for _, tests := range s.PassedTests {
total += len(tests)
}
return total
}
func (s *PackageSummary) PercentPassedTests() float64 {
return float64(s.NumPassedTests()) / float64(s.NumTotalTests())
}
func (s *PackageSummary) NumFailedTests() int {
var total int
for _, tests := range s.FailedTests {
total += len(tests)
}
return total
}
func (s *PackageSummary) PercentFailedTests() float64 {
return float64(s.NumFailedTests()) / float64(s.NumTotalTests())
}
func (s *PackageSummary) NumSkippedTests() int {
var total int
for _, tests := range s.SkippedTests {
total += len(tests)
}
return total
}
func (s *PackageSummary) PercentSkippedTests() float64 {
return float64(s.NumSkippedTests()) / float64(s.NumTotalTests())
}
func (s *PackageSummary) NumTotalTests() int {
return s.NumPassedTests() + s.NumFailedTests() + s.NumSkippedTests()
}