diff --git a/CHANGELOG.md b/CHANGELOG.md index bd7a385..6f4d1a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,12 @@ The format is based on [Keep a Changelog], and this project adheres to [keep a changelog]: https://keepachangelog.com/en/1.0.0/ [semantic versioning]: https://semver.org/spec/v2.0.0.html +## [0.14.3] - 2024-09-27 + +### Removed + +- **[ENGINE BC]** Removed deprecated `fixtures` package. + ## [0.14.2] - 2024-08-21 ### Removed @@ -354,6 +360,7 @@ No engines except [testkit] are able to provide a meaningful implementation of [0.14.0]: https://github.com/dogmatiq/dogma/releases/tag/v0.14.0 [0.14.1]: https://github.com/dogmatiq/dogma/releases/tag/v0.14.1 [0.14.2]: https://github.com/dogmatiq/dogma/releases/tag/v0.14.2 +[0.14.3]: https://github.com/dogmatiq/dogma/releases/tag/v0.14.3 diff --git a/fixtures/aggregate.go b/fixtures/aggregate.go deleted file mode 100644 index 0636d55..0000000 --- a/fixtures/aggregate.go +++ /dev/null @@ -1,67 +0,0 @@ -package fixtures - -import "github.com/dogmatiq/dogma" - -// AggregateRoot is a test implementation of [dogma.AggregateRoot]. -type AggregateRoot struct { - AppliedEvents []dogma.Event - ApplyEventFunc func(dogma.Event) `json:"-"` -} - -var _ dogma.AggregateRoot = &AggregateRoot{} - -// ApplyEvent updates aggregate instance to reflect the occurrence of an event. -func (v *AggregateRoot) ApplyEvent(e dogma.Event) { - v.AppliedEvents = append(v.AppliedEvents, e) - - if v.ApplyEventFunc != nil { - v.ApplyEventFunc(e) - } -} - -// AggregateMessageHandler is a test implementation of -// [dogma.AggregateMessageHandler]. -type AggregateMessageHandler struct { - NewFunc func() dogma.AggregateRoot - ConfigureFunc func(dogma.AggregateConfigurer) - RouteCommandToInstanceFunc func(dogma.Command) string - HandleCommandFunc func(dogma.AggregateRoot, dogma.AggregateCommandScope, dogma.Command) -} - -var _ dogma.AggregateMessageHandler = &AggregateMessageHandler{} - -// Configure describes the handler's configuration to the engine. -func (h *AggregateMessageHandler) Configure(c dogma.AggregateConfigurer) { - if h.ConfigureFunc != nil { - h.ConfigureFunc(c) - } -} - -// New returns an aggregate root instance in its initial state. -func (h *AggregateMessageHandler) New() dogma.AggregateRoot { - if h.NewFunc != nil { - return h.NewFunc() - } - return &AggregateRoot{} -} - -// RouteCommandToInstance returns the ID of the instance that handles a specific -// command. -func (h *AggregateMessageHandler) RouteCommandToInstance(c dogma.Command) string { - if h.RouteCommandToInstanceFunc == nil { - panic(dogma.UnexpectedMessage) - } - - return h.RouteCommandToInstanceFunc(c) -} - -// HandleCommand executes business logic in response to a command. -func (h *AggregateMessageHandler) HandleCommand( - r dogma.AggregateRoot, - s dogma.AggregateCommandScope, - c dogma.Command, -) { - if h.HandleCommandFunc != nil { - h.HandleCommandFunc(r, s, c) - } -} diff --git a/fixtures/application.go b/fixtures/application.go deleted file mode 100644 index 20ce6e1..0000000 --- a/fixtures/application.go +++ /dev/null @@ -1,17 +0,0 @@ -package fixtures - -import "github.com/dogmatiq/dogma" - -// Application is a test implementation of [dogma.Application]. -type Application struct { - ConfigureFunc func(dogma.ApplicationConfigurer) -} - -var _ dogma.Application = &Application{} - -// Configure describes the application's configuration to the engine. -func (a *Application) Configure(c dogma.ApplicationConfigurer) { - if a.ConfigureFunc != nil { - a.ConfigureFunc(c) - } -} diff --git a/fixtures/doc.go b/fixtures/doc.go deleted file mode 100644 index 42908e9..0000000 --- a/fixtures/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -// Package fixtures is a set of test fixtures and mocks of Dogma interfaces. -// -// Deprecated: Engine developers can use enginekit [stubs] instead. -// -// [stubs]: https://pkg.go.dev/github.com/dogmatiq/enginekit/enginetest/stubs -package fixtures diff --git a/fixtures/integration.go b/fixtures/integration.go deleted file mode 100644 index 205ac1b..0000000 --- a/fixtures/integration.go +++ /dev/null @@ -1,35 +0,0 @@ -package fixtures - -import ( - "context" - - "github.com/dogmatiq/dogma" -) - -// IntegrationMessageHandler is a test implementation of -// [dogma.IntegrationMessageHandler]. -type IntegrationMessageHandler struct { - ConfigureFunc func(dogma.IntegrationConfigurer) - HandleCommandFunc func(context.Context, dogma.IntegrationCommandScope, dogma.Command) error -} - -var _ dogma.IntegrationMessageHandler = &IntegrationMessageHandler{} - -// Configure describes the handler's configuration to the engine. -func (h *IntegrationMessageHandler) Configure(c dogma.IntegrationConfigurer) { - if h.ConfigureFunc != nil { - h.ConfigureFunc(c) - } -} - -// HandleCommand handles a command, typically by invoking some external API. -func (h *IntegrationMessageHandler) HandleCommand( - ctx context.Context, - s dogma.IntegrationCommandScope, - c dogma.Command, -) error { - if h.HandleCommandFunc != nil { - return h.HandleCommandFunc(ctx, s, c) - } - return nil -} diff --git a/fixtures/message.go b/fixtures/message.go deleted file mode 100644 index 65ce92d..0000000 --- a/fixtures/message.go +++ /dev/null @@ -1,679 +0,0 @@ -package fixtures - -import "fmt" - -// MessageA is a type used as a dogma.Message in tests. -// Deprecated: Use [TestCommand], [TestEvent] or [TestTimeout] instead. -type MessageA struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageA) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageA) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageA1 is an instance of MessageA with a distinct value. - MessageA1 = MessageA{"A1"} - // MessageA2 is an instance of MessageA with a distinct value. - MessageA2 = MessageA{"A2"} - // MessageA3 is an instance of MessageA with a distinct value. - MessageA3 = MessageA{"A3"} -) - -// MessageB is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageB struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageB) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageB) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageB1 is an instance of MessageB with a distinct value. - MessageB1 = MessageB{"B1"} - // MessageB2 is an instance of MessageB with a distinct value. - MessageB2 = MessageB{"B2"} - // MessageB3 is an instance of MessageB with a distinct value. - MessageB3 = MessageB{"B3"} -) - -// MessageC is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageC struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageC) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageC) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageC1 is an instance of MessageC with a distinct value. - MessageC1 = MessageC{"C1"} - // MessageC2 is an instance of MessageC with a distinct value. - MessageC2 = MessageC{"C2"} - // MessageC3 is an instance of MessageC with a distinct value. - MessageC3 = MessageC{"C3"} -) - -// MessageD is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageD struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageD) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageD) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageD1 is an instance of MessageD with a distinct value. - MessageD1 = MessageD{"D1"} - // MessageD2 is an instance of MessageD with a distinct value. - MessageD2 = MessageD{"D2"} - // MessageD3 is an instance of MessageD with a distinct value. - MessageD3 = MessageD{"D3"} -) - -// MessageE is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageE struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageE) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageE) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageE1 is an instance of MessageE with a distinct value. - MessageE1 = MessageE{"E1"} - // MessageE2 is an instance of MessageE with a distinct value. - MessageE2 = MessageE{"E2"} - // MessageE3 is an instance of MessageE with a distinct value. - MessageE3 = MessageE{"E3"} -) - -// MessageF is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageF struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageF) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageF) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageF1 is an instance of MessageF with a distinct value. - MessageF1 = MessageF{"F1"} - // MessageF2 is an instance of MessageF with a distinct value. - MessageF2 = MessageF{"F2"} - // MessageF3 is an instance of MessageF with a distinct value. - MessageF3 = MessageF{"F3"} -) - -// MessageG is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageG struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageG) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageG) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageG1 is an instance of MessageG with a distinct value. - MessageG1 = MessageG{"G1"} - // MessageG2 is an instance of MessageG with a distinct value. - MessageG2 = MessageG{"G2"} - // MessageG3 is an instance of MessageG with a distinct value. - MessageG3 = MessageG{"G3"} -) - -// MessageH is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageH struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageH) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageH) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageH1 is an instance of MessageH with a distinct value. - MessageH1 = MessageH{"H1"} - // MessageH2 is an instance of MessageH with a distinct value. - MessageH2 = MessageH{"H2"} - // MessageH3 is an instance of MessageH with a distinct value. - MessageH3 = MessageH{"H3"} -) - -// MessageI is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageI struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageI) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageI) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageI1 is an instance of MessageI with a distinct value. - MessageI1 = MessageI{"I1"} - // MessageI2 is an instance of MessageI with a distinct value. - MessageI2 = MessageI{"I2"} - // MessageI3 is an instance of MessageI with a distinct value. - MessageI3 = MessageI{"I3"} -) - -// MessageJ is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageJ struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageJ) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageJ) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageJ1 is an instance of MessageJ with a distinct value. - MessageJ1 = MessageJ{"J1"} - // MessageJ2 is an instance of MessageJ with a distinct value. - MessageJ2 = MessageJ{"J2"} - // MessageJ3 is an instance of MessageJ with a distinct value. - MessageJ3 = MessageJ{"J3"} -) - -// MessageK is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageK struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageK) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageK) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageK1 is an instance of MessageK with a distinct value. - MessageK1 = MessageK{"K1"} - // MessageK2 is an instance of MessageK with a distinct value. - MessageK2 = MessageK{"K2"} - // MessageK3 is an instance of MessageK with a distinct value. - MessageK3 = MessageK{"K3"} -) - -// MessageL is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageL struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageL) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageL) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageL1 is an instance of MessageL with a distinct value. - MessageL1 = MessageL{"L1"} - // MessageL2 is an instance of MessageL with a distinct value. - MessageL2 = MessageL{"L2"} - // MessageL3 is an instance of MessageL with a distinct value. - MessageL3 = MessageL{"L3"} -) - -// MessageM is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageM struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageM) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageM) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageM1 is an instance of MessageM with a distinct value. - MessageM1 = MessageM{"M1"} - // MessageM2 is an instance of MessageM with a distinct value. - MessageM2 = MessageM{"M2"} - // MessageM3 is an instance of MessageM with a distinct value. - MessageM3 = MessageM{"M3"} -) - -// MessageN is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageN struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageN) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageN) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageN1 is an instance of MessageN with a distinct value. - MessageN1 = MessageN{"N1"} - // MessageN2 is an instance of MessageN with a distinct value. - MessageN2 = MessageN{"N2"} - // MessageN3 is an instance of MessageN with a distinct value. - MessageN3 = MessageN{"N3"} -) - -// MessageO is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageO struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageO) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageO) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageO1 is an instance of MessageO with a distinct value. - MessageO1 = MessageO{"O1"} - // MessageO2 is an instance of MessageO with a distinct value. - MessageO2 = MessageO{"O2"} - // MessageO3 is an instance of MessageO with a distinct value. - MessageO3 = MessageO{"O3"} -) - -// MessageP is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageP struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageP) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageP) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageP1 is an instance of MessageP with a distinct value. - MessageP1 = MessageP{"P1"} - // MessageP2 is an instance of MessageP with a distinct value. - MessageP2 = MessageP{"P2"} - // MessageP3 is an instance of MessageP with a distinct value. - MessageP3 = MessageP{"P3"} -) - -// MessageQ is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageQ struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageQ) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageQ) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageQ1 is an instance of MessageQ with a distinct value. - MessageQ1 = MessageQ{"Q1"} - // MessageQ2 is an instance of MessageQ with a distinct value. - MessageQ2 = MessageQ{"Q2"} - // MessageQ3 is an instance of MessageQ with a distinct value. - MessageQ3 = MessageQ{"Q3"} -) - -// MessageR is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageR struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageR) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageR) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageR1 is an instance of MessageR with a distinct value. - MessageR1 = MessageR{"R1"} - // MessageR2 is an instance of MessageR with a distinct value. - MessageR2 = MessageR{"R2"} - // MessageR3 is an instance of MessageR with a distinct value. - MessageR3 = MessageR{"R3"} -) - -// MessageS is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageS struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageS) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageS) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageS1 is an instance of MessageS with a distinct value. - MessageS1 = MessageS{"S1"} - // MessageS2 is an instance of MessageS with a distinct value. - MessageS2 = MessageS{"S2"} - // MessageS3 is an instance of MessageS with a distinct value. - MessageS3 = MessageS{"S3"} -) - -// MessageT is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageT struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageT) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageT) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageT1 is an instance of MessageT with a distinct value. - MessageT1 = MessageT{"T1"} - // MessageT2 is an instance of MessageT with a distinct value. - MessageT2 = MessageT{"T2"} - // MessageT3 is an instance of MessageT with a distinct value. - MessageT3 = MessageT{"T3"} -) - -// MessageU is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageU struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageU) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageU) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageU1 is an instance of MessageU with a distinct value. - MessageU1 = MessageU{"U1"} - // MessageU2 is an instance of MessageU with a distinct value. - MessageU2 = MessageU{"U2"} - // MessageU3 is an instance of MessageU with a distinct value. - MessageU3 = MessageU{"U3"} -) - -// MessageV is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageV struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageV) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageV) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageV1 is an instance of MessageV with a distinct value. - MessageV1 = MessageV{"V1"} - // MessageV2 is an instance of MessageV with a distinct value. - MessageV2 = MessageV{"V2"} - // MessageV3 is an instance of MessageV with a distinct value. - MessageV3 = MessageV{"V3"} -) - -// MessageW is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageW struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageW) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageW) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageW1 is an instance of MessageW with a distinct value. - MessageW1 = MessageW{"W1"} - // MessageW2 is an instance of MessageW with a distinct value. - MessageW2 = MessageW{"W2"} - // MessageW3 is an instance of MessageW with a distinct value. - MessageW3 = MessageW{"W3"} -) - -// MessageX is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageX struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageX) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageX) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageX1 is an instance of MessageX with a distinct value. - MessageX1 = MessageX{"X1"} - // MessageX2 is an instance of MessageX with a distinct value. - MessageX2 = MessageX{"X2"} - // MessageX3 is an instance of MessageX with a distinct value. - MessageX3 = MessageX{"X3"} -) - -// MessageY is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageY struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageY) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageY) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageY1 is an instance of MessageY with a distinct value. - MessageY1 = MessageY{"Y1"} - // MessageY2 is an instance of MessageY with a distinct value. - MessageY2 = MessageY{"Y2"} - // MessageY3 is an instance of MessageY with a distinct value. - MessageY3 = MessageY{"Y3"} -) - -// MessageZ is a type used as a dogma.Message in tests. -// Deprecated: Use Command, Event or Timeout instead. -type MessageZ struct { - Value any -} - -// Validate returns m.Value if it implements the error interface. -func (m MessageZ) Validate() error { - err, _ := m.Value.(error) - return err -} - -// MessageDescription returns a human-readable description of the message. -func (m MessageZ) MessageDescription() string { - return fmt.Sprintf("%v", m) -} - -var ( - // MessageZ1 is an instance of MessageZ with a distinct value. - MessageZ1 = MessageZ{"Z1"} - // MessageZ2 is an instance of MessageZ with a distinct value. - MessageZ2 = MessageZ{"Z2"} - // MessageZ3 is an instance of MessageZ with a distinct value. - MessageZ3 = MessageZ{"Z3"} -) diff --git a/fixtures/process.go b/fixtures/process.go deleted file mode 100644 index d49bef1..0000000 --- a/fixtures/process.go +++ /dev/null @@ -1,79 +0,0 @@ -package fixtures - -import ( - "context" - - "github.com/dogmatiq/dogma" -) - -// ProcessRoot is a test implementation of [dogma.ProcessRoot]. -type ProcessRoot struct { - Value any -} - -var _ dogma.ProcessRoot = &ProcessRoot{} - -// ProcessMessageHandler is a test implementation of -// [dogma.ProcessMessageHandler]. -type ProcessMessageHandler struct { - NewFunc func() dogma.ProcessRoot - ConfigureFunc func(dogma.ProcessConfigurer) - RouteEventToInstanceFunc func(context.Context, dogma.Event) (string, bool, error) - HandleEventFunc func(context.Context, dogma.ProcessRoot, dogma.ProcessEventScope, dogma.Event) error - HandleTimeoutFunc func(context.Context, dogma.ProcessRoot, dogma.ProcessTimeoutScope, dogma.Timeout) error -} - -var _ dogma.ProcessMessageHandler = &ProcessMessageHandler{} - -// Configure describes the handler's configuration to the engine. -func (h *ProcessMessageHandler) Configure(c dogma.ProcessConfigurer) { - if h.ConfigureFunc != nil { - h.ConfigureFunc(c) - } -} - -// New returns a process root instance in its initial state. -func (h *ProcessMessageHandler) New() dogma.ProcessRoot { - if h.NewFunc != nil { - return h.NewFunc() - } - return &ProcessRoot{} -} - -// RouteEventToInstance returns the ID of the instance that handles a specific -// event. -func (h *ProcessMessageHandler) RouteEventToInstance( - ctx context.Context, - e dogma.Event, -) (string, bool, error) { - if h.RouteEventToInstanceFunc == nil { - panic(dogma.UnexpectedMessage) - } - return h.RouteEventToInstanceFunc(ctx, e) -} - -// HandleEvent begins or continues the process in response to an event. -func (h *ProcessMessageHandler) HandleEvent( - ctx context.Context, - r dogma.ProcessRoot, - s dogma.ProcessEventScope, - e dogma.Event, -) error { - if h.HandleEventFunc != nil { - return h.HandleEventFunc(ctx, r, s, e) - } - return nil -} - -// HandleTimeout continues the process in response to a timeout. -func (h *ProcessMessageHandler) HandleTimeout( - ctx context.Context, - r dogma.ProcessRoot, - s dogma.ProcessTimeoutScope, - t dogma.Timeout, -) error { - if h.HandleTimeoutFunc != nil { - return h.HandleTimeoutFunc(ctx, r, s, t) - } - return nil -} diff --git a/fixtures/projection.go b/fixtures/projection.go deleted file mode 100644 index 40a3a2d..0000000 --- a/fixtures/projection.go +++ /dev/null @@ -1,73 +0,0 @@ -package fixtures - -import ( - "context" - - "github.com/dogmatiq/dogma" -) - -// ProjectionMessageHandler is a test implementation of -// [dogma.ProjectionMessageHandler]. -type ProjectionMessageHandler struct { - ConfigureFunc func(dogma.ProjectionConfigurer) - HandleEventFunc func(context.Context, []byte, []byte, []byte, dogma.ProjectionEventScope, dogma.Event) (bool, error) - ResourceVersionFunc func(context.Context, []byte) ([]byte, error) - CloseResourceFunc func(context.Context, []byte) error - CompactFunc func(context.Context, dogma.ProjectionCompactScope) error -} - -var _ dogma.ProjectionMessageHandler = &ProjectionMessageHandler{} - -// Configure describes the handler's configuration to the engine. -func (h *ProjectionMessageHandler) Configure(c dogma.ProjectionConfigurer) { - if h.ConfigureFunc != nil { - h.ConfigureFunc(c) - } -} - -// HandleEvent updates the projection to reflect the occurrence of an event. -func (h *ProjectionMessageHandler) HandleEvent( - ctx context.Context, - r, c, n []byte, - s dogma.ProjectionEventScope, - e dogma.Event, -) (bool, error) { - if h.HandleEventFunc != nil { - return h.HandleEventFunc(ctx, r, c, n, s, e) - } - return true, nil -} - -// ResourceVersion returns the current version of a resource. -func (h *ProjectionMessageHandler) ResourceVersion( - ctx context.Context, - r []byte, -) ([]byte, error) { - if h.ResourceVersionFunc != nil { - return h.ResourceVersionFunc(ctx, r) - } - return nil, nil -} - -// CloseResource informs the handler that the engine has no further use for -// a resource. -func (h *ProjectionMessageHandler) CloseResource( - ctx context.Context, - r []byte, -) error { - if h.CloseResourceFunc != nil { - return h.CloseResourceFunc(ctx, r) - } - return nil -} - -// Compact attempts to reduce the size of the projection. -func (h *ProjectionMessageHandler) Compact( - ctx context.Context, - s dogma.ProjectionCompactScope, -) error { - if h.CompactFunc != nil { - return h.CompactFunc(ctx, s) - } - return nil -}