| 1 |
#!/bin/sh |
| 2 |
set -e |
| 3 |
|
| 4 |
cat <<EOF > "/etc/nginx/sites-enabled/default" |
| 5 |
server { |
| 6 |
listen 80 default_server; |
| 7 |
|
| 8 |
location /t { |
| 9 |
content_by_lua_block { |
| 10 |
local lrucache = require "resty.lrucache" |
| 11 |
local c = lrucache.new(3) |
| 12 |
|
| 13 |
collectgarbage() |
| 14 |
|
| 15 |
-- set values |
| 16 |
c:set("int-value", 0) |
| 17 |
c:set("string-value", "abc") |
| 18 |
c:set("bool-value", true) |
| 19 |
ngx.say("int-value: ", (c:get("int-value"))) |
| 20 |
ngx.say("string-value: ", (c:get("string-value"))) |
| 21 |
ngx.say("string-value: ", (c:get("bool-value"))) |
| 22 |
|
| 23 |
-- update values |
| 24 |
c:set("int-value", 1) |
| 25 |
c:set("string-value", "def") |
| 26 |
c:set("bool-value", false) |
| 27 |
ngx.say("int-value: ", (c:get("int-value"))) |
| 28 |
ngx.say("string-value: ", (c:get("string-value"))) |
| 29 |
ngx.say("string-value: ", (c:get("bool-value"))) |
| 30 |
|
| 31 |
-- delete values |
| 32 |
c:delete("int-value") |
| 33 |
c:delete("string-value") |
| 34 |
c:delete("bool-value") |
| 35 |
ngx.say("int-value: ", (c:get("int-value"))) |
| 36 |
ngx.say("string-value: ", (c:get("string-value"))) |
| 37 |
ngx.say("string-value: ", (c:get("bool-value"))) |
| 38 |
|
| 39 |
-- set values again |
| 40 |
c:set("int-value", 0) |
| 41 |
c:set("string-value", "abc") |
| 42 |
c:set("bool-value", true) |
| 43 |
ngx.say("int-value: ", (c:get("int-value"))) |
| 44 |
ngx.say("string-value: ", (c:get("string-value"))) |
| 45 |
ngx.say("string-value: ", (c:get("bool-value"))) |
| 46 |
|
| 47 |
-- flush cache |
| 48 |
c:flush_all() |
| 49 |
ngx.say("int-value: ", (c:get("int-value"))) |
| 50 |
ngx.say("string-value: ", (c:get("string-value"))) |
| 51 |
ngx.say("string-value: ", (c:get("bool-value"))) |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
EOF |
| 56 |
|
| 57 |
exp="int-value: 0 |
| 58 |
string-value: abc |
| 59 |
string-value: true |
| 60 |
int-value: 1 |
| 61 |
string-value: def |
| 62 |
string-value: false |
| 63 |
int-value: nil |
| 64 |
string-value: nil |
| 65 |
string-value: nil |
| 66 |
int-value: 0 |
| 67 |
string-value: abc |
| 68 |
string-value: true |
| 69 |
int-value: nil |
| 70 |
string-value: nil |
| 71 |
string-value: nil |
| 72 |
response_code: 200" |
| 73 |
|
| 74 |
nginx -t |
| 75 |
invoke-rc.d nginx restart || { journalctl -n all -xu nginx.service; exit 1; } |
| 76 |
out=`curl --fail -w "response_code: %{http_code}\n" http://127.0.0.1/t` |
| 77 |
|
| 78 |
if [ x"${out}" != x"${exp}" ]; then |
| 79 |
echo "output:" |
| 80 |
echo "=====================" |
| 81 |
echo "${out}" |
| 82 |
echo "=====================" |
| 83 |
echo "expected output:" |
| 84 |
echo "=====================" |
| 85 |
echo "${exp}" |
| 86 |
echo "=====================" |
| 87 |
exit 1 |
| 88 |
fi |