summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-05-13 16:00:58 -0500
committerLuke Kanies <luke@madstop.com>2008-05-13 16:00:58 -0500
commit6efe4000dda3379e867786a9c2d4ae0f0cdfc3be (patch)
treea16fd1ae1f4aab7fe04af88daa78f1be1a2b1f3e /spec/unit
parent68d8d0ae0686939d94dae8ccc70e5582187335dc (diff)
Using the new Cacher class for handling cached data.
This provides a single, global bit for determining whether a given piece of cached data is still valid.
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/file_serving/configuration.rb6
-rwxr-xr-xspec/unit/file_serving/mount.rb8
-rwxr-xr-xspec/unit/indirector/indirection.rb26
-rwxr-xr-xspec/unit/network/http_pool.rb19
-rwxr-xr-xspec/unit/node.rb2
-rwxr-xr-xspec/unit/node/catalog.rb5
-rwxr-xr-xspec/unit/node/facts.rb8
-rwxr-xr-xspec/unit/transaction/report.rb2
-rwxr-xr-xspec/unit/util/cacher.rb24
9 files changed, 38 insertions, 62 deletions
diff --git a/spec/unit/file_serving/configuration.rb b/spec/unit/file_serving/configuration.rb
index a0710e20d..d51fa70b2 100755
--- a/spec/unit/file_serving/configuration.rb
+++ b/spec/unit/file_serving/configuration.rb
@@ -15,12 +15,12 @@ describe Puppet::FileServing::Configuration do
it "should have a method for removing the current configuration instance" do
old = Puppet::FileServing::Configuration.create
- Puppet::FileServing::Configuration.clear_cache
+ Puppet::Util::Cacher.invalidate
Puppet::FileServing::Configuration.create.should_not equal(old)
end
after do
- Puppet::FileServing::Configuration.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
@@ -32,7 +32,7 @@ describe Puppet::FileServing::Configuration do
end
after :each do
- Puppet::FileServing::Configuration.clear_cache
+ Puppet::Util::Cacher.invalidate
end
describe Puppet::FileServing::Configuration, " when initializing" do
diff --git a/spec/unit/file_serving/mount.rb b/spec/unit/file_serving/mount.rb
index ebe058301..6f491e3b2 100755
--- a/spec/unit/file_serving/mount.rb
+++ b/spec/unit/file_serving/mount.rb
@@ -12,9 +12,9 @@ end
describe Puppet::FileServing::Mount do
it "should provide a method for clearing its cached host information" do
- Puppet::FileServing::Mount.new("whatever").send(:localmap)
- Puppet::FileServing::Mount.clear_cache
- Puppet::FileServing::Mount.send(:class_variable_get, "@@localmap").should be_nil
+ old = Puppet::FileServing::Mount.localmap
+ Puppet::Util::Cacher.invalidate
+ Puppet::FileServing::Mount.localmap.should_not equal(old)
end
end
@@ -106,7 +106,7 @@ describe Puppet::FileServing::Mount, " when finding files" do
end
after do
- Puppet::FileServing::Mount.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb
index cefd0557e..e4799d3ff 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -87,6 +87,9 @@ describe "Delegation Authorizer", :shared => true do
end
describe Puppet::Indirector::Indirection do
+ after do
+ Puppet::Util::Cacher.invalidate
+ end
describe "when initializing" do
# (LAK) I've no idea how to test this, really.
it "should store a reference to itself before it consumes its options" do
@@ -494,7 +497,7 @@ describe Puppet::Indirector::Indirection do
after :each do
@indirection.delete
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
@@ -615,15 +618,6 @@ describe Puppet::Indirector::Indirection do
@indirection.terminus(:foo).should equal(@terminus)
end
- it "should allow the clearance of cached terminus instances" do
- terminus1 = mock 'terminus1'
- terminus2 = mock 'terminus2'
- @terminus_class.stubs(:new).returns(terminus1, terminus2, ArgumentError)
- @indirection.terminus(:foo).should equal(terminus1)
- @indirection.class.clear_cache
- @indirection.terminus(:foo).should equal(terminus2)
- end
-
# Make sure it caches the terminus.
it "should return the same terminus instance each time for a given name" do
@terminus_class.stubs(:new).returns(@terminus)
@@ -638,7 +632,6 @@ describe Puppet::Indirector::Indirection do
after do
@indirection.delete
- Puppet::Indirector::Indirection.clear_cache
end
end
@@ -675,7 +668,6 @@ describe Puppet::Indirector::Indirection do
after do
@indirection.delete
- Puppet::Indirector::Indirection.clear_cache
end
end
@@ -706,15 +698,6 @@ describe Puppet::Indirector::Indirection do
@indirection.cache.should equal(@cache)
@indirection.cache.should equal(@cache)
end
-
- it "should remove the cache terminus when all other terminus instances are cleared" do
- cache2 = mock 'cache2'
- @cache_class.stubs(:new).returns(@cache, cache2)
- @indirection.cache_class = :cache_terminus
- @indirection.cache.should equal(@cache)
- @indirection.clear_cache
- @indirection.cache.should equal(cache2)
- end
end
describe "and saving" do
@@ -725,7 +708,6 @@ describe Puppet::Indirector::Indirection do
after :each do
@indirection.delete
- Puppet::Indirector::Indirection.clear_cache
end
end
end
diff --git a/spec/unit/network/http_pool.rb b/spec/unit/network/http_pool.rb
index 04601769e..dd8bed54c 100755
--- a/spec/unit/network/http_pool.rb
+++ b/spec/unit/network/http_pool.rb
@@ -8,6 +8,7 @@ require 'puppet/network/http_pool'
describe Puppet::Network::HttpPool do
after do
+ Puppet::Util::Cacher.invalidate
Puppet::Network::HttpPool.clear_http_instances
Puppet::Network::HttpPool.instance_variable_set("@ssl_host", nil)
end
@@ -147,24 +148,6 @@ describe Puppet::Network::HttpPool do
end
end
- # We mostly have to do this for testing, since in real life people
- # won't change certs within a single process.
- it "should remove its loaded certificate when clearing the cache" do
- Puppet::Network::HttpPool.instance_variable_set("@cert", :yay)
- Puppet::Network::HttpPool.clear_http_instances
- # Can't use the accessor, because it will read the cert in
- Puppet::Network::HttpPool.instance_variable_get("@cert").should be_nil
- end
-
- # We mostly have to do this for testing, since in real life people
- # won't change certs within a single process.
- it "should remove its loaded key when clearing the cache" do
- Puppet::Network::HttpPool.instance_variable_set("@key", :yay)
- Puppet::Network::HttpPool.clear_http_instances
- # Can't use the accessor, because it will read the cert in
- Puppet::Network::HttpPool.instance_variable_get("@key").should be_nil
- end
-
after do
Puppet::Network::HttpPool.clear_http_instances
end
diff --git a/spec/unit/node.rb b/spec/unit/node.rb
index 348e160cf..08afc5183 100755
--- a/spec/unit/node.rb
+++ b/spec/unit/node.rb
@@ -148,7 +148,7 @@ describe Puppet::Node, " when indirecting" do
end
after do
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb
index f397b8706..59c70b45e 100755
--- a/spec/unit/node/catalog.rb
+++ b/spec/unit/node/catalog.rb
@@ -797,7 +797,7 @@ describe Puppet::Node::Catalog, " when indirecting" do
before do
@indirection = stub 'indirection', :name => :catalog
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
it "should redirect to the indirection for retrieval" do
@@ -811,8 +811,7 @@ describe Puppet::Node::Catalog, " when indirecting" do
end
after do
- mocha_verify
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
diff --git a/spec/unit/node/facts.rb b/spec/unit/node/facts.rb
index 1bfccd32e..69b8e4483 100755
--- a/spec/unit/node/facts.rb
+++ b/spec/unit/node/facts.rb
@@ -10,7 +10,8 @@ describe Puppet::Node::Facts, " when indirecting" do
# We have to clear the cache so that the facts ask for our indirection stub,
# instead of anything that might be cached.
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
+
@facts = Puppet::Node::Facts.new("me", "one" => "two")
end
@@ -29,11 +30,6 @@ describe Puppet::Node::Facts, " when indirecting" do
it "should default to the 'facter' terminus" do
Puppet::Node::Facts.indirection.terminus_class.should == :facter
end
-
- after do
- mocha_verify
- Puppet::Indirector::Indirection.clear_cache
- end
end
describe Puppet::Node::Facts, " when storing and retrieving" do
diff --git a/spec/unit/transaction/report.rb b/spec/unit/transaction/report.rb
index 644f8d709..8d49b16a0 100755
--- a/spec/unit/transaction/report.rb
+++ b/spec/unit/transaction/report.rb
@@ -35,6 +35,6 @@ describe Puppet::Transaction::Report, " when being indirect" do
end
after do
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
diff --git a/spec/unit/util/cacher.rb b/spec/unit/util/cacher.rb
index 954de380d..73e449588 100755
--- a/spec/unit/util/cacher.rb
+++ b/spec/unit/util/cacher.rb
@@ -10,7 +10,7 @@ class CacheClassTest
cached_attr(:testing) { Time.now }
def sa_cache
- cache(:ca_cache) { Time.now }
+ attr_cache(:ca_cache) { Time.now }
end
end
@@ -18,7 +18,7 @@ class CacheInstanceTest
extend Puppet::Util::Cacher
def self.sa_cache
- cache(:ca_cache) { Time.now }
+ attr_cache(:ca_cache) { Time.now }
end
end
@@ -29,6 +29,14 @@ describe "a cacher user using cached values", :shared => true do
@object.sa_cache.should equal(now)
end
+ it "should not test for validity if it is creating the value" do
+ # This is only necessary in the class, since it has this value kicking
+ # around.
+ @object.instance_variable_set("@cacher_caches", nil)
+ Puppet::Util::Cacher.expects(:valid?).never
+ @object.sa_cache
+ end
+
it "should not consider cached false values to be missing values" do
Puppet::Util::Cacher.stubs(:valid?).returns true
@@ -51,6 +59,14 @@ describe "a cacher user using cached values", :shared => true do
@object.sa_cache.should_not equal(@object.sa_cache)
end
+
+ it "should still cache values after an invalidation" do
+ # Load the cache
+ @object.sa_cache
+
+ Puppet::Util::Cacher.invalidate
+ @object.sa_cache.should equal(@object.sa_cache)
+ end
end
describe Puppet::Util::Cacher do
@@ -123,7 +139,7 @@ describe Puppet::Util::Cacher do
end
it "should provide a private instance method for caching values" do
- @object.private_methods.should be_include("cache")
+ @object.private_methods.should be_include("attr_cache")
end
end
@@ -134,7 +150,7 @@ describe Puppet::Util::Cacher do
end
it "should provide a private instance method for caching values" do
- CacheInstanceTest.private_methods.should be_include("cache")
+ CacheInstanceTest.private_methods.should be_include("attr_cache")
end
it_should_behave_like "a cacher user using cached values"