summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-03-30 15:36:09 +0200
committerfranck cuny <franck@lumberjaph.net>2010-03-30 15:36:09 +0200
commitf0995c76a0dc73772f328f892ffcc3fefb1e6d96 (patch)
tree36413c2b0cd32c9510b0cc5ba3a66d11ce3e9bad
parentupdate POD, fix redis backend (diff)
downloadplack-middleware-apiratelimit-f0995c76a0dc73772f328f892ffcc3fefb1e6d96.tar.gz
clean tests
-rw-r--r--t/01_basic.t26
1 files changed, 9 insertions, 17 deletions
diff --git a/t/01_basic.t b/t/01_basic.t
index 5fb3212..336a6e2 100644
--- a/t/01_basic.t
+++ b/t/01_basic.t
@@ -5,17 +5,12 @@ use Test::More;
 use Plack::Test;
 use Plack::Builder;
 use HTTP::Request::Common;
-
-#use AnyEvent::Redis;
-#my $redis = AnyEvent::Redis->new(port => 6379, server => '127.0.0.1');
-#$redis->flushall;
+use Plack::Middleware::APIRateLimit::Backend::Hash;
 
 my $handler = builder {
-    enable "APIRateLimit";
-    #enable "APIRateLimit", requests_per_hour => 2, backend => "Hash";
-    #enable "APIRateLimit",
-        #requests_per_hour => 2,
-        #backend => [ "Redis", { port => 6379, server => '127.0.0.1' } ];
+    enable "APIRateLimit",
+        requests_per_hour => 2,
+        backend => Plack::Middleware::APIRateLimit::Backend::Hash->new();
     sub { [ '200', [ 'Content-Type' => 'text/html' ], ['hello world'] ] };
 };
 
@@ -23,21 +18,18 @@ test_psgi
     app    => $handler,
     client => sub {
     my $cb = shift;
-    use YAML::Syck;
     {
         for ( 1 .. 2 ) {
             my $req = GET "http://localhost/";
             my $res = $cb->($req);
-            is $res->code, 200;
-	    ok $res->headers('X-RateLimit-Limit');
-#	    warn Dump $res;
+            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;
-	ok $res->headers('X-RateLimit-Reset');
-#	warn Dump $res;
+        is $res->code, 503, 'http response is 503';
+        ok $res->headers('X-RateLimit-Reset'), 'header reset';
     }
-};
+    };
 
 done_testing;