File: nginxtest

package info (click to toggle)
lua-resty-core 0.1.31-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,176 kB
  • sloc: perl: 143; sh: 59; makefile: 26
file content (56 lines) | stat: -rw-r--r-- 1,103 bytes parent folder | download | duplicates (2)
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
#!/bin/sh
set -e

if [ ! -f /usr/lib/nginx/modules/ngx_http_lua_module.so ]; then
  # Skip the test if ngx_http_lua_module.so doesn't exist
  exit 77
fi

cat <<EOF > "/etc/nginx/sites-enabled/default"
server {
  listen 80 default_server;

  location /t {
    content_by_lua_block {
      local utils = require "resty.core.utils"

      local strings = {
        "Header_Name",
        "_Header_Name_",
        "Header__Name",
        "Header-Name",
        "Hello world",
      }

      for i = 1, #strings do
        ngx.say(utils.str_replace_char(strings[i], "_", "-"))
      end
    }
  }
}
EOF

exp="Header-Name
-Header-Name-
Header--Name
Header-Name
Hello world
response_code: 200"

nginx -t
invoke-rc.d nginx restart || { journalctl -n all -xu nginx.service; exit 1; }

out=`curl --fail -w "response_code: %{http_code}\n" http://127.0.0.1/t`

if [ x"${out}" != x"${exp}" ]; then
  echo "output:"
  echo "====================="
  echo "${out}"
  echo "====================="
  echo "expected output:"
  echo "====================="
  echo "${exp}"
  echo "====================="
  exit 1
fi
exit 0