generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathengine_test.go
150 lines (127 loc) · 3.84 KB
/
engine_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package verity_test
import (
"context"
"time"
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
. "github.com/dogmatiq/verity"
. "github.com/dogmatiq/verity/fixtures"
"github.com/dogmatiq/verity/persistence/memorypersistence"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ dogma.CommandExecutor = (*Engine)(nil)
var _ = Describe("type Engine", func() {
var (
app *ApplicationStub
deliveryPolicy dogma.ProjectionDeliveryPolicy
)
BeforeEach(func() {
deliveryPolicy = dogma.UnicastProjectionDeliveryPolicy{}
app = &ApplicationStub{
ConfigureFunc: func(c dogma.ApplicationConfigurer) {
c.Identity("<app-name>", DefaultAppKey)
c.RegisterAggregate(&AggregateMessageHandlerStub{
ConfigureFunc: func(c dogma.AggregateConfigurer) {
c.Identity("<agg-name>", "e4ff048e-79f7-45e2-9f02-3b10d17614c6")
c.Routes(
dogma.HandlesCommand[CommandStub[TypeC]](),
dogma.RecordsEvent[EventStub[TypeE]](),
)
},
})
c.RegisterProcess(&ProcessMessageHandlerStub{
ConfigureFunc: func(c dogma.ProcessConfigurer) {
c.Identity("<proc-name>", "2ae0b937-e806-4e70-9b23-f36298f68973")
c.Routes(
dogma.HandlesEvent[EventStub[TypeE]](),
dogma.ExecutesCommand[CommandStub[TypeI]](),
)
},
})
c.RegisterIntegration(&IntegrationMessageHandlerStub{
ConfigureFunc: func(c dogma.IntegrationConfigurer) {
c.Identity("<int-name>", "27fb3936-6f88-4873-8c56-e6a1d01f027a")
c.Routes(
dogma.HandlesCommand[CommandStub[TypeI]](),
dogma.RecordsEvent[EventStub[TypeJ]](),
)
},
})
c.RegisterProjection(&ProjectionMessageHandlerStub{
ConfigureFunc: func(c dogma.ProjectionConfigurer) {
c.Identity("<proj-name>", "b084ea4f-87d1-4001-8c1a-347c29baed35")
c.Routes(
dogma.HandlesEvent[EventStub[TypeE]](),
)
c.DeliveryPolicy(deliveryPolicy)
},
})
c.RegisterProjection(&ProjectionMessageHandlerStub{
ConfigureFunc: func(c dogma.ProjectionConfigurer) {
c.Identity("<disabled-proj-name>", "4ad6edf4-78b3-46bc-8321-0e1b834e3808")
c.Routes(
dogma.HandlesEvent[EventStub[TypeE]](),
)
c.Disable()
},
})
},
}
})
Describe("func New()", func() {
It("allows the app to be provided as the first parameter", func() {
Expect(func() {
New(app)
}).NotTo(Panic())
})
It("allows the app to be provided via the WithApplication() option", func() {
Expect(func() {
New(nil, WithApplication(app))
}).NotTo(Panic())
})
It("provides default values for networking", func() {
Expect(func() {
New(app, WithNetworking())
}).NotTo(Panic())
})
It("panics if no apps are provided", func() {
Expect(func() {
New(nil)
}).To(Panic())
})
It("panics if a projection uses an unsupported delivery policy", func() {
deliveryPolicy = dogma.BroadcastProjectionDeliveryPolicy{}
Expect(func() {
New(app)
}).To(PanicWith("the <proj-name>/b084ea4f-87d1-4001-8c1a-347c29baed35 handler uses the dogma.BroadcastProjectionDeliveryPolicy delivery policy, which is not supported"))
})
})
Describe("func Run()", func() {
var (
ctx context.Context
cancel context.CancelFunc
)
BeforeEach(func() {
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
DeferCleanup(cancel)
})
It("returns an error if the context is canceled before calling", func() {
cancel()
err := Run(ctx, app)
Expect(err).To(MatchError(context.Canceled))
})
It("returns an error if the context is canceled while running", func() {
go func() {
time.Sleep(10 * time.Millisecond)
cancel()
}()
err := Run(
ctx,
app,
WithPersistence(&memorypersistence.Provider{}), // avoid default BoltDB location
)
Expect(err).To(MatchError(context.Canceled))
})
})
})