add error tests for random processors

This commit is contained in:
Joel Wetzell
2026-02-08 15:56:14 -06:00
parent 4bbf69e644
commit 7312bfec20
2 changed files with 144 additions and 0 deletions

View File

@@ -103,3 +103,75 @@ func TestGoodUintRandom(t *testing.T) {
})
}
}
func TestBadUintRandom(t *testing.T) {
tests := []struct {
name string
params map[string]any
payload any
errorString string
}{
{
name: "no min param",
payload: "hello",
params: map[string]any{"max": 10.0},
errorString: "uint.random requires a min parameter",
},
{
name: "no max param",
payload: "hello",
params: map[string]any{"min": 1.0},
errorString: "uint.random requires a max parameter",
},
{
name: "min param not a number",
payload: "hello",
params: map[string]any{"min": "1", "max": 10.0},
errorString: "uint.random min must be a number",
},
{
name: "max param not a number",
payload: "hello",
params: map[string]any{"min": 1.0, "max": "10"},
errorString: "uint.random max must be a number",
},
{
name: "max less than min",
payload: "hello",
params: map[string]any{"min": 1.0, "max": 0.0},
errorString: "uint.random max must be greater than min",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
registration, ok := processor.ProcessorRegistry["uint.random"]
if !ok {
t.Fatalf("uint.random processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "uint.random",
Params: test.params,
})
if err != nil {
if test.errorString != err.Error() {
t.Fatalf("uint.random got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
if err == nil {
t.Fatalf("uint.random expected to fail but got payload: %s", got)
}
if err.Error() != test.errorString {
t.Fatalf("uint.random got error '%s', expected '%s'", err.Error(), test.errorString)
}
})
}
}