| 1 | package CHI::t::SetError; | ||
| 2 | 1 | $CHI::t::SetError::VERSION = '0.60'; | |
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use CHI::Test; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use CHI::Test::Util qw(activate_test_logger); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use base qw(CHI::Test::Class); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | sub readonly_cache { | ||
| 10 | 5 | ▶ | my ($on_set_error) = @_; |
|
Subroutine
readonly_cache: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 11 | |||
| 12 | 5 | return CHI->new( | |
| 13 | driver => '+CHI::Test::Driver::Readonly', | ||
| 14 | on_set_error => $on_set_error, | ||
| 15 | global => 1 | ||
| 16 | ); | ||
| 17 | } | ||
| 18 | |||
| 19 | sub test_set_errors : Tests { | ||
| 20 | 1 | ▶ | my ( $key, $value ) = ( 'medium', 'medium' ); |
|
Subroutine
test_set_errors: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 21 | |||
| 22 | 1 | my $error_pattern = | |
| 23 | qr/error during cache set for namespace='.*', key='medium', size=\d+.*: read-only cache/; | ||
| 24 | 1 | my $log = activate_test_logger(); | |
| 25 | |||
| 26 | 1 | my $cache; | |
| 27 | |||
| 28 | 1 | $cache = readonly_cache('ignore'); | |
| 29 | 1 | ▶ | lives_ok( sub { $cache->set( $key, $value ) }, "ignore - lives" ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 30 | 1 | ok( !defined( $cache->get($key) ), "ignore - miss" ); | |
| 31 | |||
| 32 | 1 | $cache = readonly_cache('die'); | |
| 33 | 1 | ▶ | throws_ok( sub { $cache->set( $key, $value ) }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 34 | 1 | $error_pattern, "die - dies" ); | |
| 35 | 1 | ok( !defined( $cache->get($key) ), "die - miss" ); | |
| 36 | |||
| 37 | 1 | $log->clear(); | |
| 38 | 1 | $cache = readonly_cache('log'); | |
| 39 | 1 | ▶ | lives_ok( sub { $cache->set( $key, $value ) }, "log - lives" ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 40 | 1 | ok( !defined( $cache->get($key) ), "log - miss" ); | |
| 41 | 1 | $log->contains_ok(qr/cache get for .* key='medium', .*: MISS/); | |
| 42 | 1 | $log->contains_ok($error_pattern); | |
| 43 | 1 | $log->empty_ok(); | |
| 44 | |||
| 45 | 1 | my ( $err_msg, $err_key ); | |
| 46 | $cache = readonly_cache( | ||
| 47 | sub { | ||
| 48 | 1 | ▶ | ( $err_msg, $err_key ) = @_; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 49 | } | ||
| 50 | 1 | ); | |
| 51 | 1 | ▶ | lives_ok( sub { $cache->set( $key, $value ) }, "custom - lives" ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 52 | 1 | ok( !defined( $cache->get($key) ), "custom - miss" ); | |
| 53 | 1 | like( $err_msg, $error_pattern, "custom - got msg" ); | |
| 54 | 1 | is( $err_key, $key, "custom - got key" ); | |
| 55 | |||
| 56 | throws_ok( | ||
| 57 | 1 | ▶ | sub { readonly_cache('bad') }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 58 | 1 | qr/Validation failed for|isa check for ".*" failed/, | |
| 59 | "bad - dies" | ||
| 60 | ); | ||
| 61 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 62 | |||
| 63 | 1 | 1; | |