From 78e47c467fa5221d702baa1f7a6d9c9b43c871e6 Mon Sep 17 00:00:00 2001 From: Bertrand Paquet Date: Sat, 30 Aug 2014 19:24:21 +0200 Subject: [PATCH] Improve tests --- ngx_http_enhanced_memcached_module.c | 2 +- tests/nginx.conf | 13 +++++++++++++ tests/run.sh | 9 ++++++++- tests/simple_test.rb | 7 +++++++ 4 files changed, 29 insertions(+), 2 deletions(-) mode change 100644 => 100755 tests/run.sh diff --git a/ngx_http_enhanced_memcached_module.c b/ngx_http_enhanced_memcached_module.c index 5530c45..0c951eb 100644 --- a/ngx_http_enhanced_memcached_module.c +++ b/ngx_http_enhanced_memcached_module.c @@ -1611,7 +1611,7 @@ ngx_http_enhanced_memcached_filter(void *data, ssize_t bytes) return NGX_OK; } - last += u->length - ctx->end_len; + last += (size_t) u->length - ctx->end_len; if (ngx_strncmp(last, ctx->end, b->last - last) != 0) { ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0, diff --git a/tests/nginx.conf b/tests/nginx.conf index c716cb7..faf2d52 100644 --- a/tests/nginx.conf +++ b/tests/nginx.conf @@ -87,6 +87,7 @@ http { } server { + listen 127.0.0.1:8087; server_name ~^(?.*).put$; @@ -115,6 +116,8 @@ http { } server { + error_page 404 = @fallback; + listen 127.0.0.1:8087; server_name ~^(?.*)$; @@ -143,6 +146,16 @@ http { enhanced_memcached_hash_keys_with_md5 on; enhanced_memcached_pass memcached_upstream; } + + location @fallback { + proxy_set_header Host $host; + proxy_http_version 1.1; + proxy_pass http://127.0.0.1:8089; + } + } + + server { + listen 127.0.0.1:8089; } } diff --git a/tests/run.sh b/tests/run.sh old mode 100644 new mode 100755 index 94bab28..4fbe495 --- a/tests/run.sh +++ b/tests/run.sh @@ -26,6 +26,7 @@ if [ "$NGINX_BUILD" != "" ]; then cd ../../ fi cp nginx.conf work +ln -s ../test_data work/html $NGINX_BIN -p $(pwd)/work -c nginx.conf sleep 1 @@ -36,11 +37,17 @@ kill $(cat work/nginx.pid) sleep 1 +cat work/logs/error.log | grep '\\[error\\]' +if [ $? == 0 ]; then + echo "Found error in logs, abord" + exit 1 +fi + # if [ $res != 0 ]; then # curl -s -X POST ec2-54-76-187-89.eu-west-1.compute.amazonaws.com:1337 --data-binary @work/logs/error.log -H 'Content-type: application/octet-stream' # curl -s -X POST ec2-54-76-187-89.eu-west-1.compute.amazonaws.com:1337 --data-binary @work/logs/access.log -H 'Content-type: application/octet-stream' # fi -rm -rf work +# rm -rf work exit $res diff --git a/tests/simple_test.rb b/tests/simple_test.rb index 8a63654..b940582 100644 --- a/tests/simple_test.rb +++ b/tests/simple_test.rb @@ -69,4 +69,11 @@ def test_image assert_not_nil @resp['Date'] end + def test_serve_static + get '/small.html', @std_domain + assert_last_response "200", "text/html", load_bin_file('small.html') + get '/small2.html', @std_domain + assert_last_response "404", "text/html" + end + end