add tests for error scenarios to script.js

This commit is contained in:
Joel Wetzell
2025-12-24 20:53:25 -06:00
parent 227d042feb
commit a1275b3b69

View File

@@ -59,7 +59,7 @@ func TestScriptJSNoProgram(t *testing.T) {
} }
} }
func TestScriptJSBadConfig(t *testing.T) { func TestScriptJSBadConfigWrongProgramType(t *testing.T) {
registration, ok := processor.ProcessorRegistry["script.js"] registration, ok := processor.ProcessorRegistry["script.js"]
if !ok { if !ok {
t.Fatalf("script.js processor not registered") t.Fatalf("script.js processor not registered")
@@ -147,3 +147,33 @@ func TestGoodScriptJS(t *testing.T) {
}) })
} }
} }
func TestBadScriptJS(t *testing.T) {
tests := []struct {
name string
processor processor.Processor
payload any
errorString string
}{
{
name: "accessing not defined variable",
processor: &processor.ScriptJS{Program: `paylod = foo`},
payload: 0,
errorString: "ReferenceError: 'foo' is not defined",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := test.processor.Process(t.Context(), test.payload)
if err == nil {
t.Fatalf("script.js expected to fail but succeeded, got: %v", got)
}
if err.Error() != test.errorString {
t.Fatalf("script.js got error '%s', expected '%s'", err.Error(), test.errorString)
}
})
}
}