matcha
matcha copied to clipboard
BUG: Unchecked type assertions in HTTP plugin tests
Describe the bug In plugin/http_test.go, multiple type assertions lack ok-checks, causing panics on type mismatch instead of clear test failures.
To reproduce
- Examine plugin/http_test.go line 51:
if status := tbl.RawGetString("status"); status.(lua.LNumber) != 200 {
// Panics if status is not lua.LNumber
}
- Examine line 58:
headers := tbl.RawGetString("headers").(*lua.LTable)
// Panics if headers is not *lua.LTable
- Examine line 99:
tbl := res.(*lua.LTable)
// Panics if res is not *lua.LTable
- If HTTP response structure changes, tests panic instead of failing gracefully
Expected behavior Type assertions in test code should check ok value and fail test with descriptive error.
Additional context
- Good first issue: straightforward test robustness improvement
- Test code (not production), but panics obscure actual problems
- Line 46-49 shows correct pattern with ok-check
- Lua plugin system returns interface{} requiring type assertions
Suggested fix (line 51):
status, ok := tbl.RawGetString("status").(lua.LNumber)
if !ok {
t.Fatalf("expected status to be LNumber, got %T", tbl.RawGetString("status"))
}
if status != 200 {
t.Errorf("expected status 200, got %v", status)
}
Suggested fix (line 58):
headersVal := tbl.RawGetString("headers")
headers, ok := headersVal.(*lua.LTable)
if !ok {
t.Fatalf("expected headers to be LTable, got %T", headersVal)
}
OS All platforms
This has had no activity for 30 days. It will be closed in 14 days unless updated. Comment or remove the stale label to keep it open.