-
Notifications
You must be signed in to change notification settings - Fork 46
/
error_test.go
82 lines (67 loc) · 2.14 KB
/
error_test.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
package health
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestUnmutedErrors(t *testing.T) {
stream := NewStream()
sink := &testSink{}
stream.AddSink(sink)
job := stream.NewJob("myjob")
origErr := fmt.Errorf("wat")
retErr := job.EventErr("abcd", origErr)
// retErr is an UnmutedError with Emitted=true
if retErr, ok := retErr.(*UnmutedError); ok {
assert.True(t, retErr.Emitted)
assert.Equal(t, retErr.Err, origErr)
} else {
t.Errorf("expected retErr to be an *UnmutedError")
}
// LastErr has Emitted=false, WasUnmuted=true
assert.NotNil(t, sink.LastErr)
assert.True(t, sink.LastErrUnmuted)
assert.False(t, sink.LastErrEmitted)
// Log it again!
retErr2 := job.EventErr("abcdefg", retErr)
// retErr is an UnmutedError with Emitted=true
if retErr2, ok := retErr2.(*UnmutedError); ok {
assert.True(t, retErr2.Emitted)
assert.Equal(t, retErr2.Err, origErr) // We don't endlessly wrap UnmutedErrors inside UnmutedErrors
} else {
t.Errorf("expected retErr to be an *UnmutedError")
}
// LastErr has Emitted=false, WasUnmuted=true
assert.NotNil(t, sink.LastErr)
assert.True(t, sink.LastErrUnmuted)
assert.True(t, sink.LastErrEmitted)
}
func TestMutedErrors(t *testing.T) {
stream := NewStream()
sink := &testSink{}
stream.AddSink(sink)
job := stream.NewJob("myjob")
origErr := fmt.Errorf("wat")
mutedOrig := Mute(origErr)
retErr := job.EventErr("abcd", mutedOrig)
// retErr is an UnmutedError with Emitted=true
if retErr, ok := retErr.(*MutedError); ok {
assert.Equal(t, retErr.Err, origErr)
} else {
t.Errorf("expected retErr to be an *MutedError")
}
// LastErr has Emitted=false, WasUnmuted=true
assert.NotNil(t, sink.LastErr)
assert.True(t, sink.LastErrMuted)
// Log it again!
retErr2 := job.EventErr("abcdefg", retErr)
// retErr is an UnmutedError with Emitted=true
if retErr2, ok := retErr2.(*MutedError); ok {
assert.Equal(t, retErr2.Err, origErr) // We don't endlessly wrap MutedErrors inside MutedErrors
} else {
t.Errorf("expected retErr to be an *MutedError")
}
// LastErr has Emitted=false, WasUnmuted=true
assert.NotNil(t, sink.LastErr)
assert.True(t, sink.LastErrMuted)
}