-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.call_test.go
157 lines (142 loc) · 3.67 KB
/
action.call_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
package testkit_test
import (
"context"
"time"
"github.com/dogmatiq/configkit"
. "github.com/dogmatiq/configkit/fixtures"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/dogma/fixtures"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
. "github.com/dogmatiq/testkit"
"github.com/dogmatiq/testkit/engine"
"github.com/dogmatiq/testkit/envelope"
"github.com/dogmatiq/testkit/fact"
"github.com/dogmatiq/testkit/internal/testingmock"
g "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
)
var _ = g.Describe("func Call()", func() {
var (
app *ApplicationStub
t *testingmock.T
startTime time.Time
buf *fact.Buffer
test *Test
)
g.BeforeEach(func() {
app = &ApplicationStub{
ConfigureFunc: func(c dogma.ApplicationConfigurer) {
c.Identity("<app>", "b51cde16-aaec-4d75-ae14-06282e3a72c8")
c.RegisterAggregate(&AggregateMessageHandlerStub{
ConfigureFunc: func(c dogma.AggregateConfigurer) {
c.Identity("<aggregate>", "832d78d7-a006-414f-b6d7-3153aa7c9ab8")
c.Routes(
dogma.HandlesCommand[MessageC](),
dogma.RecordsEvent[MessageE](),
)
},
RouteCommandToInstanceFunc: func(
dogma.Command,
) string {
return "<instance>"
},
})
c.RegisterProcess(&ProcessMessageHandlerStub{
ConfigureFunc: func(c dogma.ProcessConfigurer) {
c.Identity("<process>", "b64cdd19-782e-4e4e-9e5f-a95a943d6340")
c.Routes(
dogma.HandlesEvent[MessageE](),
dogma.ExecutesCommand[MessageC](),
)
},
RouteEventToInstanceFunc: func(
context.Context,
dogma.Event,
) (string, bool, error) {
return "<instance>", true, nil
},
})
},
}
t = &testingmock.T{}
startTime = time.Now()
buf = &fact.Buffer{}
test = Begin(
t,
app,
StartTimeAt(startTime),
WithUnsafeOperationOptions(
engine.WithObserver(buf),
),
)
})
g.It("allows use of the test's executor", func() {
e := test.CommandExecutor()
test.Prepare(
Call(func() {
e.ExecuteCommand(
context.Background(),
MessageC1,
)
}),
)
Expect(buf.Facts()).To(ContainElement(
fact.DispatchCycleBegun{
Envelope: &envelope.Envelope{
MessageID: "1",
CausationID: "1",
CorrelationID: "1",
Message: MessageC1,
Type: MessageCType,
Role: message.CommandRole,
CreatedAt: startTime,
},
EngineTime: startTime,
EnabledHandlerTypes: map[configkit.HandlerType]bool{
configkit.AggregateHandlerType: true,
configkit.IntegrationHandlerType: false,
configkit.ProcessHandlerType: true,
configkit.ProjectionHandlerType: false,
},
EnabledHandlers: map[string]bool{},
},
))
})
g.It("allows expectations to match commands executed via the test's executor", func() {
e := test.CommandExecutor()
test.Expect(
Call(func() {
e.ExecuteCommand(
context.Background(),
MessageC1,
)
}),
ToExecuteCommand(MessageC1),
)
})
g.It("produces the expected caption", func() {
test.Prepare(
Call(func() {}),
)
Expect(t.Logs).To(ContainElement(
"--- calling user-defined function ---",
))
})
g.It("panics if the function is nil", func() {
Expect(func() {
Call(nil)
}).To(PanicWith("Call(<nil>): function must not be nil"))
})
g.It("captures the location that the action was created", func() {
act := call(func() {})
Expect(act.Location()).To(MatchAllFields(
Fields{
"Func": Equal("github.com/dogmatiq/testkit_test.call"),
"File": HaveSuffix("/action.linenumber_test.go"),
"Line": Equal(51),
},
))
})
})