|
Packit |
90a5c9 |
#!/usr/bin/env lua
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
-- Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
-- contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
-- this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
-- The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
-- (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
-- the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
--
|
|
Packit |
90a5c9 |
-- http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
--
|
|
Packit |
90a5c9 |
-- Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
-- distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
-- See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
-- limitations under the License.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
local mu = require "moonunit"
|
|
Packit |
90a5c9 |
local http = require "helpers"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
http.base_url = "http://localhost:8008"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
local test = mu.TestCase:new{}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:document_root()
|
|
Packit |
90a5c9 |
local b, c = http.get "/document_root.lua"
|
|
Packit |
90a5c9 |
assert(200 == c, "expected status code 200, got " .. c)
|
|
Packit |
90a5c9 |
assert(b:find("test"), "test not found in document root")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:basic_get()
|
|
Packit |
90a5c9 |
local b, c = http.get "/basic"
|
|
Packit |
90a5c9 |
assert(200 == c, "expected status code 200, got " .. c)
|
|
Packit |
90a5c9 |
assert(b:find("hello Lua world"), "'hello Lua world' not found in response")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:quietly()
|
|
Packit |
90a5c9 |
local b, c = http.get "/test_quietly"
|
|
Packit |
90a5c9 |
assert(200 == c, "unexpected response code " .. c)
|
|
Packit |
90a5c9 |
assert(b == 'hello!', "unexpected response body [" .. b .. "]")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test.basic_post()
|
|
Packit |
90a5c9 |
local b, c = http.post "/basic" "hello=7&hello=1"
|
|
Packit |
90a5c9 |
assert(200 == c, "expected status code 200, got " .. c)
|
|
Packit |
90a5c9 |
assert(b:find("complex:%s+hello: 7, 1\n"), "didn't find complex post parsing")
|
|
Packit |
90a5c9 |
assert(b:find("simple:%s+hello: 7\n"), "didn't find simple post parsing")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test.basic_post_alt()
|
|
Packit |
90a5c9 |
local b, c = http.post("/test_foo", "hello=7&hello=1")
|
|
Packit |
90a5c9 |
assert(201 == c, "expected status code 200, got " .. c)
|
|
Packit |
90a5c9 |
assert(b:find("Handler FOO!"), "unexpected output!")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test.post_with_table()
|
|
Packit |
90a5c9 |
local b, c = http.post "/basic" { hello = "7" }
|
|
Packit |
90a5c9 |
assert(200 == c, "expected status code 200, got " .. c)
|
|
Packit |
90a5c9 |
assert(b:find("hello: 7"), "didn't get expected post data [" .. b .."]")
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
b, c = http.post "/basic" { hello = "7", goodbye = "8" }
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
assert(200 == c, "expected status code 200, got " .. c)
|
|
Packit |
90a5c9 |
assert(b:find("hello: 7"), "didn't get expected post data [" .. b .."]")
|
|
Packit |
90a5c9 |
assert(b:find("goodbye: 8"), "didn't get expected post data [" .. b .."]")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:simple_filter()
|
|
Packit |
90a5c9 |
local b, c = http.get "/filter/simple"
|
|
Packit |
90a5c9 |
assert(200 == c, "expected status code 200, got " .. c)
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:request_attributes()
|
|
Packit |
90a5c9 |
local r, c = http.get "/test_attributes?yes=no"
|
|
Packit |
90a5c9 |
assert(201 == c, "expected status code 201, got " .. c)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
assert(r:find("status: 200\nstatus: 201"), "changing status code failed")
|
|
Packit |
90a5c9 |
assert(r:find("method: GET"), "method wasn't reported correctly")
|
|
Packit |
90a5c9 |
assert(r:find("protocol: HTTP/1.1"), "protocol reported incorrectly")
|
|
Packit |
90a5c9 |
assert(r:find("assbackwards: false"), "assbackwards reported incorrectly")
|
|
Packit |
90a5c9 |
assert(r:find("args: yes=no"), "args not reported correctly")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:map_regex()
|
|
Packit |
90a5c9 |
local r, c = http.get "/test_regex"
|
|
Packit |
90a5c9 |
assert(200 == c, "expected status code 200, got " .. c)
|
|
Packit |
90a5c9 |
assert(r:find("matched in handle_regex"), "didn't find 'matched in handle_regex'")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:map_regex2()
|
|
Packit |
90a5c9 |
local r, c = http.get "/test_regex?a=8"
|
|
Packit |
90a5c9 |
assert(200 == c, "expected status code 200, got " .. c)
|
|
Packit |
90a5c9 |
assert(r:find("matched in handle_regex"), "didn't find 'matched in handle_regex'")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:translate_name_hook()
|
|
Packit |
90a5c9 |
local r, c = http.get "/translate-name"
|
|
Packit |
90a5c9 |
assert(200 == c, "expected 200 got " .. c)
|
|
Packit |
90a5c9 |
assert(r:find("please find me"), "didn't get expected static file :-(, instead got " .. r)
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:translate_name_hook2()
|
|
Packit |
90a5c9 |
local r, c = http.get "/translate-name2"
|
|
Packit |
90a5c9 |
assert(200 == c, "expected 200 got " .. c)
|
|
Packit |
90a5c9 |
assert(r:find("please find me"), "didn't get expected static file :-(, instead got " .. r)
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:server_version()
|
|
Packit |
90a5c9 |
local r, c = http.get "/test_serverversion"
|
|
Packit |
90a5c9 |
assert(200 == c)
|
|
Packit |
90a5c9 |
assert(r:find("Apache/2"), "version isn't Apache/2, but is " .. r)
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:fixups_hook()
|
|
Packit |
90a5c9 |
local r, c = http.get "/test_fixupstest"
|
|
Packit |
90a5c9 |
assert(201 == c, "incorrect status code returned, expected 201 got " .. c)
|
|
Packit |
90a5c9 |
assert(r:find("status is 201"), "handler sees incorrect status")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
function test:simple()
|
|
Packit |
90a5c9 |
local r, c = http.get "/simple.lua"
|
|
Packit |
90a5c9 |
assert(200 == c, "incorrect status code returned, expected 200 got " .. c)
|
|
Packit |
90a5c9 |
assert(r:find("Hi"), "Didn't find 'Hi'")
|
|
Packit |
90a5c9 |
end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
test:run()
|