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