1a3f37404ba20690008103ca6c7ed0ee4cbc1878
2 use lib
(split(/:/, $ENV{GITPERLLIB
}));
10 use lib
$ENV{GITWEBLIBDIR
} || "$ENV{GIT_BUILD_DIR}/gitweb/lib";
13 # Test creating a cache
15 BEGIN { use_ok
('GitwebCache::SimpleFileCache'); }
16 diag
("Using lib '$INC[0]'");
17 diag
("Testing '$INC{'GitwebCache/SimpleFileCache.pm'}'");
19 my $cache = new_ok
('GitwebCache::SimpleFileCache');
21 # Test that default values are defined
23 ok
(defined $GitwebCache::SimpleFileCache
::DEFAULT_CACHE_ROOT
,
24 '$DEFAULT_CACHE_ROOT defined');
25 ok
(defined $GitwebCache::SimpleFileCache
::DEFAULT_CACHE_DEPTH
,
26 '$DEFAULT_CACHE_DEPTH defined');
28 # Test accessors and default values for cache
31 skip
'default values not defined', 3
32 unless ($GitwebCache::SimpleFileCache
::DEFAULT_CACHE_ROOT
&&
33 $GitwebCache::SimpleFileCache
::DEFAULT_CACHE_DEPTH
);
35 is
($cache->get_namespace(), '', "default namespace is ''");
36 cmp_ok
($cache->get_root(), 'eq', $GitwebCache::SimpleFileCache
::DEFAULT_CACHE_ROOT
,
37 "default cache root is '$GitwebCache::SimpleFileCache::DEFAULT_CACHE_ROOT'");
38 cmp_ok
($cache->get_depth(), '==', $GitwebCache::SimpleFileCache
::DEFAULT_CACHE_DEPTH
,
39 "default cache depth is $GitwebCache::SimpleFileCache::DEFAULT_CACHE_DEPTH");
42 # Test the getting, setting, and removal of a cached value
43 # (Cache::Cache interface)
46 my $value = 'Test Value';
48 subtest
'Cache::Cache interface' => sub {
49 foreach my $method (qw(get set remove)) {
50 can_ok
($cache, $method);
53 $cache->set($key, $value);
54 cmp_ok
($cache->get_size($key), '>', 0, 'get_size after set, is greater than 0');
55 is
($cache->get($key), $value, 'get after set, returns cached value');
57 ok
(!defined($cache->get($key)), 'get after remove, is undefined');
59 eval { $cache->remove('Not-Existent Key'); };
60 ok
(!$@
, 'remove on non-existent key doesn\'t die');
66 # Test the getting and setting of a cached value
74 subtest
'CHI interface' => sub {
75 can_ok
($cache, qw(compute));
77 is
($cache->compute($key, \
&get_value
), $value, "compute 1st time (set) returns '$value'");
78 is
($cache->compute($key, \
&get_value
), $value, "compute 2nd time (get) returns '$value'");
79 is
($cache->compute($key, \
&get_value
), $value, "compute 3rd time (get) returns '$value'");
80 cmp_ok
($call_count, '==', 1, 'get_value() is called once from compute');