From 969ac6e04bd15495c2ad189fd328f541e183ec90 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Mon, 9 Feb 2026 19:45:04 -0600 Subject: [PATCH] add test for module registraion --- internal/module/test/module_test.go | 81 +++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 internal/module/test/module_test.go diff --git a/internal/module/test/module_test.go b/internal/module/test/module_test.go new file mode 100644 index 0000000..3889399 --- /dev/null +++ b/internal/module/test/module_test.go @@ -0,0 +1,81 @@ +package module_test + +import ( + "context" + "testing" + + "github.com/jwetzell/showbridge-go/internal/config" + "github.com/jwetzell/showbridge-go/internal/module" +) + +type TestModule struct { +} + +func (m *TestModule) Output(ctx context.Context, payload any) error { + return nil +} + +func (m *TestModule) Start(ctx context.Context) error { + <-ctx.Done() + return nil +} + +func (m *TestModule) Stop() {} + +func (m *TestModule) Type() string { + return "module.test" +} + +func (m *TestModule) Id() string { + return "test" +} + +func TestModuleBadRegistrationNoType(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Fatalf("module registration should have panicked but did not") + } + }() + + module.RegisterModule(module.ModuleRegistration{ + Type: "", + New: func(config config.ModuleConfig) (module.Module, error) { + return &TestModule{}, nil + }, + }) +} + +func TestModuleBadRegistrationNoNew(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Fatalf("processor registration should have panicked but did not") + } + }() + + module.RegisterModule(module.ModuleRegistration{ + Type: "module.test", + New: nil, + }) +} + +func TestModuleBadRegistrationExistingType(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Fatalf("processor registration should have panicked but did not") + } + }() + + module.RegisterModule(module.ModuleRegistration{ + Type: "module.test", + New: func(config config.ModuleConfig) (module.Module, error) { + return &TestModule{}, nil + }, + }) + + module.RegisterModule(module.ModuleRegistration{ + Type: "module.test", + New: func(config config.ModuleConfig) (module.Module, error) { + return &TestModule{}, nil + }, + }) +}