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,57 @@ func TestTimeIntervalFromRegistry(t *testing.T) {
t.Fatalf("time.interval module has wrong type: %s", moduleInstance.Type())
}
}
func TestBadTimeInterval(t *testing.T) {
tests := []struct {
name string
params map[string]any
errorString string
}{
{
name: "no duration param",
params: map[string]any{},
errorString: "time.interval requires a duration parameter",
},
{
name: "non-number duration param",
params: map[string]any{
"duration": "8000",
},
errorString: "time.interval duration must be a number",
},
}
for _, test := range tests {
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 {
if test.errorString != err.Error() {
t.Fatalf("time.interval got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
err = moduleInstance.Start(t.Context())
if err == nil {
t.Fatalf("time.interval expected to fail")
}
if err.Error() != test.errorString {
t.Fatalf("time.interval got error '%s', expected '%s'", err.Error(), test.errorString)
}
})
}
}