1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
pcall(require, "luarocks.require")
require "wsapi.mock"
local connector = require "wsapi.mock"
function hello(wsapi_env)
local headers = { ["Content-type"] = "text/html" }
local function hello_text()
coroutine.yield("hello world!")
end
return 200, headers, coroutine.wrap(hello_text)
end
do
print("Test successful request")
local app = connector.make_handler(hello)
local response, request = app:get("/", {hello = "world"})
assert(response.code == 200)
assert(request.request_method == "GET")
assert(request.query_string == "?hello=world")
assert(response.headers["Content-type"] == "text/html")
assert(response.body == "hello world!")
end
|