Skip to content

Commit

Permalink
Add more unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
tkan145 committed Sep 28, 2023
1 parent cf4bcad commit 79fc3ac
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions t/apicast-policy-buffering.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
use lib 't';
use Test::APIcast::Blackbox 'no_plan';

require("http_proxy.pl");

sub large_body {
my $res = "";
for (my $i=0; $i <= 1024; $i++) {
$res = $res . "1111111 1111111 1111111 1111111\n";
}
return $res;
}

$ENV{'LARGE_BODY'} = large_body();

require("policies.pl");

run_tests();

__DATA__
Expand Down Expand Up @@ -50,3 +64,102 @@ GET /?user_key=
"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nhello\r\n0\r\n\r\n"
--- response_body chomp
hello
=== TEST 2: default configuration (buffered) with big file
--- configuration
{
"services": [
{
"backend_version": 1,
"proxy": {
"api_backend": "http://test-upstream.lvh.me:$TEST_NGINX_SERVER_PORT/",
"proxy_rules": [
{ "pattern": "/", "http_method": "POST", "metric_system_name": "hits", "delta": 2 }
],
"policy_chain": [
{
"name": "buffering",
"version": "builtin",
"configuration": {}
},
{
"name": "apicast",
"version": "builtin",
"configuration": {}
}
]
}
}
]
}
--- backend
location /transactions/authrep.xml {
content_by_lua_block {
ngx.exit(200)
}
}
--- upstream
server_name test-upstream.lvh.me;
location / {
access_by_lua_block {
ngx.say("yay, api backend")
}
}
--- request eval
"POST /?user_key= \n" . $ENV{LARGE_BODY}
--- error_code: 200
--- error_log env
a client request body is buffered to a temporary file
--- no_error_log
=== TEST 3: request buffering off (un-buffered) with big file
--- ONLY
--- configuration
{
"services": [
{
"backend_version": 1,
"proxy": {
"api_backend": "http://test-upstream.lvh.me:$TEST_NGINX_SERVER_PORT/",
"proxy_rules": [
{ "pattern": "/", "http_method": "POST", "metric_system_name": "hits", "delta": 2 }
],
"policy_chain": [
{
"name": "buffering",
"version": "builtin",
"configuration": {
"request_buffering": false
}
},
{
"name": "apicast",
"version": "builtin",
"configuration": {}
}
]
}
}
]
}
--- backend
location /transactions/authrep.xml {
content_by_lua_block {
ngx.exit(200)
}
}
--- upstream
server_name test-upstream.lvh.me;
location / {
access_by_lua_block {
ngx.say("yay, api backend")
}
}
--- request eval
"POST /?user_key= \n" . $ENV{LARGE_BODY}
--- error_code: 200
--- grep_error_log
a client request body is buffered to a temporary file
--- grep_error_log_out

0 comments on commit 79fc3ac

Please sign in to comment.