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.
Improve "speculative" detection of dynamically constructed variadics.
- Loading branch information
Showing
6 changed files
with
320 additions
and
123 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
44 changes: 0 additions & 44 deletions
44
config/staticconfig/testdata/handler-with-appended-routes.md
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
config/staticconfig/testdata/handler-with-speculative-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,83 @@ | ||
# Handler with speculative routes | ||
|
||
This test verifies that the static analyzer correctly identifies routes as | ||
"speculative" under various complex conditions. | ||
|
||
Some of these scenarios could be improved, potentially avoiding false positives | ||
for the "speculative" flag. In general, however, it is preferred that the | ||
analyzer errs on the side of caution and marks routes as "speculative" when it | ||
is unsure. | ||
|
||
```au:output au:group=matrix | ||
valid application github.com/dogmatiq/enginekit/config/staticconfig.App (value unavailable) | ||
- valid identity app/e4183527-c234-42d5-8709-3dc8b9d5caa4 | ||
- valid integration github.com/dogmatiq/enginekit/config/staticconfig.Integration (value unavailable) | ||
- valid identity handler/5752bb84-0b65-4a7f-b2fa-bfb77a53a97f | ||
- valid speculative handles-command route for github.com/dogmatiq/enginekit/enginetest/stubs.CommandStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA] (type unavailable) | ||
- valid speculative records-event route for github.com/dogmatiq/enginekit/enginetest/stubs.EventStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA] (type unavailable) | ||
``` | ||
|
||
## Random index | ||
|
||
```go au:input au:group=matrix | ||
package app | ||
|
||
import "context" | ||
import "math/rand" | ||
import "github.com/dogmatiq/dogma" | ||
import "github.com/dogmatiq/enginekit/enginetest/stubs" | ||
|
||
type Integration struct{} | ||
|
||
func (Integration) Configure(c dogma.IntegrationConfigurer) { | ||
c.Identity("handler", "5752bb84-0b65-4a7f-b2fa-bfb77a53a97f") | ||
|
||
routes := make([]dogma.IntegrationRoute, 0) | ||
|
||
routes[0] = dogma.HandlesCommand[stubs.CommandStub[stubs.TypeA]]() | ||
routes[rand.Int()] = dogma.RecordsEvent[stubs.EventStub[stubs.TypeA]]() | ||
|
||
c.Routes(routes...) | ||
} | ||
|
||
func (Integration) HandleCommand(context.Context, dogma.IntegrationCommandScope, dogma.Command) error { return nil } | ||
|
||
type App struct{} | ||
|
||
func (App) Configure(c dogma.ApplicationConfigurer) { | ||
c.Identity("app", "e4183527-c234-42d5-8709-3dc8b9d5caa4") | ||
c.RegisterIntegration(Integration{}) | ||
} | ||
``` | ||
|
||
## Colliding indices | ||
|
||
```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("handler", "5752bb84-0b65-4a7f-b2fa-bfb77a53a97f") | ||
|
||
routes := make([]dogma.IntegrationRoute, 0) | ||
|
||
routes[0] = dogma.HandlesCommand[stubs.CommandStub[stubs.TypeA]]() | ||
routes[0] = dogma.RecordsEvent[stubs.EventStub[stubs.TypeA]]() | ||
|
||
c.Routes(routes...) | ||
} | ||
|
||
func (Integration) HandleCommand(context.Context, dogma.IntegrationCommandScope, dogma.Command) error { return nil } | ||
|
||
type App struct{} | ||
|
||
func (App) Configure(c dogma.ApplicationConfigurer) { | ||
c.Identity("app", "e4183527-c234-42d5-8709-3dc8b9d5caa4") | ||
c.RegisterIntegration(Integration{}) | ||
} | ||
``` |
111 changes: 111 additions & 0 deletions
111
config/staticconfig/testdata/handler-with-variadic-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,111 @@ | ||
# Handler with variadic routes | ||
|
||
This test verifies that the static analyzer correctly identifies routes that are | ||
configured via a slice which is used as the variadic parameter to the `Routes()` | ||
method. | ||
|
||
```au:output au:group=matrix | ||
valid application github.com/dogmatiq/enginekit/config/staticconfig.App (value unavailable) | ||
- valid identity app/e4183527-c234-42d5-8709-3dc8b9d5caa4 | ||
- valid integration github.com/dogmatiq/enginekit/config/staticconfig.Integration (value unavailable) | ||
- valid identity handler/5752bb84-0b65-4a7f-b2fa-bfb77a53a97f | ||
- valid handles-command route for github.com/dogmatiq/enginekit/enginetest/stubs.CommandStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA] (type unavailable) | ||
- valid records-event route for github.com/dogmatiq/enginekit/enginetest/stubs.EventStub[github.com/dogmatiq/enginekit/enginetest/stubs.TypeA] (type unavailable) | ||
``` | ||
|
||
## Appended | ||
|
||
```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("handler", "5752bb84-0b65-4a7f-b2fa-bfb77a53a97f") | ||
|
||
var routes []dogma.IntegrationRoute | ||
|
||
routes = append( | ||
routes, | ||
dogma.HandlesCommand[stubs.CommandStub[stubs.TypeA]](), | ||
dogma.RecordsEvent[stubs.EventStub[stubs.TypeA]](), | ||
) | ||
|
||
c.Routes(routes...) | ||
} | ||
|
||
func (Integration) HandleCommand(context.Context, dogma.IntegrationCommandScope, dogma.Command) error { return nil } | ||
|
||
type App struct{} | ||
|
||
func (App) Configure(c dogma.ApplicationConfigurer) { | ||
c.Identity("app", "e4183527-c234-42d5-8709-3dc8b9d5caa4") | ||
c.RegisterIntegration(Integration{}) | ||
} | ||
``` | ||
|
||
## Assigned to index | ||
|
||
```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("handler", "5752bb84-0b65-4a7f-b2fa-bfb77a53a97f") | ||
|
||
routes := make([]dogma.IntegrationRoute, 1) | ||
routes[0] = dogma.HandlesCommand[stubs.CommandStub[stubs.TypeA]]() | ||
routes[1] = dogma.RecordsEvent[stubs.EventStub[stubs.TypeA]]() | ||
|
||
c.Routes(routes...) | ||
} | ||
|
||
func (Integration) HandleCommand(context.Context, dogma.IntegrationCommandScope, dogma.Command) error { return nil } | ||
|
||
type App struct{} | ||
|
||
func (App) Configure(c dogma.ApplicationConfigurer) { | ||
c.Identity("app", "e4183527-c234-42d5-8709-3dc8b9d5caa4") | ||
c.RegisterIntegration(Integration{}) | ||
} | ||
``` | ||
|
||
## Assigned to index of sub-slice | ||
|
||
```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("handler", "5752bb84-0b65-4a7f-b2fa-bfb77a53a97f") | ||
|
||
routes := make([]dogma.IntegrationRoute, 1) | ||
routes[:1][0] = dogma.HandlesCommand[stubs.CommandStub[stubs.TypeA]]() | ||
routes[1:][0] = dogma.RecordsEvent[stubs.EventStub[stubs.TypeA]]() | ||
|
||
c.Routes(routes...) | ||
} | ||
|
||
func (Integration) HandleCommand(context.Context, dogma.IntegrationCommandScope, dogma.Command) error { return nil } | ||
|
||
type App struct{} | ||
|
||
func (App) Configure(c dogma.ApplicationConfigurer) { | ||
c.Identity("app", "e4183527-c234-42d5-8709-3dc8b9d5caa4") | ||
c.RegisterIntegration(Integration{}) | ||
} | ||
``` |
Oops, something went wrong.