Change config key in tests
[catagits/Catalyst-Plugin-Cache.git] / t / key_regexes.t
CommitLineData
c28ee69c 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More 'no_plan';
7
8use ok "Catalyst::Plugin::Cache";
9use ok "Catalyst::Plugin::Cache::Choose::KeyRegexes";
10
33002c69 11use Catalyst::Plugin::Cache::Backend::Memory;
12
c28ee69c 13{
14 package MockApp;
15 use base qw/Catalyst::Plugin::Cache Catalyst::Plugin::Cache::Choose::KeyRegexes/;
16
17 our %config = (
d18c37f3 18 'Plugin::Cache' => {
c28ee69c 19 key_regexes => [
20 qr/^foo/ => "foo_store",
21 qr/^bar/ => "bar_store",
22 ],
e9154310 23 ### as of 0.06, you must specify a backend
24 backend => {
25 class => 'Catalyst::Plugin::Cache::Backend::Memory',
26 }
c28ee69c 27 },
28 );
29 sub config { \%config }
c28ee69c 30}
31
32
33MockApp->setup;
34my $c = bless {}, "MockApp";
35
33002c69 36MockApp->register_cache_backend( default => Catalyst::Plugin::Cache::Backend::Memory->new );
37MockApp->register_cache_backend( foo_store => Catalyst::Plugin::Cache::Backend::Memory->new );
38MockApp->register_cache_backend( bar_store => Catalyst::Plugin::Cache::Backend::Memory->new );
c28ee69c 39
2e4bde89 40is( $c->choose_cache_backend_wrapper( key => "baz" ), $c->default_cache_backend, "chose default" );
41is( $c->choose_cache_backend_wrapper( key => "foo" ), $c->get_cache_backend("foo_store"), "chose foo" );
42is( $c->choose_cache_backend_wrapper( key => "bar" ), $c->get_cache_backend("bar_store"), "chose bar" );
c28ee69c 43
44$c->cache_set( foo_laa => "laa" );
45$c->cache_set( bar_laa => "laa" );
46$c->cache_set( baz_laa => "laa" );
47
2e4bde89 48is( $c->default_cache_backend->get("baz_laa"), "laa", "non match stored in default" );
49is( $c->default_cache_backend->get("foo_laa"), undef, "no foo key" );
50is( $c->default_cache_backend->get("bar_laa"), undef, "no bar key" );
c28ee69c 51
52
2e4bde89 53is( $c->get_cache_backend("foo_store")->get("baz_laa"), undef, "no non match in foo store" );
54is( $c->get_cache_backend("foo_store")->get("foo_laa"), "laa", "has foo key" );
55is( $c->get_cache_backend("foo_store")->get("bar_laa"), undef, "no bar key" );
c28ee69c 56
57
2e4bde89 58is( $c->get_cache_backend("bar_store")->get("baz_laa"), undef, "no non match in bar store" );
59is( $c->get_cache_backend("bar_store")->get("foo_laa"), undef, "no foo key" );
60is( $c->get_cache_backend("bar_store")->get("bar_laa"), "laa", "has bar key" );
c28ee69c 61
62