diff options
| author | Rick Bradley <rick@rickbradley.com> | 2007-10-09 11:29:13 -0500 |
|---|---|---|
| committer | Rick Bradley <rick@rickbradley.com> | 2007-10-09 11:29:13 -0500 |
| commit | fdfe807bd986a2b27f0dfd0cecde1a33aeee309b (patch) | |
| tree | 0b6375bdefa041a7d4fbab9745ed084fb025bc30 /spec/unit/indirector/terminus.rb | |
| parent | 42b98562b5237797e1a51fdcdd57aa3c6825b404 (diff) | |
| parent | 01f132d8b88467dfd314ad355f1cdf9f546945b3 (diff) | |
| download | puppet-fdfe807bd986a2b27f0dfd0cecde1a33aeee309b.tar.gz puppet-fdfe807bd986a2b27f0dfd0cecde1a33aeee309b.tar.xz puppet-fdfe807bd986a2b27f0dfd0cecde1a33aeee309b.zip | |
Merge branch 'master' of git://reductivelabs.com/puppet into routing
Diffstat (limited to 'spec/unit/indirector/terminus.rb')
| -rwxr-xr-x | spec/unit/indirector/terminus.rb | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/spec/unit/indirector/terminus.rb b/spec/unit/indirector/terminus.rb index 44180cf4b..3361bfeeb 100755 --- a/spec/unit/indirector/terminus.rb +++ b/spec/unit/indirector/terminus.rb @@ -1,3 +1,5 @@ +#!/usr/bin/env ruby + require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/defaults' require 'puppet/indirector' @@ -200,8 +202,8 @@ describe Puppet::Indirector::Terminus, " when creating terminus classes" do end end -describe Puppet::Indirector::Terminus, " when a terminus instance" do - before do +module TerminusInstanceTesting + def setup Puppet::Indirector::Terminus.stubs(:register_terminus_class) @indirection = stub 'indirection', :name => :myyaml, :register_terminus_type => nil Puppet::Indirector::Indirection.stubs(:instance).with(:my_stuff).returns(@indirection) @@ -218,6 +220,10 @@ describe Puppet::Indirector::Terminus, " when a terminus instance" do @terminus_class.name = :test @terminus = @terminus_class.new end +end + +describe Puppet::Indirector::Terminus, " when a terminus instance" do + include TerminusInstanceTesting it "should return the class's name as its name" do @terminus.name.should == :test @@ -236,3 +242,58 @@ describe Puppet::Indirector::Terminus, " when a terminus instance" do @terminus.model.should == :yay end end + +describe Puppet::Indirector::Terminus, " when managing indirected instances" do + include TerminusInstanceTesting + + it "should support comparing an instance's version with the terminus's version using just the instance's key" do + @terminus.should respond_to(:has_most_recent?) + end + + it "should fail if the :version method has not been overridden and no :find method is available" do + proc { @terminus.version('yay') }.should raise_error(Puppet::DevError) + end + + it "should use a found instance's version by default" do + name = 'instance' + instance = stub name, :version => 2 + @terminus.expects(:find).with(name).returns(instance) + @terminus.version(name).should == 2 + end + + it "should return nil as the version if no instance can be found" do + name = 'instance' + @terminus.expects(:find).with(name).returns(nil) + @terminus.version(name).should be_nil + end + + it "should consider an instance fresh if its version is more recent than the version provided" do + name = "yay" + @terminus.expects(:version).with(name).returns(5) + @terminus.has_most_recent?(name, 4).should be_true + end + + it "should consider an instance fresh if its version is equal to the version provided" do + name = "yay" + @terminus.expects(:version).with(name).returns(5) + @terminus.has_most_recent?(name, 5).should be_true + end + + it "should consider an instance not fresh if the provided version is more recent than its version" do + name = "yay" + @terminus.expects(:version).with(name).returns(4) + @terminus.has_most_recent?(name, 5).should be_false + end + + # Times annoyingly can't be compared directly to numbers, and our + # default version is 0. + it "should convert versions to floats when checking for freshness" do + existing = mock 'existing version' + new = mock 'new version' + existing.expects(:to_f).returns(1.0) + new.expects(:to_f).returns(1.0) + name = "yay" + @terminus.expects(:version).with(name).returns(existing) + @terminus.has_most_recent?(name, new) + end +end |
