diff options
author | franck cuny <franck@lumberjaph.net> | 2010-04-27 17:36:52 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-04-27 17:36:52 +0200 |
commit | 53f8f482732b444cc8a983f446f4c20fffb4617f (patch) | |
tree | 2d4bedfebe7748360c2ff770398843bf2f20a5a2 | |
parent | check if a path should be throttled (diff) | |
download | plack-middleware-throttle-53f8f482732b444cc8a983f446f4c20fffb4617f.tar.gz |
tests
-rw-r--r-- | t/05_filter_path.t | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/t/05_filter_path.t b/t/05_filter_path.t new file mode 100644 index 0000000..73ec24b --- /dev/null +++ b/t/05_filter_path.t @@ -0,0 +1,39 @@ +use strict; +use warnings; +use Test::More; + +use Plack::Test; +use Plack::Builder; +use HTTP::Request::Common; +use Plack::Middleware::Throttle::Backend::Hash; + +my $handler = builder { + enable "Throttle::Hourly", + max => 1, + backend => Plack::Middleware::Throttle::Backend::Hash->new(), + path => [qr/^\/foo/]; + sub { [ '200', [ 'Content-Type' => 'text/html' ], ['hello world'] ] }; +}; + +test_psgi + app => $handler, + client => sub { + my $cb = shift; + { + for ( 1 .. 2 ) { + my $req = GET "http://localhost/foo"; + my $res = $cb->($req); + is $res->content, 'hello world', 'content is valid'; + ok !$res->header('X-RateLimit-Limit'), 'no header ratelimit'; + } + my $req = GET "http://localhost/bar"; + my $res = $cb->($req); + is $res->content, 'hello world', 'content is valid'; + ok $res->header('X-RateLimit-Limit'), 'header ratelimit'; + my $req = GET "http://localhost/bar"; + my $res = $cb->($req); + is $res->code, 503, 'rate limit exceeded'; + } +}; + +done_testing; |