summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--t/05_filter_path.t39
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;