1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
# vim:set ft= ts=4 sw=4 et fdm=marker:
use lib 'lib';
use Test::Nginx::Socket;
repeat_each(1);
plan tests => blocks() * repeat_each() * 2;
#$ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
no_long_string();
run_tests();
__DATA__
=== TEST 1: syntax error in lua code chunk
--- config
location /lua {
set_by_lua $res "local a
a = a+;
return a";
echo $res;
}
--- request
GET /lua
--- error_code: 500
--- response_body_like: 500 Internal Server Error
=== TEST 2: syntax error in lua file
--- config
location /lua {
set_by_lua_file $res 'html/test.lua';
echo $res;
}
--- user_files
>>> test.lua
local a
a = 3 +;
return a
--- request
GET /lua
--- error_code: 500
--- response_body_like: 500 Internal Server Error
=== TEST 3: syntax error in lua file (from Guang Feng)
--- config
location /lua {
set $res '[{"a":32},{"b":64}]';
#set $res '[{"friend_userid":1750146},{"friend_userid":1750150},{"friend_userid":1750153},{"friend_userid":1750166},{"friend_userid":1750181},{"friend_userid":1750186},{"friend_userid":1750195},{"friend_userid":1750232}]';
set_by_lua_file $list 'html/test.lua' $res;
#set_by_lua_file $list 'html/feed.lua' $res;
echo $list;
}
--- user_files
>>> test.lua
-- local j = require('json')
local p = ngx.arg[1]
return p
>>> feed.lua
local s = require("json")
local function explode(d,p)
local t, ll
t={}
ll=0
if(#p == 1) then return p end
while true do
l=string.find(p,d,ll+1,true)
if l~=nil then
table.insert(t, string.sub(p,ll,l-1))
ll=l+1
else
table.insert(t, string.sub(p,ll))
break
end
end
return t
end
local a = explode(',', string.sub(ngx.arg[1], 2, -1))
local x = {}
for i,v in ipairs(a) do table.insert(x,s.decode(v).friend_userid) end
return table.concat(x,',')
--- request
GET /lua
--- response_body
[{"a":32},{"b":64}]
=== TEST 4: 500 in subrequest
--- config
location /main {
content_by_lua '
local res = ngx.location.capture("/err")
ngx.say(res.status);
';
}
location /err {
return 500;
}
--- request
GET /main
--- response_body
500
=== TEST 5: drizzle_pass 500 in subrequest
--- config
location /main {
content_by_lua '
local res = ngx.location.capture("/err")
ngx.say(res.status);
';
}
location /err {
set $back 'blah-blah';
drizzle_pass $back;
}
--- request
GET /main
--- response_body
500
|