Skip to content

Commit 076164c

Browse files
committed
#76 - auto tests. Feature was commited before (w/o an issue).
1 parent aa72678 commit 076164c

File tree

5 files changed

+88
-17
lines changed

5 files changed

+88
-17
lines changed

Makefile

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ INC_FLAGS += -I$(CUR_PATH)/third_party/msgpuck
2121
INC_FLAGS += -I$(CUR_PATH)/src
2222
YAJL_LIB = $(YAJL_PATH)/build/yajl-2.1.0/lib/libyajl_s.a
2323
LDFLAGS = -L$(YAJL_PATH)/build/yajl-2.1.0/lib
24+
PREFIX = /usr/local/nginx
2425

2526
DEV_CFLAGS += -ggdb3 -O0 -Wall -Werror
2627

@@ -41,10 +42,15 @@ gen_version:
4142
build: gen_version utils
4243
$(MAKE) -C $(NGX_PATH)
4344

44-
configure:
45+
__install:
4546
cd $(NGX_PATH) && $(NGX_CONFIGURE) \
46-
--with-cc-opt='$(INC_FLAGS)'\
47-
--add-module='$(MODULE_PATH)'
47+
--with-cc-opt='$(INC_FLAGS)' \
48+
--add-module='$(MODULE_PATH)' \
49+
--prefix=$(PREFIX)
50+
make -j2
51+
sudo mkdir -p $(PREFIX)/conf $(PREFIX)/logs $(PREFIX)/sbin
52+
sudo cp -Rf $(NGX_PATH)/conf/* $(PREFIX)/conf
53+
sudo cp $(NGX_PATH)/objs/nginx $(PREFIX)/sbin/nginx
4854

4955
configure-as-dynamic:
5056
cd $(NGX_PATH) && $(NGX_CONFIGURE) --add-dynamic-module='$(MODULE_PATH)'
@@ -55,16 +61,8 @@ configure-debug:
5561
--prefix=$(PREFIX_PATH) \
5662
--add-module=$(MODULE_PATH) \
5763
--with-debug
58-
mkdir -p $(PREFIX_PATH)/conf $(PREFIX_PATH)/logs
59-
cp -Rf $(NGX_PATH)/conf/* $(PREFIX_PATH)/conf
60-
cp -f $(CUR_PATH)/test/ngx_confs/tnt_server_test.conf $(PREFIX_PATH)/conf/tnt_server_test.conf
61-
cp -f $(CUR_PATH)/test/ngx_confs/nginx.dev.conf $(PREFIX_PATH)/conf/nginx.conf
6264

63-
configure-for-testing:
64-
cd $(NGX_PATH) && $(NGX_CONFIGURE) \
65-
--with-cc-opt='$(INC_FLAGS)'\
66-
--prefix=$(PREFIX_PATH) \
67-
--add-module=$(MODULE_PATH)
65+
configure-for-testing: configure-debug
6866
mkdir -p $(PREFIX_PATH)/conf $(PREFIX_PATH)/logs
6967
cp -Rf $(NGX_PATH)/conf/* $(PREFIX_PATH)/conf
7068
cp -f $(CUR_PATH)/test/ngx_confs/tnt_server_test.conf $(PREFIX_PATH)/conf/tnt_server_test.conf
@@ -77,8 +75,6 @@ configure-as-dynamic-debug:
7775
--add-dynamic-module=$(MODULE_PATH) \
7876
--with-debug
7977
mkdir -p $(PREFIX_PATH)/conf $(PREFIX_PATH)/logs $(PREFIX_PATH)/modules
80-
# cp -f $(CUR_PATH)/nginx/objs/ngx_http_tnt_module.so $(PREFIX_PATH)/modules/ngx_http_tnt_module.so
81-
# cp -f $(CUR_PATH)/nginx/objs/ngx_http_tnt_module.so /usr/local/nginx/modules/ngx_http_tnt_module.so
8278
cp -Rf $(NGX_PATH)/conf/* $(PREFIX_PATH)/conf
8379
cp -f $(CUR_PATH)/test/ngx_confs/nginx.dev.dyn.conf $(PREFIX_PATH)/conf/nginx.conf
8480
cp -f $(CUR_PATH)/test/ngx_confs/tnt_server_test.conf $(PREFIX_PATH)/conf/tnt_server_test.conf

src/ngx_http_tnt_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
#ifndef NGX_HTTP_TNT_VERSION_H
3434
#define NGX_HTTP_TNT_VERSION_H 1
3535

36-
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.3.5"
36+
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.3.6"
3737

3838
#endif

test/http_utils.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,33 @@
1313
BASE_URL = 'http://0.0.0.0:8081'
1414

1515

16+
def post_form(url, values, headers=None):
17+
out = '{}'
18+
try:
19+
data = urllib.urlencode(values)
20+
req = urllib2.Request(url, data)
21+
if headers:
22+
for header in headers:
23+
req.add_header(header, headers[header])
24+
response = urllib2.urlopen(req)
25+
out = response.read()
26+
rc = response.getcode()
27+
if VERBOSE:
28+
print("code: ", rc, " recv: '", out, "'")
29+
if rc != 500:
30+
return (rc, json.loads(out))
31+
return (rc, False)
32+
except urllib2.HTTPError as e:
33+
if e.code == 400:
34+
out = e.read();
35+
if VERBOSE:
36+
print("code: ", e.code, " recv: '", out, "'")
37+
return (e.code, json.loads(out))
38+
except Exception as e:
39+
print(traceback.format_exc())
40+
return (False, e)
41+
42+
1643
def post(url, data, headers):
1744
out = '{}'
1845
try:
@@ -176,15 +203,29 @@ def get_success_pure(url, data, headers):
176203
assert(code == 200), 'expected 200'
177204
return msg
178205

179-
def post_success(url, data, headers, print_f=None):
206+
def post_success(url, data, headers=None, print_f=None):
180207
(code, msg) = post(url, data, headers)
181208
if print_f:
182209
print_f(code, msg)
183210
assert(code == 200), 'expected 200'
184211
result = get_result(msg)
185212
return result
186213

187-
def post_success_pure(url, data, headers):
214+
def post_form_success(url, data, headers=None, print_f=None):
215+
(code, msg) = post_form(url, data, headers)
216+
if print_f:
217+
print_f(code, msg)
218+
assert(code == 200), 'expected 200'
219+
return msg
220+
221+
def post_form_ec500(url, data, headers=None, print_f=None):
222+
(code, msg) = post_form(url, data, headers)
223+
if print_f:
224+
print_f(code, msg)
225+
assert(code == 500), 'expected 500'
226+
return msg
227+
228+
def post_success_pure(url, data, headers=None):
188229
(code, msg) = post(url, data, headers)
189230
assert(code == 200), 'expected 200'
190231
return msg

test/test.lua

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env tarantool
2+
13
json = require('json')
24
yaml = require('yaml')
35
os = require('os')

test/v24_features.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,35 @@
4747
result = result[0]
4848
assert(result['args']['a'] == arg_a), 'does not expected (args.a)'
4949

50+
# ============
51+
#
52+
print('[+] Post form')
53+
preset_method_location = BASE_URL + '/form'
54+
data = { 'a':'b', 'b':'c', 'c':'d'}
55+
result = get_result(post_form_success(preset_method_location, data))
56+
assert(result[0]['body'] == urllib.urlencode(data)), 'result does not match'
57+
# ============
58+
#
59+
print('[+] Post large form')
60+
preset_method_location = BASE_URL + '/form_large'
61+
for i in range(1000):
62+
key = 'a' + str(i)
63+
data[key] = 'b'
64+
result = get_result(post_form_success(preset_method_location, data))
65+
assert(result[0]['body'] == urllib.urlencode(data)), "result does not matched"
66+
67+
# ============
68+
#
69+
print('[+] Post empty form')
70+
preset_method_location = BASE_URL + '/form_nothing'
71+
result = get_result(post_form_success(preset_method_location, {}))
72+
assert(not 'body' in result[0]), "result contains 'body'"
73+
74+
# ============
75+
#
76+
print('[+] Post overflow form')
77+
preset_method_location = BASE_URL + '/form_large'
78+
for i in range(100000):
79+
key = 'a' + str(i)
80+
data[key] = 'b'
81+
post_form_ec500(preset_method_location, data, None, default_print_f)

0 commit comments

Comments
 (0)