-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshutdown_test.go
77 lines (64 loc) · 1.76 KB
/
shutdown_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
package opentelemetry_test
import (
"context"
"errors"
"testing"
"flamingo.me/flamingo/v3/framework/flamingo"
"go.opentelemetry.io/otel"
noopMetric "go.opentelemetry.io/otel/metric/noop"
noopTrace "go.opentelemetry.io/otel/trace/noop"
"flamingo.me/opentelemetry"
"flamingo.me/opentelemetry/mocks"
)
type (
tracerProvider struct {
noopTrace.TracerProvider
mocks.Shutdowner
}
meterProvider struct {
noopMetric.MeterProvider
mocks.Shutdowner
}
)
var errShutdown = errors.New("shutdown error")
func TestListener_Notify(t *testing.T) { //nolint:tparallel // no parallel subtests possible because of global state manipulation
t.Parallel()
type args struct {
event flamingo.Event
}
tests := []struct {
name string
args args
traceShutdownError error
meterShutdownError error
}{
{
name: "shutdown meter and tracer successfully",
args: args{
event: new(flamingo.ShutdownEvent),
},
traceShutdownError: nil,
meterShutdownError: nil,
},
{
name: "error on shutdown meter and tracer",
args: args{
event: new(flamingo.ShutdownEvent),
},
traceShutdownError: errShutdown,
meterShutdownError: errShutdown,
},
}
for _, tt := range tests { //nolint:paralleltest // no parallel test possible because of global state manipulation
t.Run(tt.name, func(t *testing.T) {
tp := new(tracerProvider)
tp.Shutdowner.EXPECT().Shutdown(context.Background()).Once().Return(tt.traceShutdownError)
otel.SetTracerProvider(tp)
mp := new(meterProvider)
mp.Shutdowner.EXPECT().Shutdown(context.Background()).Once().Return(tt.meterShutdownError)
otel.SetMeterProvider(mp)
l := new(opentelemetry.Listener).Inject(new(flamingo.NullLogger))
l.Notify(context.Background(), tt.args.event)
})
}
}