File: mock_test.lua

package info (click to toggle)
lua-wsapi 1.5-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 640 kB
  • sloc: ansic: 618; sh: 495; makefile: 42
file content (23 lines) | stat: -rw-r--r-- 731 bytes parent folder | download
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