matcha icon indicating copy to clipboard operation
matcha copied to clipboard

BUG: Unchecked type assertions in HTTP plugin tests

Open andrinoff opened this issue 7 months ago • 1 comments

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

  1. Examine plugin/http_test.go line 51:
if status := tbl.RawGetString("status"); status.(lua.LNumber) != 200 {
    // Panics if status is not lua.LNumber
}
  1. Examine line 58:
headers := tbl.RawGetString("headers").(*lua.LTable)
// Panics if headers is not *lua.LTable
  1. Examine line 99:
tbl := res.(*lua.LTable)
// Panics if res is not *lua.LTable
  1. 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

andrinoff avatar Apr 21 '26 09:04 andrinoff

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.

floatpanebot avatar May 22 '26 06:05 floatpanebot