-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage_types_test.go
More file actions
252 lines (192 loc) · 5.71 KB
/
Copy pathcoverage_types_test.go
File metadata and controls
252 lines (192 loc) · 5.71 KB
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package auditlog_test
import (
"testing"
flow "github.com/Azure/go-workflow"
auditlog "github.com/larsartmann/go-workflow-auditlog"
testhelpers "github.com/larsartmann/go-workflow-auditlog/testhelpers"
)
// --- Event method tests ---
func TestEvent_ConvenienceMethods(t *testing.T) {
t.Parallel()
dur := 5.5
errMsg := "boom"
startEvent := auditlog.Event{
EventType: auditlog.EventTypeAttemptStart,
Phase: auditlog.PhaseBefore,
StepRef: auditlog.StepRef{Name: "step-a"},
DurationMs: &dur,
}
endEvent := auditlog.Event{
EventType: auditlog.EventTypeAttemptEnd,
Phase: auditlog.PhaseAfter,
Error: &errMsg,
Status: auditlog.StepStatusFailed,
}
if !startEvent.IsAttemptStart() {
t.Error("expected IsAttemptStart=true")
}
if startEvent.IsAttemptEnd() {
t.Error("expected IsAttemptEnd=false")
}
if !endEvent.IsAttemptEnd() {
t.Error("expected IsAttemptEnd=true")
}
if !startEvent.IsBefore() {
t.Error("expected IsBefore=true")
}
if !endEvent.IsAfter() {
t.Error("expected IsAfter=true")
}
if !endEvent.HasError() {
t.Error("expected HasError=true")
}
if startEvent.HasError() {
t.Error("expected HasError=false")
}
if startEvent.Duration() != 5.5 {
t.Errorf("expected Duration=5.5, got %f", startEvent.Duration())
}
if endEvent.Duration() != 0 {
t.Errorf("expected Duration=0, got %f", endEvent.Duration())
}
}
func TestEvent_Label(t *testing.T) {
t.Parallel()
if auditlog.EventTypeAttemptStart.Label() != "Attempt Start" {
t.Errorf("unexpected label: %s", auditlog.EventTypeAttemptStart.Label())
}
if auditlog.EventTypeAttemptEnd.Label() != "Attempt End" {
t.Errorf("unexpected label: %s", auditlog.EventTypeAttemptEnd.Label())
}
unknown := auditlog.EventType("unknown")
if unknown.Label() != "" {
t.Errorf("expected empty label for unknown type")
}
}
func TestEvent_Color(t *testing.T) {
t.Parallel()
if auditlog.EventTypeAttemptStart.Color() == "" {
t.Error("expected non-empty color")
}
unknown := auditlog.EventType("unknown")
if unknown.Color() != "" {
t.Error("expected empty color for unknown type")
}
}
// --- StepStatus method tests ---
func TestStepStatus_Methods(t *testing.T) {
t.Parallel()
if auditlog.StepStatusSucceeded.String() != "succeeded" {
t.Errorf("expected 'succeeded', got %s", auditlog.StepStatusSucceeded.String())
}
if auditlog.StepStatusSucceeded.Label() != "Succeeded" {
t.Errorf("expected 'Succeeded', got %s", auditlog.StepStatusSucceeded.Label())
}
if !auditlog.StepStatusFailed.IsTerminal() {
t.Error("expected Failed to be terminal")
}
if !auditlog.StepStatusSkipped.IsTerminal() {
t.Error("expected Skipped to be terminal")
}
if auditlog.StepStatusPending.IsTerminal() {
t.Error("expected Pending to NOT be terminal")
}
if auditlog.StepStatusRunning.IsTerminal() {
t.Error("expected Running to NOT be terminal")
}
if !auditlog.StepStatusFailed.IsError() {
t.Error("expected Failed to be error")
}
if !auditlog.StepStatusCanceled.IsError() {
t.Error("expected Canceled to be error")
}
if auditlog.StepStatusSucceeded.IsError() {
t.Error("expected Succeeded to NOT be error")
}
if auditlog.StepStatusSucceeded.Icon() == "" {
t.Error("expected non-empty icon")
}
}
// --- StepInfo method tests ---
func TestStepInfo_HasError(t *testing.T) {
t.Parallel()
a, w := testhelpers.NewAuditAndWorkflow(t)
s := testhelpers.NewFail("fail-step", "err")
w.Add(flow.Step(s))
testhelpers.RunWorkflow(t, a, w)
report := a.Report()
step := report.StepByName("fail-step")
if !step.HasError() {
t.Error("expected HasError=true")
}
okStep := report.StepByName("fail-step")
okStep.Error = nil
if okStep.HasError() {
t.Error("expected HasError=false after clearing error")
}
}
func TestStepInfo_DeriveStatus_Terminal(t *testing.T) {
t.Parallel()
s := auditlog.StepInfo{Status: auditlog.StepStatusSucceeded}
if s.DeriveStatus() != auditlog.StepStatusSucceeded {
t.Error("expected terminal status preserved")
}
}
func TestStepInfo_DeriveStatus_FromError(t *testing.T) {
t.Parallel()
errMsg := "fail"
s := auditlog.StepInfo{
Status: auditlog.StepStatusRunning,
Error: &errMsg,
}
if s.DeriveStatus() != auditlog.StepStatusFailed {
t.Error("expected failed from error")
}
}
// TestCoverage_StepInfo_Type covers StepInfo.Type() (was 0%).
func TestCoverage_StepInfo_Type(t *testing.T) {
t.Parallel()
step := auditlog.StepInfo{
StepRef: auditlog.StepRef{Name: "x", StepType: "FetchStep"},
}
if step.Type() != "FetchStep" {
t.Errorf("expected Type()='FetchStep', got %q", step.Type())
}
}
// TestCoverage_StepStatus_IsKnown covers StepStatus.IsKnown() (was 0%).
func TestCoverage_StepStatus_IsKnown(t *testing.T) {
t.Parallel()
if !auditlog.StepStatusSucceeded.IsKnown() {
t.Error("expected Succeeded to be known")
}
unknown := auditlog.StepStatus("bogus")
if unknown.IsKnown() {
t.Error("expected bogus status to be unknown")
}
}
// TestCoverage_RunID_StringAndIsEmpty covers RunID.String() and
// RunID.IsEmpty() (both were 0%).
func TestCoverage_RunID_StringAndIsEmpty(t *testing.T) {
t.Parallel()
id := auditlog.RunID("abc123")
if id.String() != "abc123" {
t.Errorf("expected String()='abc123', got %q", id.String())
}
if id.IsEmpty() {
t.Error("expected non-empty RunID to not be empty")
}
var empty auditlog.RunID
if !empty.IsEmpty() {
t.Error("expected zero-value RunID to be empty")
}
}
// TestCoverage_StepStatus_Color_Unknown covers the unknown-status branch of
// StepStatus.Color() (was 66.7%).
func TestCoverage_StepStatus_Color_Unknown(t *testing.T) {
t.Parallel()
unknown := auditlog.StepStatus("bogus")
fill, font := unknown.Color()
if fill != "" || font != "" {
t.Errorf("expected empty colors for unknown status, got fill=%q font=%q", fill, font)
}
}