Skip to content

Commit 7284ec3

Browse files
committed
tests: update test for both ngx_lua_module and stream_ngx_lua_module
1 parent 69c9f53 commit 7284ec3

File tree

12 files changed

+102
-457
lines changed

12 files changed

+102
-457
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ script:
8181
- cd lua-cjson && (LUA_INCLUDE_DIR=$LUAJIT_INC make && sudo PATH=$PATH make install) || (cat build.log && exit 1) && cd ..
8282
- export PATH=$PWD/work/nginx/sbin:$PWD/nginx-devel-utils:$PATH
8383
- ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-cc-opt="-I$OPENSSL_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB" --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=../lua-nginx-module --add-module=../stream-lua-nginx-module --with-debug > build.log 2>&1 || (cat build.log && exit 1)
84-
- prove -r t
84+
- TEST_SUBSYSTEM=http prove -r t
85+
- TEST_SUBSYSTEM=stream prove -r t

t/Test.pm

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
11+
my $default_config = qq{
12+
resolver \$TEST_NGINX_RESOLVER;
13+
lua_package_path "$pwd/t/servroot/html/?.lua;$pwd/lib/?.lua;$pwd/t/lib/?.lua;$pwd/../lua-resty-rsa/lib/?.lua;$pwd/../lua-resty-string/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_MYSQL_PORT} ||= 3306;
19+
$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1';
20+
$ENV{TEST_NGINX_MYSQL_PATH} ||= '/var/run/mysql/mysql.sock';
21+
22+
no_long_string();
23+
24+
add_block_preprocessor(sub {
25+
my $block = shift;
26+
27+
if (defined($ENV{TEST_SUBSYSTEM}) && $ENV{TEST_SUBSYSTEM} eq "stream") {
28+
if (!defined $block->stream_config) {
29+
$block->set_value("stream_config", $default_config);
30+
}
31+
if (!defined $block->stream_server_config) {
32+
$block->set_value("stream_server_config", $block->server_config);
33+
}
34+
} else {
35+
if (!defined $block->http_config) {
36+
$block->set_value("http_config", $default_config);
37+
}
38+
if (!defined $block->request) {
39+
$block->set_value("request", "GET /t\n");
40+
}
41+
if (!defined $block->config) {
42+
$block->set_value("config", "location /t {\n" . $block->server_config . "\n}");
43+
}
44+
}
45+
});
46+
47+
1;

t/auth.t

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
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(5);
76

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

10-
my $pwd = cwd();
11-
12-
our $HttpConfig = qq{
13-
resolver \$TEST_NGINX_RESOLVER;
14-
lua_package_path "$pwd/t/servroot/html/?.lua;$pwd/lib/?.lua;$pwd/t/lib/?.lua;$pwd/../lua-resty-rsa/lib/?.lua;$pwd/../lua-resty-string/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_MYSQL_PORT} ||= 3306;
20-
$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1';
21-
$ENV{TEST_NGINX_MYSQL_PATH} ||= '/var/run/mysql/mysql.sock';
22-
239
#log_level 'warn';
2410

2511
no_long_string();
@@ -143,9 +129,7 @@ __DATA__
143129
=== TEST 1: test different auth plugin
144130
--- main_config
145131
env DB_VERSION;
146-
--- http_config eval: $::HttpConfig
147-
--- config
148-
location /t {
132+
--- server_config
149133
content_by_lua_block {
150134
local test_suit = require "test_suit"
151135
test_suit.prepare()
@@ -256,8 +240,5 @@ __DATA__
256240
end
257241
end
258242
}
259-
}
260-
--- request
261-
GET /t
262243
--- no_error_log
263244
[error]

t/big.t

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,13 @@ BEGIN {
77
}
88
}
99

10-
use Test::Nginx::Socket::Lua @skip;
11-
use Cwd qw(cwd);
10+
use t::Test @skip;
1211

1312
repeat_each(50);
1413
#repeat_each(10);
1514

1615
plan tests => repeat_each() * (3 * blocks());
1716

18-
my $pwd = cwd();
19-
20-
our $HttpConfig = qq{
21-
resolver \$TEST_NGINX_RESOLVER;
22-
lua_package_path "$pwd/lib/?.lua;$pwd/t/lib/?.lua;$pwd/../lua-resty-rsa/lib/?.lua;$pwd/../lua-resty-string/lib/?.lua;;";
23-
lua_package_cpath "/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;";
24-
};
25-
26-
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
27-
$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
28-
$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1';
29-
$ENV{TEST_NGINX_MYSQL_PATH} ||= '/var/run/mysql/mysql.sock';
30-
3117
log_level 'warn';
3218

3319
#no_long_string();
@@ -39,9 +25,7 @@ run_tests();
3925
__DATA__
4026

4127
=== TEST 1: big field value exceeding 256
42-
--- http_config eval: $::HttpConfig
43-
--- config
44-
location /t {
28+
--- server_config
4529
content_by_lua '
4630
local ljson = require "ljson"
4731
@@ -113,9 +97,6 @@ __DATA__
11397
return
11498
end
11599
';
116-
}
117-
--- request
118-
GET /t
119100
--- response_body eval
120101
'connected to mysql.
121102
table cats dropped.
@@ -131,9 +112,7 @@ result: [{"id":"1","name":"' . ('B' x 1024)
131112

132113

133114
=== TEST 2: big field value exceeding max packet size
134-
--- http_config eval: $::HttpConfig
135-
--- config
136-
location /t {
115+
--- server_config
137116
content_by_lua '
138117
local ljson = require "ljson"
139118
@@ -208,9 +187,6 @@ result: [{"id":"1","name":"' . ('B' x 1024)
208187
return
209188
end
210189
';
211-
}
212-
--- request
213-
GET /t
214190
--- response_body eval
215191
'connected to mysql.
216192
table cats dropped.
@@ -224,9 +200,7 @@ bad result: packet size too big: 1029: nil: nil.
224200

225201

226202
=== TEST 3: big field value exceeding 256 (first field in rows)
227-
--- http_config eval: $::HttpConfig
228-
--- config
229-
location /t {
203+
--- server_config
230204
content_by_lua '
231205
local ljson = require "ljson"
232206
@@ -298,9 +272,6 @@ bad result: packet size too big: 1029: nil: nil.
298272
return
299273
end
300274
';
301-
}
302-
--- request
303-
GET /t
304275
--- response_body eval
305276
'connected to mysql.
306277
table cats dropped.
@@ -316,9 +287,7 @@ result: [{"name":"' . ('B' x 1024)
316287

317288

318289
=== TEST 4: big field value exceeding 65536 (first field in rows)
319-
--- http_config eval: $::HttpConfig
320-
--- config
321-
location /t {
290+
--- server_config
322291
content_by_lua '
323292
local ljson = require "ljson"
324293
@@ -390,9 +359,6 @@ result: [{"name":"' . ('B' x 1024)
390359
return
391360
end
392361
';
393-
}
394-
--- request
395-
GET /t
396362
--- response_body eval
397363
'connected to mysql.
398364
table cats dropped.

t/bug.t

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
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-
resolver \$TEST_NGINX_RESOLVER;
14-
lua_package_path "$pwd/lib/?.lua;$pwd/t/lib/?.lua;$pwd/../lua-resty-rsa/lib/?.lua;$pwd/../lua-resty-string/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_MYSQL_PORT} ||= 3306;
20-
$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1';
21-
$ENV{TEST_NGINX_MYSQL_PATH} ||= '/var/run/mysql/mysql.sock';
22-
239
#log_level 'warn';
2410

2511
no_long_string();
@@ -31,9 +17,7 @@ run_tests();
3117
__DATA__
3218

3319
=== TEST 1: message in ok packet (github #61)
34-
--- http_config eval: $::HttpConfig
35-
--- config
36-
location /t {
20+
--- server_config
3721
content_by_lua_block {
3822
local mysql_driver = require "resty.mysql"
3923

@@ -89,10 +73,6 @@ location /t {
8973
end
9074
end
9175
}
92-
}
93-
--- request
94-
GET /t
95-
9676
--- response_body
9777
Rows matched: 1 Changed: 1 Warnings: 0
9878
--- no_error_log

t/charset.t

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
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-
resolver \$TEST_NGINX_RESOLVER;
14-
lua_package_path "$pwd/lib/?.lua;$pwd/t/lib/?.lua;$pwd/../lua-resty-rsa/lib/?.lua;$pwd/../lua-resty-string/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_MYSQL_PORT} ||= 3306;
20-
$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1';
21-
$ENV{TEST_NGINX_MYSQL_PATH} ||= '/var/run/mysql/mysql.sock';
22-
239
#log_level 'warn';
2410

2511
#no_long_string();
@@ -31,9 +17,7 @@ run_tests();
3117
__DATA__
3218

3319
=== TEST 1: connect db using charset option (utf8)
34-
--- http_config eval: $::HttpConfig
35-
--- config
36-
location /t {
20+
--- server_config
3721
content_by_lua_block {
3822
local ljson = require "ljson"
3923
local mysql = require "resty.mysql"
@@ -84,9 +68,6 @@ __DATA__
8468

8569
ngx.say(ljson.encode(res))
8670
}
87-
}
88-
--- request
89-
GET /t
9071
--- response_body
9172
[{"id":"1","name":"愛麗絲"}]
9273
--- no_error_log
@@ -95,9 +76,7 @@ GET /t
9576

9677

9778
=== TEST 2: connect db using charset option (big5)
98-
--- http_config eval: $::HttpConfig
99-
--- config
100-
location /t {
79+
--- server_config
10180
content_by_lua_block {
10281
local ljson = require "ljson"
10382
local mysql = require "resty.mysql"
@@ -148,9 +127,6 @@ GET /t
148127

149128
ngx.say(ljson.encode(res))
150129
}
151-
}
152-
--- request
153-
GET /t
154130
--- response_body eval
155131
qq/[{"id":"1","name":"\x{b7}R\x{c4}R\x{b5}\x{b7}"}]\n/
156132
--- no_error_log
@@ -159,9 +135,7 @@ qq/[{"id":"1","name":"\x{b7}R\x{c4}R\x{b5}\x{b7}"}]\n/
159135

160136

161137
=== TEST 3: connect db using charset option (gbk)
162-
--- http_config eval: $::HttpConfig
163-
--- config
164-
location /t {
138+
--- server_config
165139
content_by_lua_block {
166140
local ljson = require "ljson"
167141
local mysql = require "resty.mysql"
@@ -212,9 +186,6 @@ qq/[{"id":"1","name":"\x{b7}R\x{c4}R\x{b5}\x{b7}"}]\n/
212186

213187
ngx.say(ljson.encode(res))
214188
}
215-
}
216-
--- request
217-
GET /t
218189
--- response_body eval
219190
qq/[{"id":"1","name":"\x{90}\x{db}\x{fb}\x{90}\x{bd}z"}]\n/
220191
--- no_error_log

0 commit comments

Comments
 (0)