generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic tests for remaining handler and route types.
- Loading branch information
Showing
11 changed files
with
256 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
config/staticconfig/testdata/aggregate.md → ...taticconfig/testdata/handler-aggregate.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Integration message handler | ||
|
||
This test ensures that the static analyzer supports all aspects of configuring | ||
an integration handler. | ||
|
||
```au:output au:group=matrix | ||
valid application github.com/dogmatiq/enginekit/config/staticconfig.App (runtime type unavailable) | ||
- valid identity app/0726ae0d-67e4-4a50-8a19-9f58eae38e51 | ||
- disabled valid integration github.com/dogmatiq/enginekit/config/staticconfig.Integration (runtime type unavailable) | ||
- valid identity integration/b92431e6-3a7d-4235-a76f-541622c487ee | ||
- valid handles-command route for github.com/dogmatiq/enginekit/enginetest/stubs.CommandStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA] (runtime type unavailable) | ||
- valid records-event route for github.com/dogmatiq/enginekit/enginetest/stubs.EventStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA] (runtime type unavailable) | ||
``` | ||
|
||
```go au:input au:group=matrix | ||
package app | ||
|
||
import "context" | ||
import "github.com/dogmatiq/dogma" | ||
import "github.com/dogmatiq/enginekit/enginetest/stubs" | ||
|
||
type Integration struct {} | ||
|
||
func (Integration) Configure(c dogma.IntegrationConfigurer) { | ||
c.Identity("integration", "b92431e6-3a7d-4235-a76f-541622c487ee") | ||
c.Routes( | ||
dogma.HandlesCommand[stubs.CommandStub[stubs.TypeA]](), | ||
dogma.RecordsEvent[stubs.EventStub[stubs.TypeA]](), | ||
) | ||
c.Disable() | ||
} | ||
|
||
type App struct{} | ||
|
||
func (App) Configure(c dogma.ApplicationConfigurer) { | ||
c.Identity("app", "0726ae0d-67e4-4a50-8a19-9f58eae38e51") | ||
c.RegisterIntegration(Integration{}) | ||
} | ||
|
||
func (Integration) HandleCommand(context.Context, dogma.IntegrationCommandScope, dogma.Command) error { return nil } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Process message handler | ||
|
||
This test ensures that the static analyzer supports all aspects of configuring | ||
a process handler. | ||
|
||
```au:output au:group=matrix | ||
valid application github.com/dogmatiq/enginekit/config/staticconfig.App (runtime type unavailable) | ||
- valid identity app/0726ae0d-67e4-4a50-8a19-9f58eae38e51 | ||
- disabled valid process github.com/dogmatiq/enginekit/config/staticconfig.Process (runtime type unavailable) | ||
- valid identity process/4ff1b1c1-5c64-49bc-a547-c13f5bafad7d | ||
- valid handles-event route for github.com/dogmatiq/enginekit/enginetest/stubs.EventStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA] (runtime type unavailable) | ||
- valid executes-command route for github.com/dogmatiq/enginekit/enginetest/stubs.CommandStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA] (runtime type unavailable) | ||
- valid schedules-timeout route for github.com/dogmatiq/enginekit/enginetest/stubs.TimeoutStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA] (runtime type unavailable) | ||
``` | ||
|
||
```go au:input au:group=matrix | ||
package app | ||
|
||
import "context" | ||
import "github.com/dogmatiq/dogma" | ||
import "github.com/dogmatiq/enginekit/enginetest/stubs" | ||
|
||
type Process struct {} | ||
|
||
func (Process) Configure(c dogma.ProcessConfigurer) { | ||
c.Identity("process", "4ff1b1c1-5c64-49bc-a547-c13f5bafad7d") | ||
c.Routes( | ||
dogma.HandlesEvent[stubs.EventStub[stubs.TypeA]](), | ||
dogma.ExecutesCommand[stubs.CommandStub[stubs.TypeA]](), | ||
dogma.SchedulesTimeout[stubs.TimeoutStub[stubs.TypeA]](), | ||
) | ||
c.Disable() | ||
} | ||
|
||
type App struct{} | ||
|
||
func (App) Configure(c dogma.ApplicationConfigurer) { | ||
c.Identity("app", "0726ae0d-67e4-4a50-8a19-9f58eae38e51") | ||
c.RegisterProcess(Process{}) | ||
} | ||
|
||
func (Process) New() dogma.ProcessRoot { return nil } | ||
func (Process) RouteEventToInstance(context.Context, dogma.Event) (string, bool, error) { return "", false, nil } | ||
func (Process) HandleEvent(context.Context, dogma.ProcessRoot, dogma.ProcessEventScope, dogma.Event) error { return nil } | ||
func (Process) HandleTimeout(context.Context, dogma.ProcessRoot, dogma.ProcessTimeoutScope, dogma.Timeout) error { return nil } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Projection message handler | ||
|
||
This test ensures that the static analyzer supports all aspects of configuring | ||
a projection handler. | ||
|
||
```au:output au:group=matrix | ||
valid application github.com/dogmatiq/enginekit/config/staticconfig.App (runtime type unavailable) | ||
- valid identity app/0726ae0d-67e4-4a50-8a19-9f58eae38e51 | ||
- disabled valid projection github.com/dogmatiq/enginekit/config/staticconfig.Projection (runtime type unavailable) | ||
- valid identity projection/238d7498-515b-44b5-b6a8-914a08762ecc | ||
- valid handles-event route for github.com/dogmatiq/enginekit/enginetest/stubs.EventStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA] (runtime type unavailable) | ||
``` | ||
|
||
```go au:input au:group=matrix | ||
package app | ||
|
||
import "context" | ||
import "github.com/dogmatiq/dogma" | ||
import "github.com/dogmatiq/enginekit/enginetest/stubs" | ||
|
||
type Projection struct {} | ||
|
||
func (Projection) Configure(c dogma.ProjectionConfigurer) { | ||
c.Identity("projection", "238d7498-515b-44b5-b6a8-914a08762ecc") | ||
c.Routes( | ||
dogma.HandlesEvent[stubs.EventStub[stubs.TypeA]](), | ||
) | ||
// c.DeliveryPolicy(dogma.BroadcastProjectionDeliveryPolicy{ | ||
// PrimaryFirst: true, | ||
// }) | ||
c.Disable() | ||
} | ||
|
||
type App struct{} | ||
|
||
func (App) Configure(c dogma.ApplicationConfigurer) { | ||
c.Identity("app", "0726ae0d-67e4-4a50-8a19-9f58eae38e51") | ||
c.RegisterProjection(Projection{}) | ||
} | ||
|
||
func (Projection) HandleEvent(context.Context, []byte, []byte, []byte, dogma.ProjectionEventScope, dogma.Event) (bool, error) { return false, nil } | ||
func (Projection) Compact(context.Context, dogma.ProjectionCompactScope) error { return nil } | ||
func (Projection) ResourceVersion(context.Context, []byte) ([]byte, error) | ||
func (Projection) CloseResource(context.Context, []byte) error | ||
``` |
79 changes: 79 additions & 0 deletions
79
config/staticconfig/testdata/handler-with-unregistered-routes.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Handler with unregistered routes | ||
|
||
This test verifies that static analyzer does not include information about | ||
routes that are constructed but never passed to the configurer's `Routes()` | ||
method. | ||
|
||
```au:output au:group=matrix | ||
valid application github.com/dogmatiq/enginekit/config/staticconfig.App (runtime type unavailable) | ||
- valid identity app/f2c08525-623e-4c76-851c-3172953269e3 | ||
- invalid integration github.com/dogmatiq/enginekit/config/staticconfig.Integration (runtime type unavailable) | ||
- no "handles-command" routes are configured | ||
- valid identity handler/ac391765-da58-4e7c-a478-e4725eb2b0e9 | ||
``` | ||
|
||
## No call to Routes() | ||
|
||
```go au:input au:group=matrix | ||
package app | ||
|
||
import ( | ||
"context" | ||
"github.com/dogmatiq/dogma" | ||
"github.com/dogmatiq/enginekit/enginetest/stubs" | ||
) | ||
|
||
type Integration struct{} | ||
|
||
func (Integration) Configure(c dogma.IntegrationConfigurer) { | ||
c.Identity("handler", "ac391765-da58-4e7c-a478-e4725eb2b0e9") | ||
dogma.HandlesCommand[stubs.CommandStub[stubs.TypeX]]() | ||
} | ||
|
||
type App struct{} | ||
|
||
func (App) Configure(c dogma.ApplicationConfigurer) { | ||
c.Identity("app", "f2c08525-623e-4c76-851c-3172953269e3") | ||
c.RegisterIntegration(Integration{}) | ||
} | ||
|
||
func (Integration) HandleCommand(context.Context, dogma.IntegrationCommandScope, dogma.Command) error { return nil } | ||
``` | ||
|
||
## Route appended to slice after calling Routes() | ||
|
||
```go au:input au:group=matrix | ||
package app | ||
|
||
import ( | ||
"context" | ||
"github.com/dogmatiq/dogma" | ||
"github.com/dogmatiq/enginekit/enginetest/stubs" | ||
) | ||
|
||
type Integration struct{} | ||
|
||
func (Integration) Configure(c dogma.IntegrationConfigurer) { | ||
c.Identity("handler", "ac391765-da58-4e7c-a478-e4725eb2b0e9") | ||
|
||
var routes []dogma.IntegrationRoute | ||
|
||
c.Routes(routes...) | ||
|
||
routes = append( | ||
routes, | ||
dogma.HandlesCommand[stubs.CommandStub[stubs.TypeX]](), | ||
) | ||
} | ||
|
||
type App struct{} | ||
|
||
func (App) Configure(c dogma.ApplicationConfigurer) { | ||
c.Identity("app", "f2c08525-623e-4c76-851c-3172953269e3") | ||
|
||
|
||
c.RegisterIntegration(Integration{}) | ||
} | ||
|
||
func (Integration) HandleCommand(context.Context, dogma.IntegrationCommandScope, dogma.Command) error { return nil } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters