Skip to content

Commit 5e94b2d

Browse files
committed
Embed lua-resty-http
1 parent e5c51c1 commit 5e94b2d

File tree

5 files changed

+90
-8
lines changed

5 files changed

+90
-8
lines changed

Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,10 @@ test: check-required-vars
3737
nginx -c /etc/nginx/nginx-$(flavor).conf" \
3838

3939
$(DOCKER) cp ./test/nginx-$(flavor).conf test-tsuru-nginx-$(flavor)-$(nginx_version):/etc/nginx/
40+
$(DOCKER) cp ./test/nginx-$(flavor).bash test-tsuru-nginx-$(flavor)-$(nginx_version):/bin/test-nginx
41+
4042
$(DOCKER) cp $$PWD/test/GeoIP2-Country-Test.mmdb test-tsuru-nginx-$(flavor)-$(nginx_version):/etc/nginx; \
4143

4244
$(DOCKER) start test-tsuru-nginx-$(flavor)-$(nginx_version) && sleep 3
4345

44-
@if [ "$$($(DOCKER) exec test-tsuru-nginx-$(flavor)-$(nginx_version) curl -fsSL http://localhost:8080)" != "nginx config check ok" ]; then \
45-
echo 'FAIL' >&2; \
46-
$(DOCKER) logs test-tsuru-nginx-$(flavor)-$(nginx_version); \
47-
exit 1; \
48-
else \
49-
echo 'SUCCESS'; \
50-
fi
46+
$(DOCKER) exec test-tsuru-nginx-$(flavor)-$(nginx_version) sh -c '/bin/test-nginx; exit $$?' || $(DOCKER) logs test-tsuru-nginx-$(flavor)-$(nginx_version)

flavors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"https://github.com/wandenberg/nginx-sorted-querystring-module.git"
1818
],
1919
"lua_modules": [
20-
"tsuru-rpaasv2 INOTIFY_INCDIR=/usr/include/linux-gnu"
20+
"tsuru-rpaasv2 INOTIFY_INCDIR=/usr/include/linux-gnu",
21+
"lua-resty-http 0.17.2-0"
2122
]
2223
},
2324
{

test/nginx-echo.bash

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash -e
2+
3+
assert() {
4+
local expected="$1"
5+
local actual="$2"
6+
local message="$3"
7+
8+
if [[ "$expected" == "$actual" ]]; then
9+
echo "✅ SUCESS: $message"
10+
else
11+
echo "❌ FAIL: $message"
12+
echo " ➡ Expected: '$expected', Obtained: '$actual'"
13+
exit 1
14+
fi
15+
}
16+
17+
test_nginx_serving_request() {
18+
response=$(curl --fail --silent --show-error http://localhost:8080/)
19+
assert "nginx config check ok" "$response" "/ with expected response"
20+
}
21+
22+
echo "Running tests"
23+
24+
test_nginx_serving_request
25+
26+
echo "✅ SUCESS: All tests passed"

test/nginx-tsuru.bash

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash -e
2+
3+
assert() {
4+
local expected="$1"
5+
local actual="$2"
6+
local message="$3"
7+
8+
if [[ "$expected" == "$actual" ]]; then
9+
echo "✅ SUCESS: $message"
10+
else
11+
echo "❌ FAIL: $message"
12+
echo " ➡ Expected: '$expected', Obtained: '$actual'"
13+
exit 1
14+
fi
15+
}
16+
17+
test_nginx_serving_request() {
18+
response=$(curl --fail --silent --show-error http://localhost:8080/)
19+
assert "nginx config check ok" "$response" "/ with expected response"
20+
}
21+
22+
test_lua_content() {
23+
response=$(curl --fail --silent --show-error http://localhost:8080/lua_content)
24+
assert "Hello,world!" "$response" "/lua_content with expected response"
25+
}
26+
27+
test_lua_http_resty() {
28+
response=$(curl --fail --silent --show-error http://localhost:8080/lua_http_resty)
29+
assert "Proxyied response: nginx config check ok" "$response" "/lua_http_resty with expected response"
30+
}
31+
32+
echo "Running tests"
33+
34+
test_nginx_serving_request
35+
test_lua_content
36+
test_lua_http_resty
37+
38+
echo "✅ SUCESS: All tests passed"

test/nginx-tsuru.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ http {
5757
}
5858
}
5959

60+
location /lua_http_resty {
61+
# MIME type determined by default_type:
62+
default_type 'text/plain';
63+
64+
content_by_lua_block {
65+
local httpc = require("resty.http").new();
66+
67+
local res, err = httpc:request_uri("http://127.0.0.1:8080/", {
68+
method = "GET",
69+
})
70+
if not res then
71+
ngx.log(ngx.ERR, "request failed: ", err)
72+
ngx.status = 500
73+
return
74+
end
75+
76+
ngx.say('Proxyied response: ' .. res.body)
77+
78+
}
79+
}
80+
6081
location ~ ^/purge/(.+) {
6182
proxy_cache_purge cache_zone $1$is_args$args;
6283
}

0 commit comments

Comments
 (0)