[Catalyst-commits] r13677 - in trunk/Catalyst-Plugin-PageCache/t: . lib lib/TestApp/Controller

timbunce at dev.catalyst.perl.org timbunce at dev.catalyst.perl.org
Mon Nov 1 20:08:19 GMT 2010


Author: timbunce
Date: 2010-11-01 20:08:19 +0000 (Mon, 01 Nov 2010)
New Revision: 13677

Modified:
   trunk/Catalyst-Plugin-PageCache/t/14keymaker.t
   trunk/Catalyst-Plugin-PageCache/t/lib/TestApp.pm
   trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/Controller/Cache.pm
Log:
Add tests for cache key generation.


Modified: trunk/Catalyst-Plugin-PageCache/t/14keymaker.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/14keymaker.t	2010-11-01 18:46:12 UTC (rev 13676)
+++ trunk/Catalyst-Plugin-PageCache/t/14keymaker.t	2010-11-01 20:08:19 UTC (rev 13677)
@@ -10,10 +10,8 @@
 use File::Path;
 
 BEGIN {
-    eval "use Catalyst::Plugin::Cache";
-    plan $@
-        ? ( skip_all => 'needs Catalyst::Plugin::Cache for testing' )
-      : ( tests => 8 );
+    skip_all => 'needs Catalyst::Plugin::Cache for testing'
+        if not eval "use Catalyst::Plugin::Cache";
 }
 
 # This test that options can be passed to cache.
@@ -23,6 +21,28 @@
 
 use Catalyst::Test 'TestApp';
 
+
+#####
+# These first few tests are really testing internal behaviour
+
+ok( my $res = request('http://host1/cache/get_key'), 'request ok' );
+is( $res->content, '/cache/get_key', 'key is just url for simple case' );
+
+ok( $res = request('http://host1/cache/get_key?foo='.('x' x 200)), 'request ok' );
+like $res->content, qr{/cache/get_key\?[0-9a-f]{40,40}$}i,
+    'cache key has params encoded';
+
+ok( $res = request('http://host1/cache/get_key/'.('x' x 200)), 'request ok' );
+like $res->content, qr{/cache/get_key/x+[0-9a-f]{40,40}$}i,
+    'cache key encodes long paths';
+
+# reset the count for the following tests
+ok( $res = request('http://host1/cache/set_count/0', 'request ok' ) );
+is( $res->content, 0, 'count is reset' );
+
+#
+####
+
 # add config option
 # cannot call TestApp->config() because TestApp has already called setup
 TestApp->config->{'Plugin::PageCache'}->{key_maker} = sub {
@@ -31,7 +51,7 @@
 };
 
 # cache a page
-ok( my $res = request('http://host1/cache/count'), 'request ok' );
+ok( $res = request('http://host1/cache/count'), 'request ok' );
 is( $res->content, 1, 'count is 1' );
 
 # page will be served from cache
@@ -45,3 +65,5 @@
 # page will be served from cache
 ok( $res = request('http://host2/cache/count'), 'request ok' );
 is( $res->content, 2, 'count is still 2 from cache' );
+
+done_testing();

Modified: trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/Controller/Cache.pm
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/Controller/Cache.pm	2010-11-01 18:46:12 UTC (rev 13676)
+++ trunk/Catalyst-Plugin-PageCache/t/lib/TestApp/Controller/Cache.pm	2010-11-01 20:08:19 UTC (rev 13677)
@@ -25,6 +25,14 @@
     $c->res->output( $c->config->{counter} );
 }
 
+sub set_count : Local {
+    my ( $self, $c, $newvalue ) = @_;
+
+    $c->config->{counter} = $newvalue || 0;
+
+    $c->res->output( $c->config->{counter} );
+}
+
 sub another_auto_count : Local {
     my ( $self, $c ) = @_;
 
@@ -100,4 +108,12 @@
     $c->res->body('busy');
 }
 
+sub get_key : Local {
+    my ( $self, $c ) = @_;
+
+    $c->cache_page( 1 );
+
+    $c->res->output( $c->_get_page_cache_key );
+}
+
 1;

Modified: trunk/Catalyst-Plugin-PageCache/t/lib/TestApp.pm
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/lib/TestApp.pm	2010-11-01 18:46:12 UTC (rev 13676)
+++ trunk/Catalyst-Plugin-PageCache/t/lib/TestApp.pm	2010-11-01 20:08:19 UTC (rev 13677)
@@ -13,9 +13,6 @@
 
 TestApp->setup( qw/Cache Cache::Store::Memory PageCache/ );
 
-sub default : Private {
-    my ( $self, $c ) = @_;
-    
-}
+#sub default : Private { my ( $self, $c ) = @_; }
 
 1;




More information about the Catalyst-commits mailing list