diff --git a/internal/module/nats-server.go b/internal/module/nats-server.go index c7657a8..1a3131b 100644 --- a/internal/module/nats-server.go +++ b/internal/module/nats-server.go @@ -113,7 +113,6 @@ func (ns *NATSServer) Start(ctx context.Context, router common.RouteIO) error { if !natsServer.ReadyForConnections(5 * time.Second) { return errors.New("nats.server failed to start") } - ns.logger.Info("NATS server started", "client_url", natsServer.ClientURL()) <-ns.ctx.Done() diff --git a/internal/module/test/db-sqlite_test.go b/internal/module/test/db-sqlite_test.go index c23dcc6..4321eb2 100644 --- a/internal/module/test/db-sqlite_test.go +++ b/internal/module/test/db-sqlite_test.go @@ -2,6 +2,7 @@ package module_test import ( "testing" + "time" "github.com/jwetzell/showbridge-go/internal/config" "github.com/jwetzell/showbridge-go/internal/module" @@ -34,6 +35,51 @@ func TestDbSqliteFromRegistry(t *testing.T) { } } +func TestGoodDbSqlite(t *testing.T) { + + testCases := []struct { + name string + params map[string]any + }{ + { + name: "in memory db", + params: map[string]any{ + "dsn": ":memory:", + }, + }, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + + registration, ok := module.ModuleRegistry["db.sqlite"] + if !ok { + t.Fatalf("db.sqlite module not registered") + } + + moduleInstance, err := registration.New(config.ModuleConfig{ + Id: "test", + Type: "db.sqlite", + Params: test.params, + }) + + if err != nil { + t.Fatalf("db.sqlite failed to create module: %s", err) + } + // TODO(jwetzell) this is kind of hacky + go func() { + time.Sleep(1 * time.Second) + moduleInstance.Stop() + }() + err = moduleInstance.Start(t.Context(), nil) + + if err != nil { + t.Fatalf("db.sqlite failed to start: %s", err) + } + }) + } +} + func TestBadDbSqlite(t *testing.T) { tests := []struct { name string diff --git a/internal/module/test/http-server_test.go b/internal/module/test/http-server_test.go index 40aac8d..4ac9871 100644 --- a/internal/module/test/http-server_test.go +++ b/internal/module/test/http-server_test.go @@ -2,6 +2,7 @@ package module_test import ( "testing" + "time" "github.com/jwetzell/showbridge-go/internal/config" "github.com/jwetzell/showbridge-go/internal/module" @@ -34,6 +35,52 @@ func TestHTTPServerFromRegistry(t *testing.T) { } } +func TestGoodHTTPServer(t *testing.T) { + + testCases := []struct { + name string + params map[string]any + }{ + { + name: "minimal config", + params: map[string]any{ + "port": 8000, + }, + }, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + + registration, ok := module.ModuleRegistry["http.server"] + if !ok { + t.Fatalf("http.server module not registered") + } + + moduleInstance, err := registration.New(config.ModuleConfig{ + Id: "test", + Type: "http.server", + Params: test.params, + }) + + if err != nil { + t.Fatalf("http.server failed to create module: %s", err) + } + // TODO(jwetzell) this is kind of hacky + go func() { + time.Sleep(1 * time.Second) + moduleInstance.Stop() + }() + + err = moduleInstance.Start(t.Context(), nil) + + if err != nil { + t.Fatalf("http.server failed to start: %s", err) + } + }) + } +} + func TestBadHTTPServer(t *testing.T) { tests := []struct { name string diff --git a/internal/module/test/nats-server_test.go b/internal/module/test/nats-server_test.go index 52a4da5..6c9ef9d 100644 --- a/internal/module/test/nats-server_test.go +++ b/internal/module/test/nats-server_test.go @@ -2,6 +2,7 @@ package module_test import ( "testing" + "time" "github.com/jwetzell/showbridge-go/internal/config" "github.com/jwetzell/showbridge-go/internal/module" @@ -35,6 +36,52 @@ func TestNATSServerFromRegistry(t *testing.T) { } } +func TestGoodNATSServer(t *testing.T) { + + testCases := []struct { + name string + params map[string]any + }{ + { + name: "minimal config", + params: map[string]any{ + "port": 4222, + }, + }, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + + registration, ok := module.ModuleRegistry["nats.server"] + if !ok { + t.Fatalf("nats.server module not registered") + } + + moduleInstance, err := registration.New(config.ModuleConfig{ + Id: "test", + Type: "nats.server", + Params: test.params, + }) + + if err != nil { + t.Fatalf("nats.server failed to create module: %s", err) + } + // TODO(jwetzell) this is kind of hacky + go func() { + time.Sleep(1 * time.Second) + moduleInstance.Stop() + }() + + err = moduleInstance.Start(t.Context(), nil) + + if err != nil { + t.Fatalf("nats.server failed to start: %s", err) + } + }) + } +} + func TestBadNATSServer(t *testing.T) { tests := []struct { name string diff --git a/internal/module/test/tcp-server_test.go b/internal/module/test/tcp-server_test.go index cc1c997..e82f15f 100644 --- a/internal/module/test/tcp-server_test.go +++ b/internal/module/test/tcp-server_test.go @@ -2,6 +2,7 @@ package module_test import ( "testing" + "time" "github.com/jwetzell/showbridge-go/internal/config" "github.com/jwetzell/showbridge-go/internal/module" @@ -35,6 +36,52 @@ func TestTCPServerFromRegistry(t *testing.T) { } } +func TestGoodTCPServer(t *testing.T) { + + testCases := []struct { + name string + params map[string]any + }{ + { + name: "minimal config", + params: map[string]any{ + "port": 8000, + "framing": "LF", + }, + }, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + + registration, ok := module.ModuleRegistry["net.tcp.server"] + if !ok { + t.Fatalf("net.tcp.server module not registered") + } + + moduleInstance, err := registration.New(config.ModuleConfig{ + Id: "test", + Type: "net.tcp.server", + Params: test.params, + }) + + if err != nil { + t.Fatalf("net.tcp.server failed to create module: %s", err) + } + // TODO(jwetzell) this is kind of hacky + go func() { + time.Sleep(1 * time.Second) + moduleInstance.Stop() + }() + err = moduleInstance.Start(t.Context(), nil) + + if err != nil { + t.Fatalf("net.tcp.server failed to start: %s", err) + } + }) + } +} + func TestBadTCPServer(t *testing.T) { tests := []struct { name string diff --git a/internal/module/test/time-interval_test.go b/internal/module/test/time-interval_test.go index 10eb07c..794df1b 100644 --- a/internal/module/test/time-interval_test.go +++ b/internal/module/test/time-interval_test.go @@ -2,6 +2,7 @@ package module_test import ( "testing" + "time" "github.com/jwetzell/showbridge-go/internal/config" "github.com/jwetzell/showbridge-go/internal/module" @@ -34,6 +35,51 @@ func TestTimeIntervalFromRegistry(t *testing.T) { } } +func TestGoodTimeInterval(t *testing.T) { + + testCases := []struct { + name string + params map[string]any + }{ + { + name: "minimal config", + params: map[string]any{ + "duration": 1000, + }, + }, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + + registration, ok := module.ModuleRegistry["time.interval"] + if !ok { + t.Fatalf("time.interval module not registered") + } + + moduleInstance, err := registration.New(config.ModuleConfig{ + Id: "test", + Type: "time.interval", + Params: test.params, + }) + + if err != nil { + t.Fatalf("time.interval failed to create module: %s", err) + } + // TODO(jwetzell) this is kind of hacky + go func() { + time.Sleep(1 * time.Second) + moduleInstance.Stop() + }() + err = moduleInstance.Start(t.Context(), nil) + + if err != nil { + t.Fatalf("time.interval failed to start: %s", err) + } + }) + } +} + func TestBadTimeInterval(t *testing.T) { tests := []struct { name string diff --git a/internal/module/test/time-timer_test.go b/internal/module/test/time-timer_test.go index c02870b..b09674f 100644 --- a/internal/module/test/time-timer_test.go +++ b/internal/module/test/time-timer_test.go @@ -2,6 +2,7 @@ package module_test import ( "testing" + "time" "github.com/jwetzell/showbridge-go/internal/config" "github.com/jwetzell/showbridge-go/internal/module" @@ -34,6 +35,51 @@ func TestTimeTimerFromRegistry(t *testing.T) { } } +func TestGoodTimeTimer(t *testing.T) { + + testCases := []struct { + name string + params map[string]any + }{ + { + name: "minimal config", + params: map[string]any{ + "duration": 2000, + }, + }, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + + registration, ok := module.ModuleRegistry["time.timer"] + if !ok { + t.Fatalf("time.timer module not registered") + } + + moduleInstance, err := registration.New(config.ModuleConfig{ + Id: "test", + Type: "time.timer", + Params: test.params, + }) + + if err != nil { + t.Fatalf("time.timer failed to create module: %s", err) + } + // TODO(jwetzell) this is kind of hacky + go func() { + time.Sleep(1 * time.Second) + moduleInstance.Stop() + }() + err = moduleInstance.Start(t.Context(), nil) + + if err != nil { + t.Fatalf("time.timer failed to start: %s", err) + } + }) + } +} + func TestBadTimeTimer(t *testing.T) { tests := []struct { name string diff --git a/internal/module/test/udp-client_test.go b/internal/module/test/udp-client_test.go index bda415f..fb3035a 100644 --- a/internal/module/test/udp-client_test.go +++ b/internal/module/test/udp-client_test.go @@ -2,6 +2,7 @@ package module_test import ( "testing" + "time" "github.com/jwetzell/showbridge-go/internal/config" "github.com/jwetzell/showbridge-go/internal/module" @@ -36,6 +37,53 @@ func TestUDPClientFromRegistry(t *testing.T) { } } +func TestGoodUDPClient(t *testing.T) { + + testCases := []struct { + name string + params map[string]any + }{ + { + name: "minimal config", + params: map[string]any{ + "host": "localhost", + "port": 8000, + }, + }, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + + registration, ok := module.ModuleRegistry["net.udp.client"] + if !ok { + t.Fatalf("net.udp.client module not registered") + } + + moduleInstance, err := registration.New(config.ModuleConfig{ + Id: "test", + Type: "net.udp.client", + Params: test.params, + }) + + if err != nil { + t.Fatalf("net.udp.client failed to create module: %s", err) + } + // TODO(jwetzell) this is kind of hacky + go func() { + time.Sleep(1 * time.Second) + moduleInstance.Stop() + }() + + err = moduleInstance.Start(t.Context(), nil) + + if err != nil { + t.Fatalf("net.udp.client failed to start: %s", err) + } + }) + } +} + func TestBadUDPClient(t *testing.T) { tests := []struct { name string diff --git a/internal/module/test/udp-server_test.go b/internal/module/test/udp-server_test.go index 03b477f..127a0e1 100644 --- a/internal/module/test/udp-server_test.go +++ b/internal/module/test/udp-server_test.go @@ -2,6 +2,7 @@ package module_test import ( "testing" + "time" "github.com/jwetzell/showbridge-go/internal/config" "github.com/jwetzell/showbridge-go/internal/module" @@ -34,6 +35,52 @@ func TestUDPServerFromRegistry(t *testing.T) { } } +func TestGoodUDPServer(t *testing.T) { + + testCases := []struct { + name string + params map[string]any + }{ + { + name: "minimal config", + params: map[string]any{ + "port": 8000, + }, + }, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + + registration, ok := module.ModuleRegistry["net.udp.server"] + if !ok { + t.Fatalf("net.udp.server module not registered") + } + + moduleInstance, err := registration.New(config.ModuleConfig{ + Id: "test", + Type: "net.udp.server", + Params: test.params, + }) + + if err != nil { + t.Fatalf("net.udp.server failed to create module: %s", err) + } + // TODO(jwetzell) this is kind of hacky + go func() { + time.Sleep(1 * time.Second) + moduleInstance.Stop() + }() + + err = moduleInstance.Start(t.Context(), nil) + + if err != nil { + t.Fatalf("net.udp.server failed to start: %s", err) + } + }) + } +} + func TestBadUDPServer(t *testing.T) { tests := []struct { name string diff --git a/internal/processor/test/db-query_test.go b/internal/processor/test/db-query_test.go index a8d96fb..3341c87 100644 --- a/internal/processor/test/db-query_test.go +++ b/internal/processor/test/db-query_test.go @@ -242,16 +242,6 @@ func TestBadDbQuery(t *testing.T) { wrappedPayloadModules: map[string]common.Module{}, errorString: "db.query unable to find module with id: test", }, - { - name: "module not found in context", - payload: test.TestStruct{Data: "hello"}, - params: map[string]any{ - "module": "test", - "query": "select * from test;", - }, - wrappedPayloadModules: map[string]common.Module{}, - errorString: "db.query unable to find module with id: test", - }, { name: "module not a DatabseModule", payload: test.TestStruct{Data: "hello"},