Skip to content

Commit 84dc8bc

Browse files
test: support running test in both http and stream subsystems (#190)
1 parent 3323079 commit 84dc8bc

File tree

12 files changed

+187
-470
lines changed

12 files changed

+187
-470
lines changed

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ addons:
1313
- luarocks
1414

1515
services:
16-
- redis-server
16+
- redis
1717

1818
cache:
1919
directories:
@@ -30,11 +30,11 @@ env:
3030
- OPENSSL_PREFIX=/opt/ssl
3131
- OPENSSL_LIB=$OPENSSL_PREFIX/lib
3232
- OPENSSL_INC=$OPENSSL_PREFIX/include
33-
- OPENSSL_VER=1.0.2h
33+
- OPENSSL_VER=1.1.1f
3434
- LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH
3535
- TEST_NGINX_SLEEP=0.006
3636
- LUACHECK_VER=0.21.1
37-
matrix:
37+
jobs:
3838
- NGINX_VERSION=1.17.8
3939

4040
before_install:
@@ -74,4 +74,5 @@ script:
7474
- ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --add-module=../echo-nginx-module --add-module=../lua-nginx-module --add-module=../stream-lua-nginx-module --with-stream --with-stream_ssl_module --with-debug
7575
- nginx -V
7676
- ldd `which nginx`|grep -E 'luajit|ssl|pcre'
77-
- prove -r t
77+
- TEST_SUBSYSTEM=http prove -r t
78+
- TEST_SUBSYSTEM=stream prove -r t

t/Test.pm

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package t::Test;
2+
3+
use strict;
4+
use warnings;
5+
6+
use Test::Nginx::Socket::Lua::Stream -Base;
7+
use Cwd qw(cwd);
8+
9+
my $pwd = cwd();
10+
my $HtmlDir = html_dir;
11+
12+
our @EXPORT = qw($GlobalConfig);
13+
our $GlobalConfig = qq{
14+
lua_package_path "$pwd/lib/?.lua;;";
15+
lua_package_cpath "/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;";
16+
};
17+
18+
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
19+
$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
20+
21+
no_long_string();
22+
23+
add_block_preprocessor(sub {
24+
my $block = shift;
25+
26+
if (!defined $block->http_only) {
27+
if ($ENV{TEST_SUBSYSTEM} eq "stream") {
28+
if (!defined $block->stream_config) {
29+
$block->set_value("stream_config", $block->global_config);
30+
}
31+
if (!defined $block->stream_server_config) {
32+
$block->set_value("stream_server_config", $block->server_config);
33+
}
34+
if (defined $block->internal_server_error) {
35+
$block->set_value("stream_respons", "");
36+
}
37+
} else {
38+
if (!defined $block->http_config) {
39+
$block->set_value("http_config", $block->global_config);
40+
}
41+
if (!defined $block->request) {
42+
$block->set_value("request", <<\_END_);
43+
GET /t
44+
_END_
45+
}
46+
if (!defined $block->config) {
47+
$block->set_value("config", "location /t {\n" . $block->server_config . "\n}");
48+
}
49+
if (defined $block->internal_server_error) {
50+
$block->set_value("error_code", 500);
51+
$block->set_value("ignore_response_body", "");
52+
}
53+
}
54+
}
55+
});
56+
57+
1;

t/bugs.t

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
# vim:set ft= ts=4 sw=4 et:
22

3-
use Test::Nginx::Socket::Lua;
4-
use Cwd qw(cwd);
3+
use t::Test;
54

65
repeat_each(2);
76

87
plan tests => repeat_each() * (3 * blocks());
98

10-
my $pwd = cwd();
11-
my $HtmlDir = html_dir;
12-
13-
our $HttpConfig = qq{
14-
lua_package_path "$HtmlDir/?.lua;$pwd/lib/?.lua;;";
15-
};
16-
17-
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
18-
$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
19-
20-
no_long_string();
21-
#no_diff();
22-
239
log_level 'warn';
2410

2511
run_tests();
2612

2713
__DATA__
2814

2915
=== TEST 1: github issue #108: ngx.location.capture + redis.set_keepalive
30-
--- http_config eval: $::HttpConfig
16+
--- http_only
17+
--- http_config eval: $::GlobalConfig
3118
--- config
3219
location /r1 {
3320
default_type text/html;
@@ -95,7 +82,8 @@ ok
9582

9683
=== TEST 2: exit(404) after I/O (ngx_lua github issue #110
9784
https://github.com/chaoslawful/lua-nginx-module/issues/110
98-
--- http_config eval: $::HttpConfig
85+
--- http_only
86+
--- http_config eval: $::GlobalConfig
9987
--- config
10088
error_page 400 /400.html;
10189
error_page 404 /404.html;
@@ -166,9 +154,8 @@ Not found, dear...
166154

167155

168156
=== TEST 3: set and get an empty string
169-
--- http_config eval: $::HttpConfig
170-
--- config
171-
location /t {
157+
--- global_config eval: $::GlobalConfig
158+
--- server_config
172159
content_by_lua '
173160
local redis = require "resty.redis"
174161
local red = redis:new()
@@ -210,9 +197,6 @@ Not found, dear...
210197
211198
red:close()
212199
';
213-
}
214-
--- request
215-
GET /t
216200
--- response_body
217201
set dog: OK
218202
dog:
@@ -223,7 +207,8 @@ dog:
223207

224208

225209
=== TEST 4: ngx.exec() after red:get()
226-
--- http_config eval: $::HttpConfig
210+
--- http_only
211+
--- http_config eval: $::GlobalConfig
227212
--- config
228213
location /t {
229214
content_by_lua '

t/count.t

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
# vim:set ft= ts=4 sw=4 et:
22

3-
use Test::Nginx::Socket::Lua;
4-
use Cwd qw(cwd);
3+
use t::Test;
54

65
repeat_each(2);
76

87
plan tests => repeat_each() * (3 * blocks());
98

10-
my $pwd = cwd();
11-
12-
our $HttpConfig = qq{
13-
lua_package_path "$pwd/lib/?.lua;;";
14-
lua_package_cpath "/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;";
15-
};
16-
17-
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
18-
$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
19-
20-
no_long_string();
21-
#no_diff();
22-
239
run_tests();
2410

2511
__DATA__
2612

2713
=== TEST 1: module size of resty.redis
28-
--- http_config eval: $::HttpConfig
29-
--- config
30-
location = /t {
14+
--- global_config eval: $::GlobalConfig
15+
--- server_config
3116
content_by_lua '
3217
local redis = require "resty.redis"
3318
n = 0
@@ -36,9 +21,6 @@ __DATA__
3621
end
3722
ngx.say("size: ", n)
3823
';
39-
}
40-
--- request
41-
GET /t
4224
--- response_body
4325
size: 55
4426
--- no_error_log

t/hmset.t

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
# vim:set ft= ts=4 sw=4 et:
22

3-
use Test::Nginx::Socket::Lua;
4-
use Cwd qw(cwd);
3+
use t::Test;
54

65
repeat_each(2);
76

8-
plan tests => repeat_each() * (3 * blocks());
9-
10-
my $pwd = cwd();
11-
12-
our $HttpConfig = qq{
13-
lua_package_path "$pwd/lib/?.lua;;;";
14-
lua_package_cpath "/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;";
15-
};
16-
17-
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
18-
$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
19-
20-
no_long_string();
21-
#no_diff();
7+
plan tests => repeat_each() * (3 * blocks()) - 2;
228

239
run_tests();
2410

2511
__DATA__
2612

2713
=== TEST 1: hmset key-pairs
28-
--- http_config eval: $::HttpConfig
29-
--- config
30-
location /t {
14+
--- global_config eval: $::GlobalConfig
15+
--- server_config
3116
content_by_lua '
3217
local redis = require "resty.redis"
3318
local red = redis:new()
@@ -57,9 +42,6 @@ __DATA__
5742
5843
red:close()
5944
';
60-
}
61-
--- request
62-
GET /t
6345
--- response_body
6446
hmset animals: OK
6547
hmget animals: barkmeow
@@ -69,9 +51,8 @@ hmget animals: barkmeow
6951

7052

7153
=== TEST 2: hmset lua tables
72-
--- http_config eval: $::HttpConfig
73-
--- config
74-
location /t {
54+
--- global_config eval: $::GlobalConfig
55+
--- server_config
7556
content_by_lua '
7657
local redis = require "resty.redis"
7758
local red = redis:new()
@@ -102,9 +83,6 @@ hmget animals: barkmeow
10283
10384
red:close()
10485
';
105-
}
106-
--- request
107-
GET /t
10886
--- response_body
10987
hmset animals: OK
11088
hmget animals: barkmeowmoo
@@ -114,9 +92,8 @@ hmget animals: barkmeowmoo
11492

11593

11694
=== TEST 3: hmset a single scalar
117-
--- http_config eval: $::HttpConfig
118-
--- config
119-
location /t {
95+
--- global_config eval: $::GlobalConfig
96+
--- server_config
12097
content_by_lua '
12198
local redis = require "resty.redis"
12299
local red = redis:new()
@@ -146,10 +123,6 @@ hmget animals: barkmeowmoo
146123
147124
red:close()
148125
';
149-
}
150-
--- request
151-
GET /t
152-
--- response_body_like: 500 Internal Server Error
153-
--- error_code: 500
126+
--- internal_server_error
154127
--- error_log
155128
table expected, got string

t/mock.t

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
# vim:set ft= ts=4 sw=4 et:
22

3-
use Test::Nginx::Socket::Lua;
4-
use Cwd qw(cwd);
3+
use t::Test;
54

65
repeat_each(2);
76

87
plan tests => repeat_each() * (4 * blocks());
98

10-
my $pwd = cwd();
11-
12-
our $HttpConfig = qq{
13-
lua_package_path "$pwd/lib/?.lua;;";
14-
lua_package_cpath "/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;";
15-
};
16-
17-
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
18-
$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
19-
20-
no_long_string();
21-
#no_diff();
22-
239
run_tests();
2410

2511
__DATA__
2612

2713
=== TEST 1: continue using the obj when read timeout happens
28-
--- http_config eval: $::HttpConfig
29-
--- config
30-
location /t {
14+
--- global_config eval: $::GlobalConfig
15+
--- server_config
3116
content_by_lua '
3217
local redis = require "resty.redis"
3318
local red = redis:new()
@@ -52,9 +37,6 @@ __DATA__
5237
5338
red:close()
5439
';
55-
}
56-
--- request
57-
GET /t
5840
--- tcp_listen: 1921
5941
--- tcp_query eval
6042
"*2\r

0 commit comments

Comments
 (0)