diff options
author | Luke Kanies <luke@madstop.com> | 2008-04-10 14:44:14 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-04-10 14:44:14 -0500 |
commit | 738889ba027b894867209d5175c716f9a2cc54c6 (patch) | |
tree | 77e46799379d1d5654b24b0dfefdcaff2482491d /spec | |
parent | f285f1aab525a2585532fda0b15b7fd28e994491 (diff) | |
download | puppet-738889ba027b894867209d5175c716f9a2cc54c6.tar.gz puppet-738889ba027b894867209d5175c716f9a2cc54c6.tar.xz puppet-738889ba027b894867209d5175c716f9a2cc54c6.zip |
Fixing the expire method (it wasn't using a request
internally), and fixing the Facts class so it
auto-expires any associated cached nodes when facts
are saved.
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/integration/node/facts.rb | 9 | ||||
-rwxr-xr-x | spec/unit/indirector/indirection.rb | 38 |
2 files changed, 38 insertions, 9 deletions
diff --git a/spec/integration/node/facts.rb b/spec/integration/node/facts.rb index d065918be..c2f876578 100755 --- a/spec/integration/node/facts.rb +++ b/spec/integration/node/facts.rb @@ -10,7 +10,14 @@ describe Puppet::Node::Facts do after { Puppet::Node::Facts.indirection.clear_cache } it "should expire any cached node instances when it is saved" do - raise "This test fails" + Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml + terminus = Puppet::Node::Facts.indirection.terminus(:yaml) + + terminus.expects(:save) + Puppet::Node.expects(:expire).with("me") + + facts = Puppet::Node::Facts.new("me") + facts.save end it "should be able to delegate to the :yaml terminus" do diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb index 06d9fcb6d..e8ab9633b 100755 --- a/spec/unit/indirector/indirection.rb +++ b/spec/unit/indirector/indirection.rb @@ -437,6 +437,13 @@ describe Puppet::Indirector::Indirection do @cache_class.expects(:new).returns(@cache) @instance.stubs(:expired?).returns false + + @cached = stub 'cached', :expiration= => nil, :name => "/my/key" + end + + it "should use a request to find within the cache" do + @cache.expects(:find).with { |r| r.is_a?(Puppet::Indirector::Request) and r.method == :find } + @indirection.expire("/my/key") end it "should do nothing if no such instance is cached" do @@ -445,25 +452,40 @@ describe Puppet::Indirector::Indirection do @indirection.expire("/my/key") end - it "should set the cached instance's expiration to a time in the past" do - cached = mock 'cached' + it "should log that it is expiring any found instance" do + @cache.expects(:find).returns @cached + @cache.stubs(:save) + + Puppet.expects(:info) + + @indirection.expire("/my/key") + end - @cache.expects(:find).returns cached + it "should set the cached instance's expiration to a time in the past" do + @cache.expects(:find).returns @cached @cache.stubs(:save) - cached.expects(:expiration=).with { |t| t < Time.now } + @cached.expects(:expiration=).with { |t| t < Time.now } @indirection.expire("/my/key") end it "should save the now expired instance back into the cache" do - cached = stub 'cached', :expiration= => nil + @cache.expects(:find).returns @cached + + @cached.expects(:expiration=).with { |t| t < Time.now } + + @cache.expects(:save) + + @indirection.expire("/my/key") + end - @cache.expects(:find).returns cached + it "should use a request to save the expired resource to the cache" do + @cache.expects(:find).returns @cached - cached.expects(:expiration=).with { |t| t < Time.now } + @cached.expects(:expiration=).with { |t| t < Time.now } - @cache.expects(:save).with(cached) + @cache.expects(:save).with { |r| r.is_a?(Puppet::Indirector::Request) and r.instance == @cached and r.method == :save }.returns(@cached) @indirection.expire("/my/key") end |