diff --git a/internal/processor/script-js_test.go b/internal/processor/script-js_test.go index 24a63dc..42b5d18 100644 --- a/internal/processor/script-js_test.go +++ b/internal/processor/script-js_test.go @@ -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"] if !ok { 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) + } + }) + } +}