-
Notifications
You must be signed in to change notification settings - Fork 0
/
expectation.messagematch.eventonly_test.go
196 lines (188 loc) · 5.4 KB
/
expectation.messagematch.eventonly_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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package testkit_test
import (
"errors"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/dogma/fixtures"
. "github.com/dogmatiq/dogma/fixtures"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
. "github.com/dogmatiq/testkit"
"github.com/dogmatiq/testkit/internal/testingmock"
g "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() {
var (
testingT *testingmock.T
app dogma.Application
)
g.BeforeEach(func() {
testingT = &testingmock.T{
FailSilently: true,
}
app = &ApplicationStub{
ConfigureFunc: func(c dogma.ApplicationConfigurer) {
c.Identity("<app>", "94f425c5-339a-4213-8309-16234225480e")
c.RegisterAggregate(&AggregateMessageHandlerStub{
ConfigureFunc: func(c dogma.AggregateConfigurer) {
c.Identity("<aggregate>", "bc64cfe4-3339-4eee-a9d2-364d33dff47d")
c.Routes(
dogma.HandlesCommand[MessageC](), // C = command
dogma.RecordsEvent[MessageE](), // E = event
)
},
RouteCommandToInstanceFunc: func(dogma.Command) string {
return "<instance>"
},
HandleCommandFunc: func(
_ dogma.AggregateRoot,
s dogma.AggregateCommandScope,
m dogma.Command,
) {
s.RecordEvent(MessageE1)
s.RecordEvent(MessageE2)
s.RecordEvent(MessageE3)
},
})
},
}
})
g.DescribeTable(
"expectation behavior",
func(
a Action,
e Expectation,
ok bool,
rm reportMatcher,
options ...TestOption,
) {
test := Begin(testingT, app, options...)
test.Expect(a, e)
rm(testingT)
Expect(testingT.Failed()).To(Equal(!ok))
},
g.Entry(
"all recorded events match",
ExecuteCommand(MessageC1),
ToOnlyRecordEventsMatching(
func(m dogma.Event) error {
return nil
},
),
expectPass,
expectReport(
`✓ only record events that match the predicate near expectation.messagematch.eventonly_test.go:75`,
),
),
g.Entry(
"all recorded events match, using predicate with application-defined type parameter",
ExecuteCommand(MessageC1),
ToOnlyRecordEventsMatching(
func(m MessageE) error {
return nil
},
),
expectPass,
expectReport(
`✓ only record events that match the predicate near expectation.messagematch.eventonly_test.go:88`,
),
),
g.Entry(
"no events recorded at all",
noop,
ToOnlyRecordEventsMatching(
func(m dogma.Event) error {
panic("unexpected call")
},
),
expectPass,
expectReport(
`✓ only record events that match the predicate near expectation.messagematch.eventonly_test.go:100`,
),
),
g.Entry(
"none of the recorded events match",
ExecuteCommand(MessageC1),
ToOnlyRecordEventsMatching(
func(m dogma.Event) error {
return errors.New("<error>")
},
),
expectFail,
expectReport(
`✗ only record events that match the predicate near expectation.messagematch.eventonly_test.go:113`,
``,
` | EXPLANATION`,
` | none of the 3 relevant events matched the predicate`,
` | `,
` | FAILED MATCHES`,
` | • fixtures.MessageE: <error> (repeated 3 times)`,
` | `,
` | SUGGESTIONS`,
` | • verify the logic within the predicate function`,
` | • enable integration handlers using the EnableHandlerType() option`,
` | • verify the logic within the '<aggregate>' aggregate message handler`,
),
),
g.Entry(
"some matching events recorded",
ExecuteCommand(MessageC1),
ToOnlyRecordEventsMatching(
func(m dogma.Event) error {
switch m {
case fixtures.MessageE1:
return errors.New("<error>")
case fixtures.MessageE2:
return IgnoreMessage
default:
return nil
}
},
),
expectFail,
expectReport(
`✗ only record events that match the predicate near expectation.messagematch.eventonly_test.go:137`,
``,
` | EXPLANATION`,
` | only 1 of 2 relevant events matched the predicate`,
` | `,
` | FAILED MATCHES`,
` | • fixtures.MessageE: <error>`,
` | `,
` | SUGGESTIONS`,
` | • verify the logic within the predicate function, it ignored 1 event`,
` | • enable integration handlers using the EnableHandlerType() option`,
` | • verify the logic within the '<aggregate>' aggregate message handler`,
),
),
g.Entry(
"no matching events recorded, using predicate with application-defined type parameter",
ExecuteCommand(MessageC1),
ToOnlyRecordEventsMatching(
func(m MessageX) error {
panic("unexpected call")
},
),
expectFail,
expectReport(
`✗ only record events that match the predicate near expectation.messagematch.eventonly_test.go:168`,
``,
` | EXPLANATION`,
` | none of the 3 relevant events matched the predicate`,
` | `,
` | FAILED MATCHES`,
` | • fixtures.MessageE: predicate function expected fixtures.MessageX (repeated 3 times)`,
` | `,
` | SUGGESTIONS`,
` | • verify the logic within the predicate function`,
` | • enable integration handlers using the EnableHandlerType() option`,
` | • verify the logic within the '<aggregate>' aggregate message handler`,
),
),
)
g.It("panics if the function is nil", func() {
Expect(func() {
var fn func(dogma.Event) error
ToOnlyRecordEventsMatching(fn)
}).To(PanicWith("ToOnlyRecordEventsMatching(<nil>): function must not be nil"))
})
})