mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
add tests for error scenarios to script.js
This commit is contained in:
@@ -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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user