-
Notifications
You must be signed in to change notification settings - Fork 1
/
multi_test.go
60 lines (46 loc) · 1.21 KB
/
multi_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
package reporter
import (
"errors"
"testing"
"context"
)
func TestMultiReporter(t *testing.T) {
var (
r1Called bool
r2Called bool
)
r1 := ReporterFunc(func(ctx context.Context, level string, err error) error {
r1Called = true
return nil
})
r2 := ReporterFunc(func(ctx context.Context, level string, err error) error {
r2Called = true
return nil
})
h := MultiReporter{r1, r2}
ctx := WithReporter(context.Background(), h)
if err := Report(ctx, errBoom); err != nil {
t.Fatal(err)
}
if got, want := r1Called, true; got != want {
t.Fatal("Expected r1 to be called")
}
if got, want := r2Called, true; got != want {
t.Fatal("Expected r2 to be called")
}
}
// Tests when the Report method of the individual reporters returns an error.
func TestMultiReporterError(t *testing.T) {
r1 := ReporterFunc(func(ctx context.Context, level string, err error) error {
return errors.New("boom 1")
})
r2 := ReporterFunc(func(ctx context.Context, level string, err error) error {
return errors.New("boom 2")
})
h := MultiReporter{r1, r2}
ctx := WithReporter(context.Background(), h)
err := Report(ctx, errBoom)
if _, ok := err.(*MultiError); !ok {
t.Fatal("Expected a MultiError to be returned")
}
}