From 3f99f606dc688088260cfdd00656f7ac9dd220e0 Mon Sep 17 00:00:00 2001 From: akeemphilbert Date: Thu, 4 Apr 2024 10:28:16 -0400 Subject: [PATCH] feature: WS-279 made it so that command receivers are explicitly add (instead of magically via providers) --- README.md | 2 +- rest/command.go | 6 +----- rest/integration_test.go | 9 ++++++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2eec3f8f..320efe6d 100644 --- a/README.md +++ b/README.md @@ -42,4 +42,4 @@ For general help using WeOS, please refer to [the official WeOS documentation](h ## License -See the [LICENSE](./LICENSE) file for licensing information. +See the [LICENSE](./LICENSE) file for licensing information diff --git a/rest/command.go b/rest/command.go index 44b98d6d..fb95067b 100644 --- a/rest/command.go +++ b/rest/command.go @@ -15,8 +15,7 @@ const DELETE_COMMAND = "delete" type CommandDispatcherParams struct { fx.In - CommandConfigs []CommandConfig - Logger Log + Logger Log } type CommandDispatcherResult struct { @@ -29,9 +28,6 @@ func NewCommandDispatcher(p CommandDispatcherParams) CommandDispatcherResult { dispatcher := &DefaultCommandDispatcher{ handlers: make(map[string][]CommandHandler), } - for _, config := range p.CommandConfigs { - dispatcher.AddSubscriber(config) - } return CommandDispatcherResult{ Dispatcher: dispatcher, } diff --git a/rest/integration_test.go b/rest/integration_test.go index 5787490f..c9b303a5 100644 --- a/rest/integration_test.go +++ b/rest/integration_test.go @@ -31,8 +31,8 @@ func TestIntegrations(t *testing.T) { os.Setenv("WEOS_PORT", "8681") os.Setenv("WEOS_SPEC", "./fixtures/blog.yaml") //use fx Module to start the server - Receivers := func() []rest.CommandConfig { - return []rest.CommandConfig{ + Receivers := func(commandDispatcher rest.CommandDispatcher) { + handlers := []rest.CommandConfig{ { Type: "CreateBlog", Handler: func(ctx context.Context, command *rest.Command, logger rest.Log, options *rest.CommandOptions) (response rest.CommandResponse, err error) { @@ -45,8 +45,11 @@ func TestIntegrations(t *testing.T) { }, }, } + for _, handler := range handlers { + commandDispatcher.AddSubscriber(handler) + } } - app := fxtest.New(t, fx.Provide(Receivers), rest.Core, fx.Invoke(func(techo *echo.Echo) { + app := fxtest.New(t, fx.Invoke(Receivers), rest.Core, fx.Invoke(func(techo *echo.Echo) { e = techo })) defer app.RequireStop()