Skip to content

Commit

Permalink
Use enginetest/stubs in ToOnlyRecordEventsMatching() tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Sep 24, 2024
1 parent 97f4291 commit 69c0b7c
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions expectation.messagematch.eventonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ 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"
Expand All @@ -19,6 +17,11 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() {
app dogma.Application
)

type (
CommandThatRecordsEvent = CommandStub[TypeE]
EventThatIsRecorded = EventStub[TypeE]
)

g.BeforeEach(func() {
testingT = &testingmock.T{
FailSilently: true,
Expand All @@ -32,8 +35,8 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() {
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
dogma.HandlesCommand[CommandThatRecordsEvent](),
dogma.RecordsEvent[EventThatIsRecorded](),
)
},
RouteCommandToInstanceFunc: func(dogma.Command) string {
Expand All @@ -44,9 +47,9 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() {
s dogma.AggregateCommandScope,
m dogma.Command,
) {
s.RecordEvent(MessageE1)
s.RecordEvent(MessageE2)
s.RecordEvent(MessageE3)
s.RecordEvent(EventE1)
s.RecordEvent(EventE2)
s.RecordEvent(EventE3)
},
})
},
Expand All @@ -69,28 +72,28 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() {
},
g.Entry(
"all recorded events match",
ExecuteCommand(MessageC1),
ExecuteCommand(CommandThatRecordsEvent{}),
ToOnlyRecordEventsMatching(
func(m dogma.Event) error {
return nil
},
),
expectPass,
expectReport(
`✓ only record events that match the predicate near expectation.messagematch.eventonly_test.go:75`,
`✓ only record events that match the predicate near expectation.messagematch.eventonly_test.go:78`,
),
),
g.Entry(
"all recorded events match, using predicate with a more specific type",
ExecuteCommand(MessageC1),
ExecuteCommand(CommandThatRecordsEvent{}),
ToOnlyRecordEventsMatching(
func(m MessageE) error {
func(m EventThatIsRecorded) error {
return nil
},
),
expectPass,
expectReport(
`✓ only record events that match the predicate near expectation.messagematch.eventonly_test.go:88`,
`✓ only record events that match the predicate near expectation.messagematch.eventonly_test.go:91`,
),
),
g.Entry(
Expand All @@ -103,26 +106,26 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() {
),
expectPass,
expectReport(
`✓ only record events that match the predicate near expectation.messagematch.eventonly_test.go:100`,
`✓ only record events that match the predicate near expectation.messagematch.eventonly_test.go:103`,
),
),
g.Entry(
"none of the recorded events match",
ExecuteCommand(MessageC1),
ExecuteCommand(CommandThatRecordsEvent{}),
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`,
`✗ only record events that match the predicate near expectation.messagematch.eventonly_test.go:116`,
``,
` | EXPLANATION`,
` | none of the 3 relevant events matched the predicate`,
` | `,
` | FAILED MATCHES`,
` | • fixtures.MessageE: <error> (repeated 3 times)`,
` | • stubs.EventStub[TypeE]: <error> (repeated 3 times)`,
` | `,
` | SUGGESTIONS`,
` | • verify the logic within the predicate function`,
Expand All @@ -132,13 +135,13 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() {
),
g.Entry(
"some matching events recorded",
ExecuteCommand(MessageC1),
ExecuteCommand(CommandThatRecordsEvent{}),
ToOnlyRecordEventsMatching(
func(m dogma.Event) error {
switch m {
case fixtures.MessageE1:
case EventE1:
return errors.New("<error>")
case fixtures.MessageE2:
case EventE2:
return IgnoreMessage
default:
return nil
Expand All @@ -147,13 +150,13 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() {
),
expectFail,
expectReport(
`✗ only record events that match the predicate near expectation.messagematch.eventonly_test.go:137`,
`✗ only record events that match the predicate near expectation.messagematch.eventonly_test.go:140`,
``,
` | EXPLANATION`,
` | only 1 of 2 relevant events matched the predicate`,
` | `,
` | FAILED MATCHES`,
` | • fixtures.MessageE: <error>`,
` | • stubs.EventStub[TypeE]: <error>`,
` | `,
` | SUGGESTIONS`,
` | • verify the logic within the predicate function, it ignored 1 event`,
Expand All @@ -163,21 +166,21 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() {
),
g.Entry(
"no matching events recorded, using predicate with a more specific type",
ExecuteCommand(MessageC1),
ExecuteCommand(CommandThatRecordsEvent{}),
ToOnlyRecordEventsMatching(
func(m MessageX) error {
func(m EventStub[TypeX]) error {
panic("unexpected call")
},
),
expectFail,
expectReport(
`✗ only record events that match the predicate near expectation.messagematch.eventonly_test.go:168`,
`✗ only record events that match the predicate near expectation.messagematch.eventonly_test.go:171`,
``,
` | EXPLANATION`,
` | none of the 3 relevant events matched the predicate`,
` | `,
` | FAILED MATCHES`,
` | • fixtures.MessageE: predicate function expected fixtures.MessageX (repeated 3 times)`,
` | • stubs.EventStub[TypeE]: predicate function expected stubs.EventStub[TypeX] (repeated 3 times)`,
` | `,
` | SUGGESTIONS`,
` | • verify the logic within the predicate function`,
Expand Down

0 comments on commit 69c0b7c

Please sign in to comment.