Skip to content

Commit

Permalink
Ignore disabled handlers when enabling handlers by pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Jul 16, 2024
1 parent a99922b commit 9d6c3e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
6 changes: 3 additions & 3 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,16 @@ func (t *Test) enableHandlersLike(patterns []string, enable bool) *Test {
re := regexp.MustCompile(p)
matched := false

for ident := range t.app.Handlers() {
if re.MatchString(ident.Name) {
for ident, h := range t.app.Handlers() {
if !h.IsDisabled() && re.MatchString(ident.Name) {
names[ident.Name] = struct{}{}
matched = true
}
}

if !matched {
panic(fmt.Sprintf(
"the %q application does not have any handlers with names that match the regular expression: %s",
"the %q application does not have any handlers with names that match the regular expression (%s), or all such handlers have been disabled by a call to ProjectionConfigurer.Disable()",
t.app.Identity().Name,
p,
))
Expand Down
26 changes: 24 additions & 2 deletions test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,29 @@ var _ = g.Describe("type Test", func() {
Expect(func() {
Begin(&testingmock.T{}, app).
EnableHandlersLike(`^\<proj`)
}).To(PanicWith(`the "<app>" application does not have any handlers with names that match the regular expression: ^\<proj`))
}).To(PanicWith(`the "<app>" application does not have any handlers with names that match the regular expression (^\<proj), or all such handlers have been disabled by a call to ProjectionConfigurer.Disable()`))
})

g.It("does not enable handlers that are disabled by their own configuration", func() {
app := &Application{
ConfigureFunc: func(c dogma.ApplicationConfigurer) {
c.Identity("<app>", "7d5b218d-d69b-48d5-8831-2af77561ee62")
c.RegisterProjection(&ProjectionMessageHandler{
ConfigureFunc: func(c dogma.ProjectionConfigurer) {
c.Identity("<projection>", "fb5f05c0-589c-4d64-9599-a4875b5a3569")
c.Routes(
dogma.HandlesEvent[MessageE](),
)
c.Disable()
},
})
},
}

Expect(func() {
Begin(&testingmock.T{}, app).
EnableHandlersLike(`^\<proj`)
}).To(PanicWith(`the "<app>" application does not have any handlers with names that match the regular expression (^\<proj), or all such handlers have been disabled by a call to ProjectionConfigurer.Disable()`))
})
})

Expand Down Expand Up @@ -256,7 +278,7 @@ var _ = g.Describe("type Test", func() {
Expect(func() {
Begin(&testingmock.T{}, app).
DisableHandlersLike(`^\<proj`)
}).To(PanicWith(`the "<app>" application does not have any handlers with names that match the regular expression: ^\<proj`))
}).To(PanicWith(`the "<app>" application does not have any handlers with names that match the regular expression (^\<proj), or all such handlers have been disabled by a call to ProjectionConfigurer.Disable()`))
})
})
})

0 comments on commit 9d6c3e3

Please sign in to comment.