diff options
| author | franck cuny <franck@lumberjaph.net> | 2010-04-01 17:02:18 +0200 |
|---|---|---|
| committer | franck cuny <franck@lumberjaph.net> | 2010-04-01 17:02:18 +0200 |
| commit | c3edbdf1b4bd4fc6091c811e598dcaeb4a0fd6e0 (patch) | |
| tree | 686c916ecbf7fba5ab99f659ead5e269c7d32def /t/01_hourly.t | |
| parent | handle black and white list, add support to interval (diff) | |
| download | plack-middleware-throttle-c3edbdf1b4bd4fc6091c811e598dcaeb4a0fd6e0.tar.gz | |
add tests
Diffstat (limited to 't/01_hourly.t')
| -rw-r--r-- | t/01_hourly.t | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/t/01_hourly.t b/t/01_hourly.t new file mode 100644 index 0000000..31a4e98 --- /dev/null +++ b/t/01_hourly.t @@ -0,0 +1,35 @@ +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 => 2, + backend => Plack::Middleware::Throttle::Backend::Hash->new(); + 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/"; + my $res = $cb->($req); + is $res->code, 200, 'http response is 200'; + ok $res->headers('X-RateLimit-Limit'), 'header ratelimit'; + } + my $req = GET "http://localhost/"; + my $res = $cb->($req); + is $res->code, 503, 'http response is 503'; + ok $res->headers('X-RateLimit-Reset'), 'header reset'; + } + }; + +done_testing; |
