summaryrefslogtreecommitdiff
path: root/t/04_combine.t
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-04-01 17:02:50 +0200
committerfranck cuny <franck@lumberjaph.net>2010-04-01 17:02:50 +0200
commit60faca51cb5ecdd89daa61a6c897dacac813aaa8 (patch)
treeec7a45670b9fdc84313c967c22ae6368097b9418 /t/04_combine.t
parentadd tests (diff)
downloadplack-middleware-throttle-60faca51cb5ecdd89daa61a6c897dacac813aaa8.tar.gz
add tests
Diffstat (limited to 't/04_combine.t')
-rw-r--r--t/04_combine.t35
1 files changed, 35 insertions, 0 deletions
diff --git a/t/04_combine.t b/t/04_combine.t
new file mode 100644
index 0000000..31a4e98
--- /dev/null
+++ b/t/04_combine.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;