| 1 | package CHI::t::Driver::File; | ||||||||||||||||||||
| 2 | 2 | $CHI::t::Driver::File::VERSION = '0.59'; | |||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use CHI::Test; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use CHI::Test::Util qw(random_string); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use CHI::Util qw(fast_catdir unique_id); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use File::Basename; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use File::Path; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use File::Temp qw(tempdir); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use base qw(CHI::t::Driver); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | my $root_dir; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | sub new_cache_options { | ||||||||||||||||||||
| 16 | 196 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
new_cache_options: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 196 | ▶ | $root_dir ||= tempdir( "chi-driver-file-XXXX", TMPDIR => 1, CLEANUP => 1 ); | ||||||||||||||||||
|
Condition66%2/3
$root_dir ||= tempdir("chi-driver-file-XXXX", "TMPDIR", 1, "CLEANUP", 1)
MC/DC0%0/2
$root_dir ||= tempdir("chi-driver-file-XXXX", "TMPDIR", 1, "CLEANUP", 1)
$root_dir
tempdir("chi-driver-file-XXXX", "TMPDIR", 1, "CLEANUP", 1)
Truth table66%2/3
A ||= B
A= $root_dirB= tempdir("chi-driver-file-XXXX", "TMPDIR", 1, "CLEANUP", 1)
| |||||||||||||||||||||
| 19 | 196 | return ( $self->SUPER::new_cache_options(), root_dir => $root_dir ); | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | { | ||||||||||||||||||||
| 23 | package CHI::t::Driver::File::NoTempDriver; | ||||||||||||||||||||
| 24 | 2 | $CHI::t::Driver::File::NoTempDriver::VERSION = '0.59'; | |||||||||||||||||||
| 25 | 2 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 2 | extends 'CHI::Driver::File'; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | sub generate_temporary_filename { | ||||||||||||||||||||
| 29 | 2 | ▶ | my ( $self, $dir, $file ) = @_; | ||||||||||||||||||
|
Subroutine
generate_temporary_filename: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 30 | 2 | return undef; | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | { | ||||||||||||||||||||
| 35 | 2 | package CHI::t::Driver::File::BadTempDriver; | |||||||||||||||||||
| 36 | 2 | $CHI::t::Driver::File::BadTempDriver::VERSION = '0.59'; | |||||||||||||||||||
| 37 | 2 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | 2 | extends 'CHI::Driver::File'; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | sub generate_temporary_filename { | ||||||||||||||||||||
| 41 | 2 | ▶ | my ( $self, $dir, $file ) = @_; | ||||||||||||||||||
|
Subroutine
generate_temporary_filename: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 42 | 2 | return "/dir/does/not/exist/$file"; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | # Test that we can override how temporary files are generated | ||||||||||||||||||||
| 47 | # | ||||||||||||||||||||
| 48 | 2 | sub test_generate_temporary_filename : Tests { | |||||||||||||||||||
| 49 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
test_generate_temporary_filename: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | $self->{cache} = | ||||||||||||||||||||
| 52 | 2 | $self->new_cache( driver => '+CHI::t::Driver::File::NoTempDriver' ); | |||||||||||||||||||
| 53 | 2 | $self->test_simple(); | |||||||||||||||||||
| 54 | $self->{cache} = | ||||||||||||||||||||
| 55 | 2 | $self->new_cache( driver => '+CHI::t::Driver::File::BadTempDriver' ); | |||||||||||||||||||
| 56 | 2 | ▶ | throws_ok { $self->test_simple() } qr/error during cache set/; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | 2 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | sub test_default_depth : Tests { | ||||||||||||||||||||
| 60 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
test_default_depth: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 1 | my $cache = $self->new_cache(); | |||||||||||||||||||
| 63 | 1 | is( $cache->depth, 2 ); | |||||||||||||||||||
| 64 | 2 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | sub test_creation_and_deletion : Tests { | ||||||||||||||||||||
| 67 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
test_creation_and_deletion: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 2 | my $cache = $self->new_cache(); | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 2 | my ( $key, $value ) = $self->kvpair(); | |||||||||||||||||||
| 72 | 2 | my $cache_file = $cache->path_to_key($key); | |||||||||||||||||||
| 73 | 2 | my $namespace_dir = $cache->path_to_namespace(); | |||||||||||||||||||
| 74 | 2 | ok( !-f $cache_file, "cache file '$cache_file' does not exist before set" ); | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 2 | $cache->set( $key, $value, 0 ); | |||||||||||||||||||
| 77 | 2 | ok( !defined $cache->get($key) ); | |||||||||||||||||||
| 78 | 2 | ok( -f $cache_file, "cache file '$cache_file' exists after set" ); | |||||||||||||||||||
| 79 | 2 | ok( -d $namespace_dir, "namespace dir '$namespace_dir' exists after set" ); | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 2 | $cache->remove($key); | |||||||||||||||||||
| 82 | 2 | ok( !-f $cache_file, | |||||||||||||||||||
| 83 | "cache file '$cache_file' does not exist after remove" ); | ||||||||||||||||||||
| 84 | 2 | ok( -d $namespace_dir, | |||||||||||||||||||
| 85 | "namespace dir '$namespace_dir' exists after remove" ); | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 2 | $cache->clear(); | |||||||||||||||||||
| 88 | 2 | ok( !-d $namespace_dir, | |||||||||||||||||||
| 89 | "namespace dir '$namespace_dir' does not exist after clear" ); | ||||||||||||||||||||
| 90 | 2 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | sub test_root_dir_does_not_exist : Tests { | ||||||||||||||||||||
| 93 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
test_root_dir_does_not_exist: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 2 | my $parent_dir = | |||||||||||||||||||
| 96 | tempdir( "chi-driver-file-XXXX", TMPDIR => 1, CLEANUP => 1 ); | ||||||||||||||||||||
| 97 | 2 | my $non_existent_root = fast_catdir( $parent_dir, unique_id() ); | |||||||||||||||||||
| 98 | 2 | ok( !-d $non_existent_root, "$non_existent_root does not exist" ); | |||||||||||||||||||
| 99 | 2 | my $cache = $self->new_cache( root_dir => $non_existent_root ); | |||||||||||||||||||
| 100 | 2 | ok( !defined( $cache->get('foo') ), 'miss' ); | |||||||||||||||||||
| 101 | 2 | $cache->set( 'foo', 5 ); | |||||||||||||||||||
| 102 | 2 | is( $cache->get('foo'), 5, 'hit' ); | |||||||||||||||||||
| 103 | 2 | ok( -d $non_existent_root, "$non_existent_root exists after set" ); | |||||||||||||||||||
| 104 | 2 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | sub test_ignore_bad_namespaces : Tests { | ||||||||||||||||||||
| 107 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
test_ignore_bad_namespaces: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 108 | 2 | my $cache = | |||||||||||||||||||
| 109 | $self->new_cleared_cache( root_dir => | ||||||||||||||||||||
| 110 | tempdir( "chi-driver-file-XXXX", TMPDIR => 1, CLEANUP => 1 ) ); | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 2 | foreach my $dir ( ".etc", "+2eetd", 'a@b', 'a+40c', "plain" ) { | |||||||||||||||||||
| 113 | 10 | mkpath( join( "/", $cache->root_dir, $dir ) ); | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | cmp_set( | ||||||||||||||||||||
| 116 | 2 | [ $cache->get_namespaces ], | |||||||||||||||||||
| 117 | [ '.etd', 'a@c', 'plain' ], | ||||||||||||||||||||
| 118 | 'only valid dirs shown as namespaces' | ||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||
| 120 | 2 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | sub test_default_discard : Tests { | ||||||||||||||||||||
| 123 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
test_default_discard: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 124 | 2 | my $cache = $self->new_cleared_cache( is_size_aware => 1 ); | |||||||||||||||||||
| 125 | 2 | is( $cache->discard_policy, 'arbitrary' ); | |||||||||||||||||||
| 126 | 2 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 2 | 1; | |||||||||||||||||||