standardize layout of bad tests

This commit is contained in:
Joel Wetzell
2026-03-02 12:34:46 -06:00
parent cd1b5e1437
commit f68312ee84
3 changed files with 65 additions and 197 deletions

View File

@@ -26,78 +26,6 @@ func TestUintParseFromRegistry(t *testing.T) {
}
}
func TestUintParseBadConfigBaseString(t *testing.T) {
registration, ok := processor.ProcessorRegistry["uint.parse"]
if !ok {
t.Fatalf("uint.parse processor not registered")
}
_, err := registration.New(config.ProcessorConfig{
Type: "uint.parse",
Params: map[string]any{
"base": "10",
},
})
if err == nil {
t.Fatalf("uint.parse should have returned an error for bad base config")
}
}
func TestUintParseBadConfigBitSizeString(t *testing.T) {
registration, ok := processor.ProcessorRegistry["uint.parse"]
if !ok {
t.Fatalf("uint.parse processor not registered")
}
_, err := registration.New(config.ProcessorConfig{
Type: "uint.parse",
Params: map[string]any{
"bitSize": "64",
},
})
if err == nil {
t.Fatalf("uint.parse should have returned an error for bad bitSize config")
}
}
func TestUintParseGoodConfig(t *testing.T) {
registration, ok := processor.ProcessorRegistry["uint.parse"]
if !ok {
t.Fatalf("uint.parse processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "uint.parse",
Params: map[string]any{
"base": 10.0,
"bitSize": 64.0,
},
})
if err != nil {
t.Fatalf("uint.parse should have created processor but got error: %s", err)
}
payload := "12345"
expected := uint64(12345)
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("uint.parse processing failed: %s", err)
}
gotUint, ok := got.(uint64)
if !ok {
t.Fatalf("uint.parse returned a %T payload: %s", got, got)
}
if gotUint != expected {
t.Fatalf("uint.parse got %d, expected %d", gotUint, expected)
}
}
func TestGoodUintParse(t *testing.T) {
tests := []struct {
@@ -171,6 +99,24 @@ func TestBadUintParse(t *testing.T) {
payload any
errorString string
}{
{
name: "non-string base",
params: map[string]any{
"base": "10",
"bitSize": 64,
},
payload: "12345",
errorString: "uint.parse base error: not a number",
},
{
name: "non-string bitSize",
params: map[string]any{
"base": 10,
"bitSize": "64",
},
payload: "12345",
errorString: "uint.parse bitSize error: not a number",
},
{
name: "non-string input",
params: map[string]any{"base": 10, "bitSize": 64},
@@ -203,6 +149,13 @@ func TestBadUintParse(t *testing.T) {
Params: test.params,
})
if err != nil {
if err.Error() != test.errorString {
t.Fatalf("uint.parse got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
if err == nil {