From 69c0b7c2b3d7e4127571781ca67447b1fd41384d Mon Sep 17 00:00:00 2001 From: James Harris Date: Wed, 25 Sep 2024 07:32:14 +1000 Subject: [PATCH] Use `enginetest/stubs` in `ToOnlyRecordEventsMatching()` tests. --- expectation.messagematch.eventonly_test.go | 53 ++++++++++++---------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/expectation.messagematch.eventonly_test.go b/expectation.messagematch.eventonly_test.go index f40118f..928fcf8 100644 --- a/expectation.messagematch.eventonly_test.go +++ b/expectation.messagematch.eventonly_test.go @@ -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" @@ -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, @@ -32,8 +35,8 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() { ConfigureFunc: func(c dogma.AggregateConfigurer) { c.Identity("", "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 { @@ -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) }, }) }, @@ -69,7 +72,7 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() { }, g.Entry( "all recorded events match", - ExecuteCommand(MessageC1), + ExecuteCommand(CommandThatRecordsEvent{}), ToOnlyRecordEventsMatching( func(m dogma.Event) error { return nil @@ -77,20 +80,20 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() { ), 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( @@ -103,12 +106,12 @@ 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("") @@ -116,13 +119,13 @@ var _ = g.Describe("func ToOnlyRecordEventsMatching()", func() { ), 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: (repeated 3 times)`, + ` | • stubs.EventStub[TypeE]: (repeated 3 times)`, ` | `, ` | SUGGESTIONS`, ` | • verify the logic within the predicate function`, @@ -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("") - case fixtures.MessageE2: + case EventE2: return IgnoreMessage default: return nil @@ -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: `, + ` | • stubs.EventStub[TypeE]: `, ` | `, ` | SUGGESTIONS`, ` | • verify the logic within the predicate function, it ignored 1 event`, @@ -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`,