-
Notifications
You must be signed in to change notification settings - Fork 354
Expand file tree
/
Copy patherrors_test.go
More file actions
58 lines (54 loc) · 1.03 KB
/
errors_test.go
File metadata and controls
58 lines (54 loc) · 1.03 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
package job
import (
"context"
"errors"
"fmt"
"testing"
)
func TestFormatJobError(t *testing.T) {
t.Parallel()
tests := []struct {
name string
err error
want string
}{
{
name: "nil error",
err: nil,
want: "",
},
{
name: "context.Canceled",
err: context.Canceled,
want: "job cancelled",
},
{
name: "context.DeadlineExceeded",
err: context.DeadlineExceeded,
want: "job timed out",
},
{
name: "wrapped context.Canceled",
err: fmt.Errorf("running command: %w", context.Canceled),
want: "job cancelled",
},
{
name: "wrapped context.DeadlineExceeded",
err: fmt.Errorf("running command: %w", context.DeadlineExceeded),
want: "job timed out",
},
{
name: "non-context error passes through",
err: errors.New("kaboom"),
want: "kaboom",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := FormatJobError(tt.err); got != tt.want {
t.Errorf("FormatJobError(%v) = %q, want %q", tt.err, got, tt.want)
}
})
}
}