add basic tests for bad module creation

This commit is contained in:
Joel Wetzell
2026-02-09 19:44:54 -06:00
parent 6b178d1ae4
commit bfa63499c3
17 changed files with 1023 additions and 0 deletions

View File

@@ -33,3 +33,55 @@ func TestMIDIInputFromRegistry(t *testing.T) {
t.Fatalf("midi.input module has wrong type: %s", moduleInstance.Type())
}
}
func TestBadMIDIInput(t *testing.T) {
tests := []struct {
name string
params map[string]any
errorString string
}{
{
name: "no port param",
params: map[string]any{},
errorString: "midi.input requires a port parameter",
},
{
name: "non-string port",
params: map[string]any{"port": 123},
errorString: "midi.input port must be a string",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
registration, ok := module.ModuleRegistry["midi.input"]
if !ok {
t.Fatalf("midi.input module not registered")
}
moduleInstance, err := registration.New(config.ModuleConfig{
Id: "test",
Type: "midi.input",
Params: test.params,
})
if err != nil {
if test.errorString != err.Error() {
t.Fatalf("midi.input got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
err = moduleInstance.Start(t.Context())
if err == nil {
t.Fatalf("midi.input expected to fail")
}
if err.Error() != test.errorString {
t.Fatalf("midi.input got error '%s', expected '%s'", err.Error(), test.errorString)
}
})
}
}