From 53f8f482732b444cc8a983f446f4c20fffb4617f Mon Sep 17 00:00:00 2001 From: franck cuny Date: Tue, 27 Apr 2010 17:36:52 +0200 Subject: tests --- t/05_filter_path.t | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 t/05_filter_path.t (limited to 't') 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; -- cgit v1.2.3