From e6aaffbb95de24f3db389ee7528aa897c3802790 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Tue, 10 Feb 2026 20:49:40 -0600 Subject: [PATCH] add error tests for script.wasm --- internal/processor/test/script-wasm_test.go | 82 ++++++++++++--------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/internal/processor/test/script-wasm_test.go b/internal/processor/test/script-wasm_test.go index 68e0c24..886ee4b 100644 --- a/internal/processor/test/script-wasm_test.go +++ b/internal/processor/test/script-wasm_test.go @@ -30,40 +30,6 @@ func TestScriptWASMFromRegistry(t *testing.T) { } -func TestScriptWASMNoPath(t *testing.T) { - registration, ok := processor.ProcessorRegistry["script.wasm"] - if !ok { - t.Fatalf("script.wasm processor not registered") - } - - _, err := registration.New(config.ProcessorConfig{ - Type: "script.wasm", - Params: map[string]any{}, - }) - - if err == nil { - t.Fatalf("script.wasm processor should have thrown an error when creating") - } -} - -func TestScriptWASMBadConfigWrongPathType(t *testing.T) { - registration, ok := processor.ProcessorRegistry["script.wasm"] - if !ok { - t.Fatalf("script.wasm processor not registered") - } - - _, err := registration.New(config.ProcessorConfig{ - Type: "script.wasm", - Params: map[string]any{ - "path": 12345, - }, - }) - - if err == nil { - t.Fatalf("script.wasm processor should have thrown an error when creating with non-string path") - } -} - func TestGoodScriptWASM(t *testing.T) { tests := []struct { name string @@ -133,6 +99,39 @@ func TestBadScriptWASM(t *testing.T) { payload any errorString string }{ + { + name: "no path parameter", + params: map[string]any{}, + payload: []byte("hello"), + errorString: "script.wasm requires a path parameter", + }, + { + name: "non-string path parameter", + params: map[string]any{ + "path": 12345, + }, + payload: []byte("hello"), + errorString: "script.wasm path must be a string", + }, + { + name: "non-string function", + params: map[string]any{ + "path": "good.wasm", + "enableWasi": true, + "function": 12345, + }, + payload: []byte("hello"), + errorString: "script.wasm function must be a string", + }, + { + name: "non-boolean enableWasi", + params: map[string]any{ + "path": "good.wasm", + "enableWasi": "true", + }, + payload: []byte("hello"), + errorString: "script.wasm enableWasi must be a boolean", + }, { name: "non-byte slice input", params: map[string]any{ @@ -152,6 +151,14 @@ func TestBadScriptWASM(t *testing.T) { payload: []byte("hello"), errorString: "unknown function: asdf", }, + { + name: "path doesn't exist", + params: map[string]any{ + "path": "asdf.wasm", + }, + payload: []byte("hello"), + errorString: "open asdf.wasm: no such file or directory", + }, } for _, test := range tests { @@ -166,6 +173,13 @@ func TestBadScriptWASM(t *testing.T) { Params: test.params, }) + if err != nil { + if test.errorString != err.Error() { + t.Fatalf("string.create got error '%s', expected '%s'", err.Error(), test.errorString) + } + return + } + got, err := processorInstance.Process(t.Context(), test.payload) if err == nil {