Skip to content

Commit 0a9283d

Browse files
committed
chore: add ci tests
1 parent 44eed0d commit 0a9283d

File tree

6 files changed

+148
-64
lines changed

6 files changed

+148
-64
lines changed

.travis.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
sudo: required
2+
dist: trusty
3+
4+
os: linux
5+
6+
language: c
7+
8+
compiler: gcc
9+
10+
addons:
11+
apt:
12+
packages:
13+
- cpanminus
14+
- axel
15+
- luarocks
16+
17+
cache:
18+
directories:
19+
- download-cache
20+
21+
env:
22+
global:
23+
- JOBS=2
24+
- NGX_BUILD_JOBS=$JOBS
25+
- LUAJIT_PREFIX=/opt/luajit21
26+
- LUAJIT_LIB=$LUAJIT_PREFIX/lib
27+
- LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
28+
- LUA_INCLUDE_DIR=$LUAJIT_INC
29+
- LUA_CMODULE_DIR=/lib
30+
- LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH
31+
- TEST_NGINX_SLEEP=0.005
32+
- TEST_NGINX_RANDOMIZE=1
33+
- LUACHECK_VER=0.21.1
34+
matrix:
35+
- NGINX_VERSION=1.15.8 STREAM_LUA_MODULE_VERSION=v0.0.7 LUA_NGINX_MODULE_VERSION=v0.10.15 LUA_RESTY_CORE_VERSION=v0.1.17
36+
37+
services:
38+
- memcache
39+
40+
before_install:
41+
- sudo luarocks install luacheck $LUACHECK_VER
42+
# - luacheck -q .
43+
# - '! grep -n -P ''(?<=.{80}).+'' --color `find . -name ''*.lua''` || (echo "ERROR: Found Lua source lines exceeding 80 columns." > /dev/stderr; exit 1)'
44+
# - '! grep -n -P ''\t+'' --color `find . -name ''*.lua''` || (echo "ERROR: Cannot use tabs." > /dev/stderr; exit 1)'
45+
- sudo cpanm --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
46+
47+
install:
48+
- if [ ! -d download-cache ]; then mkdir download-cache; fi
49+
- git clone https://github.com/openresty/openresty.git ../openresty
50+
- git clone https://github.com/openresty/openresty-devel-utils.git
51+
- git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module
52+
- git clone -b $LUA_NGINX_MODULE_VERSION https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module
53+
- git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx
54+
- git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module
55+
- git clone https://github.com/openresty/lua-resty-lrucache.git ../lua-resty-lrucache
56+
- git clone -b $LUA_RESTY_CORE_VERSION https://github.com/openresty/lua-resty-core.git ../lua-resty-core
57+
- git clone https://github.com/openresty/headers-more-nginx-module.git ../headers-more-nginx-module
58+
- git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git luajit2
59+
- git clone https://github.com/openresty/set-misc-nginx-module.git ../set-misc-nginx-module
60+
- git clone https://github.com/openresty/test-nginx.git
61+
- git clone -b $STREAM_LUA_MODULE_VERSION https://github.com/openresty/stream-lua-nginx-module.git ../stream-lua-nginx-module
62+
63+
script:
64+
- cd luajit2/
65+
- make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT -msse4.2' > build.log 2>&1 || (cat build.log && exit 1)
66+
- sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1)
67+
- cd ..
68+
- export LD_LIBRARY_PATH=$PWD/mockeagain:$LD_LIBRARY_PATH
69+
- export TEST_NGINX_RESOLVER=8.8.4.4
70+
- export NGX_BUILD_CC=$CC
71+
- export PATH=$PWD/work/nginx/sbin:$PWD/openresty-devel-utils:$PATH
72+
- ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../set-misc-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --with-debug --with-stream --with-ipv6 --add-module=../stream-lua-nginx-module > build.log 2>&1 || (cat build.log && exit 1)
73+
- nginx -V
74+
- ldd `which nginx`|grep -E 'luajit|ssl|pcre'
75+
- prove -Itest-nginx/lib -j$JOBS -r t

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Name
33

44
lua-resty-shdict-server - A HTTP and Redis protocol compatible interface for debugging ngx.shared API
55

6+
![Build status](https://travis-ci.com/fffonion/lua-resty-shdict-server.svg?branch=master)
7+
68
Table of Contents
79
=================
810

@@ -38,7 +40,7 @@ It can also be used as a mocking Redis server (WIP).
3840
Status
3941
========
4042

41-
Experimental.
43+
Production.
4244

4345
Synopsis
4446
========
@@ -399,4 +401,4 @@ See Also
399401
========
400402
* [openresty/lua-nginx-module](https://github.com/openresty/lua-nginx-module)
401403
402-
[Back to TOC](#table-of-contents)
404+
[Back to TOC](#table-of-contents)

lib/resty/shdict/redis-commands.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ if ngx_shared then
7474
if numkeys ~= nil then
7575
numkeys = tonumber(numkeys)
7676
if numkeys == nil then
77-
return "nil", "value is not an integer or out of range"
77+
return nil, "value is not an integer or out of range"
7878
elseif numkeys < 0 then
7979
return nil, "Number of keys can't be negative"
8080
elseif #arg < numkeys then

t/http.t

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
# vim:set ft= ts=4 sw=4 et fdm=marker:
22

3-
use Test::Nginx::Socket 'no_plan';
3+
use Test::Nginx::Socket::Lua 'no_plan';
4+
use Cwd qw(cwd);
5+
6+
7+
my $pwd = cwd();
8+
9+
our $HttpConfig = qq{
10+
lua_package_path "$pwd/lib/?.lua;$pwd/lib/?/init.lua;;";
11+
lua_shared_dict dogs 1m;
12+
};
413

514
run_tests();
615

716
__DATA__
817
=== TEST 1: HTTP with get.
9-
--- http_config
10-
lua_shared_dict dogs 1m;
18+
--- http_config eval: $::HttpConfig
1119
--- config
1220
location =/t {
1321
content_by_lua_block {
@@ -19,15 +27,14 @@ __DATA__
1927
}
2028
--- request
2129
GET /t?cmd=get%20doge
22-
--- response_body
23-
"wow"
30+
--- response_body eval
31+
"\"wow\""
2432
--- no_error_log
2533
[error]
2634
2735
2836
=== TEST 2: HTTP initialized without shdict, no dict arg.
29-
--- http_config
30-
lua_shared_dict dogs 1m;
37+
--- http_config eval: $::HttpConfig
3138
--- config
3239
location =/t {
3340
content_by_lua_block {
@@ -39,15 +46,14 @@ __DATA__
3946
}
4047
--- request
4148
GET /t?cmd=get%20doge
42-
--- response_body
43-
ERR no shdict selected
49+
--- response_body eval
50+
"ERR no shdict selected"
4451
--- no_error_log
4552
[error]
4653
4754
4855
=== TEST 3: HTTP initialized without shdict, has dict arg.
49-
--- http_config
50-
lua_shared_dict dogs 1m;
56+
--- http_config eval: $::HttpConfig
5157
--- config
5258
location =/t {
5359
content_by_lua_block {
@@ -59,15 +65,14 @@ ERR no shdict selected
5965
}
6066
--- request
6167
GET /t?dict=dogs&cmd=get%20doge
62-
--- response_body
63-
"wow"
68+
--- response_body eval
69+
"\"wow\""
6470
--- no_error_log
6571
[error]
6672
6773
6874
=== TEST 4: HTTP initialized without shdict, has wrong dict arg.
69-
--- http_config
70-
lua_shared_dict dogs 1m;
75+
--- http_config eval: $::HttpConfig
7176
--- config
7277
location =/t {
7378
content_by_lua_block {
@@ -79,15 +84,14 @@ ERR no shdict selected
7984
}
8085
--- request
8186
GET /t?dict=cats&cmd=get%20dog
82-
--- response_body
83-
ERR shdict 'cats' not defined
87+
--- response_body eval
88+
"ERR shdict 'cats' not defined"
8489
--- no_error_log
8590
[error]
8691
8792
8893
=== TEST 5: HTTP initialized with password, no password arg.
89-
--- http_config
90-
lua_shared_dict dogs 1m;
94+
--- http_config eval: $::HttpConfig
9195
--- config
9296
location =/t {
9397
content_by_lua_block {
@@ -99,15 +103,14 @@ ERR shdict 'cats' not defined
99103
}
100104
--- request
101105
GET /t?dict=dogs&cmd=get%20dog
102-
--- response_body
103-
ERR authentication required
106+
--- response_body eval
107+
"ERR authentication required"
104108
--- no_error_log
105109
[error]
106110
107111
108112
=== TEST 6: HTTP initialized with password, has password arg.
109-
--- http_config
110-
lua_shared_dict dogs 1m;
113+
--- http_config eval: $::HttpConfig
111114
--- config
112115
location =/t {
113116
content_by_lua_block {
@@ -119,15 +122,14 @@ ERR authentication required
119122
}
120123
--- request
121124
GET /t?dict=dogs&cmd=get%20doge&password=foobar
122-
--- response_body
123-
"wow"
125+
--- response_body eval
126+
"\"wow\""
124127
--- no_error_log
125128
[error]
126129
127130
128131
=== TEST 7: HTTP initialized with password, wrong password arg.
129-
--- http_config
130-
lua_shared_dict dogs 1m;
132+
--- http_config eval: $::HttpConfig
131133
--- config
132134
location =/t {
133135
content_by_lua_block {
@@ -139,8 +141,8 @@ ERR authentication required
139141
}
140142
--- request
141143
GET /t?dict=dogs&cmd=get%20doge&password=foobarbar
142-
--- response_body
143-
ERR invalid password
144+
--- response_body eval
145+
"ERR invalid password"
144146
--- no_error_log
145147
[error]
146148

t/redis-inline.t

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22

33
use Test::Nginx::Socket::Lua::Stream 'no_plan';
44

5+
use Cwd qw(cwd);
6+
7+
8+
my $pwd = cwd();
9+
10+
our $StreamConfig = qq{
11+
lua_package_path "$pwd/lib/?.lua;$pwd/lib/?/init.lua;;";
12+
lua_shared_dict dogs 1m;
13+
};
14+
515
#no_shuffle();
616
run_tests();
717

818
__DATA__
919
=== TEST 1: Redis inline protocol simple get.
10-
--- stream_config
11-
lua_shared_dict dogs 1m;
20+
--- stream_config eval: $::StreamConfig
1221
--- stream_server_config
1322
content_by_lua_block {
1423
ngx.shared.dogs:set("doge", "wow")
@@ -30,8 +39,7 @@ quit\r
3039
3140
3241
=== TEST 2: Redis inline protocol initialized without shdict, no dict arg.
33-
--- stream_config
34-
lua_shared_dict dogs 1m;
42+
--- stream_config eval: $::StreamConfig
3543
--- stream_server_config
3644
content_by_lua_block {
3745
ngx.shared.dogs:set("doge", "wow")
@@ -53,8 +61,7 @@ quit\r
5361
5462
5563
=== TEST 3: Redis inline protocol initialized without shdict, has dict arg.
56-
--- stream_config
57-
lua_shared_dict dogs 1m;
64+
--- stream_config eval: $::StreamConfig
5865
--- stream_server_config
5966
content_by_lua_block {
6067
ngx.shared.dogs:set("doge", "wow")
@@ -78,8 +85,7 @@ quit\r
7885
7986
8087
=== TEST 4: Redis inline protocol initialized without shdict, has wrong dict arg.
81-
--- stream_config
82-
lua_shared_dict dogs 1m;
88+
--- stream_config eval: $::StreamConfig
8389
--- stream_server_config
8490
content_by_lua_block {
8591
ngx.shared.dogs:set("doge", "wow")
@@ -101,8 +107,7 @@ quit\r
101107
102108
103109
=== TEST 5: Redis inline protocol initialized with password, no password arg.
104-
--- stream_config
105-
lua_shared_dict dogs 1m;
110+
--- stream_config eval: $::StreamConfig
106111
--- stream_server_config
107112
content_by_lua_block {
108113
ngx.shared.dogs:set("doge", "wow")
@@ -126,8 +131,7 @@ quit\r
126131
127132
128133
=== TEST 6: Redis inline protocol initialized with password, has password arg.
129-
--- stream_config
130-
lua_shared_dict dogs 1m;
134+
--- stream_config eval: $::StreamConfig
131135
--- stream_server_config
132136
content_by_lua_block {
133137
ngx.shared.dogs:set("doge", "wow")
@@ -153,8 +157,7 @@ quit\r
153157
154158
155159
=== TEST 7: Redis inline protocol initialized with password, wrong password arg.
156-
--- stream_config
157-
lua_shared_dict dogs 1m;
160+
--- stream_config eval: $::StreamConfig
158161
--- stream_server_config
159162
content_by_lua_block {
160163
ngx.shared.dogs:set("doge", "wow")
@@ -180,8 +183,7 @@ quit\r
180183
181184
182185
=== TEST 8: Redis inline protocol ping
183-
--- stream_config
184-
lua_shared_dict dogs 1m;
186+
--- stream_config eval: $::StreamConfig
185187
--- stream_server_config
186188
content_by_lua_block {
187189
local srv = require("resty.shdict.server")
@@ -202,8 +204,7 @@ quit\r
202204
203205
204206
=== TEST 9: Redis inline protocol parse line
205-
--- stream_config
206-
lua_shared_dict dogs 1m;
207+
--- stream_config eval: $::StreamConfig
207208
--- stream_server_config
208209
content_by_lua_block {
209210
ngx.shared.dogs:set("d'o'ge", "wow")

0 commit comments

Comments
 (0)