From 9d6c3e3afb774d82d134eab84d02cf923a639ad7 Mon Sep 17 00:00:00 2001 From: James Harris Date: Thu, 11 Jul 2024 06:45:07 +1000 Subject: [PATCH] Ignore disabled handlers when enabling handlers by pattern. --- test.go | 6 +++--- test_test.go | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/test.go b/test.go index c248d3e2..dfea739c 100644 --- a/test.go +++ b/test.go @@ -228,8 +228,8 @@ 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 } @@ -237,7 +237,7 @@ func (t *Test) enableHandlersLike(patterns []string, enable bool) *Test { 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, )) diff --git a/test_test.go b/test_test.go index 7e938a78..21101d85 100644 --- a/test_test.go +++ b/test_test.go @@ -164,7 +164,29 @@ var _ = g.Describe("type Test", func() { Expect(func() { Begin(&testingmock.T{}, app). EnableHandlersLike(`^\" application does not have any handlers with names that match the regular expression: ^\" application does not have any handlers with names that match the regular expression (^\", "7d5b218d-d69b-48d5-8831-2af77561ee62") + c.RegisterProjection(&ProjectionMessageHandler{ + ConfigureFunc: func(c dogma.ProjectionConfigurer) { + c.Identity("", "fb5f05c0-589c-4d64-9599-a4875b5a3569") + c.Routes( + dogma.HandlesEvent[MessageE](), + ) + c.Disable() + }, + }) + }, + } + + Expect(func() { + Begin(&testingmock.T{}, app). + EnableHandlersLike(`^\" application does not have any handlers with names that match the regular expression (^\" application does not have any handlers with names that match the regular expression: ^\" application does not have any handlers with names that match the regular expression (^\