-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_test.go
59 lines (53 loc) · 1.1 KB
/
context_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
package cqrs_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/vulpes-ferrilata/cqrs"
)
func TestGetEventProvider(t *testing.T) {
t.Parallel()
var (
eventProvider = cqrs.NewEventProvider()
)
type wants struct {
eventProvider cqrs.EventProvider
ok bool
}
tests := []struct {
name string
prepare func() context.Context
wants wants
}{
{
name: "no event provider injected into context",
prepare: func() context.Context {
return context.Background()
},
wants: wants{
eventProvider: nil,
ok: false,
},
},
{
name: " event provider injected into context",
prepare: func() context.Context {
ctx := context.Background()
ctx = cqrs.WithEventProvider(ctx, eventProvider)
return ctx
},
wants: wants{
eventProvider: eventProvider,
ok: true,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := tt.prepare()
got, ok := cqrs.GetEventProvider(ctx)
assert.Equal(t, tt.wants.eventProvider, got)
assert.Equal(t, tt.wants.ok, ok)
})
}
}