From a217b729cd38a11c5d5945ca15db66d8c36035b0 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Mon, 9 Feb 2026 22:28:34 -0600 Subject: [PATCH] add tests for error script.wasm error scenarios --- internal/processor/test/script-wasm_test.go | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/internal/processor/test/script-wasm_test.go b/internal/processor/test/script-wasm_test.go index 17c0187..68e0c24 100644 --- a/internal/processor/test/script-wasm_test.go +++ b/internal/processor/test/script-wasm_test.go @@ -125,3 +125,56 @@ func TestGoodScriptWASM(t *testing.T) { }) } } + +func TestBadScriptWASM(t *testing.T) { + tests := []struct { + name string + params map[string]any + payload any + errorString string + }{ + { + name: "non-byte slice input", + params: map[string]any{ + "path": "good.wasm", + "enableWasi": true, + }, + payload: "hello", + errorString: "script.wasm can only operator on byte array", + }, + { + name: "function not found in module", + params: map[string]any{ + "path": "good.wasm", + "enableWasi": true, + "function": "asdf", + }, + payload: []byte("hello"), + errorString: "unknown function: asdf", + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + registration, ok := processor.ProcessorRegistry["script.wasm"] + if !ok { + t.Fatalf("script.wasm processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "script.wasm", + Params: test.params, + }) + + got, err := processorInstance.Process(t.Context(), test.payload) + + if err == nil { + t.Fatalf("script.wasm expected to fail but succeeded, got: %v", got) + } + + if err.Error() != test.errorString { + t.Fatalf("script.wasm got error '%s', expected '%s'", err.Error(), test.errorString) + } + }) + } +}