start working on startup tests for modules

This commit is contained in:
Joel Wetzell
2026-05-19 21:56:04 -05:00
parent 5db23627d6
commit 7c8695b9fe
10 changed files with 374 additions and 11 deletions
+46
View File
@@ -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