Skip to content

test(core): cover the variadic form of response.exit and response.say - #13771

Open
AlinsRan wants to merge 1 commit into
apache:masterfrom
AlinsRan:test/response-variadic
Open

test(core): cover the variadic form of response.exit and response.say#13771
AlinsRan wants to merge 1 commit into
apache:masterfrom
AlinsRan:test/response-variadic

Conversation

@AlinsRan

@AlinsRan AlinsRan commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

resp_exit is variadic — it accepts a non-numeric first argument (no status code), and any number of body parts which are printed in order, with tables encoded as JSON:

local function resp_exit(code, ...)
    ...
    if code and type(code) ~= "number" then
        idx = idx + 1
        t[idx] = code
        code = nil
    end

t/core/response.t only ever calls exit(code, body), so none of that is covered, and _M.say is not exercised at all. apisix/plugins/mcp/server_wrapper.lua already depends on the variadic form:

return core.response.exit(message_handler(conf, ctx, opts))

Changes

Three tests, no production code touched:

  • TEST 9 — exit("done\n"): no status code, body still written, response stays 200
  • TEST 10 — exit(201, "a", {b = "b"}, "c\n"): parts printed in order, the table encoded as JSON
  • TEST 11 — say("a", "b", "c\n")

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation accordingly
  • I have verified that the change is backward compatible

response.t only exercised exit(code, body). The variadic form that
resp_exit actually implements -- a non-numeric first argument, and
several body parts in one call -- had no coverage, nor did say().

Signed-off-by: AlinsRan <alinsran@apache.org>
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant