diff options
Diffstat (limited to 'spec/unit')
-rwxr-xr-x | spec/unit/indirector/node/exec.rb | 93 | ||||
-rwxr-xr-x | spec/unit/indirector/node/ldap.rb | 7 | ||||
-rwxr-xr-x | spec/unit/indirector/yaml.rb | 12 | ||||
-rwxr-xr-x | spec/unit/node.rb | 4 |
4 files changed, 71 insertions, 45 deletions
diff --git a/spec/unit/indirector/node/exec.rb b/spec/unit/indirector/node/exec.rb index 5e6a9b1da..b67e0fe97 100755 --- a/spec/unit/indirector/node/exec.rb +++ b/spec/unit/indirector/node/exec.rb @@ -4,65 +4,70 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/indirector/node/exec' -describe Puppet::Node::Exec, " when constructing the command to run" do +describe Puppet::Node::Exec do before do @indirection = mock 'indirection' Puppet.settings.stubs(:value).with(:external_nodes).returns("/echo") @searcher = Puppet::Node::Exec.new end - it "should use the external_node script as the command" do - Puppet.expects(:[]).with(:external_nodes).returns("/bin/echo") - @searcher.command.should == %w{/bin/echo} + it "should use the version of the facts as its version" do + version = mock 'version' + Puppet::Node::Facts.expects(:version).with("me").returns version + @searcher.version("me").should equal(version) end - it "should throw an exception if no external node command is set" do - Puppet.expects(:[]).with(:external_nodes).returns("none") - proc { @searcher.find("foo") }.should raise_error(ArgumentError) - end -end + describe "when constructing the command to run" do + it "should use the external_node script as the command" do + Puppet.expects(:[]).with(:external_nodes).returns("/bin/echo") + @searcher.command.should == %w{/bin/echo} + end -describe Puppet::Node::Exec, " when handling the results of the command" do - before do - @indirection = mock 'indirection' - Puppet.settings.stubs(:value).with(:external_nodes).returns("/echo") - @searcher = Puppet::Node::Exec.new - @node = stub 'node', :fact_merge => nil - @name = "yay" - Puppet::Node.expects(:new).with(@name).returns(@node) - @result = {} - # Use a local variable so the reference is usable in the execute() definition. - result = @result - @searcher.meta_def(:execute) do |command| - return YAML.dump(result) + it "should throw an exception if no external node command is set" do + Puppet.expects(:[]).with(:external_nodes).returns("none") + proc { @searcher.find("foo") }.should raise_error(ArgumentError) end end - it "should translate the YAML into a Node instance" do - # Use an empty hash - @searcher.find(@name).should equal(@node) - end + describe "when handling the results of the command" do + before do + @node = stub 'node', :fact_merge => nil + @name = "yay" + Puppet::Node.expects(:new).with(@name).returns(@node) + @result = {} + # Use a local variable so the reference is usable in the execute() definition. + result = @result + @searcher.meta_def(:execute) do |command| + return YAML.dump(result) + end + end - it "should set the resulting parameters as the node parameters" do - @result[:parameters] = {"a" => "b", "c" => "d"} - @node.expects(:parameters=).with "a" => "b", "c" => "d" - @searcher.find(@name) - end + it "should translate the YAML into a Node instance" do + # Use an empty hash + @searcher.find(@name).should equal(@node) + end - it "should set the resulting classes as the node classes" do - @result[:classes] = %w{one two} - @node.expects(:classes=).with %w{one two} - @searcher.find(@name) - end + it "should set the resulting parameters as the node parameters" do + @result[:parameters] = {"a" => "b", "c" => "d"} + @node.expects(:parameters=).with "a" => "b", "c" => "d" + @searcher.find(@name) + end - it "should merge the node's facts with its parameters" do - @node.expects(:fact_merge) - @searcher.find(@name) - end + it "should set the resulting classes as the node classes" do + @result[:classes] = %w{one two} + @node.expects(:classes=).with %w{one two} + @searcher.find(@name) + end + + it "should merge the node's facts with its parameters" do + @node.expects(:fact_merge) + @searcher.find(@name) + end - it "should set the node's environment if one is provided" do - @result[:environment] = "yay" - @node.expects(:environment=).with "yay" - @searcher.find(@name) + it "should set the node's environment if one is provided" do + @result[:environment] = "yay" + @node.expects(:environment=).with "yay" + @searcher.find(@name) + end end end diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb index 2a4f240ed..34456703d 100755 --- a/spec/unit/indirector/node/ldap.rb +++ b/spec/unit/indirector/node/ldap.rb @@ -5,6 +5,13 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/indirector/node/ldap' describe Puppet::Node::Ldap do + it "should use the version of the facts as its version" do + @searcher = Puppet::Node::Ldap.new + version = mock 'version' + Puppet::Node::Facts.expects(:version).with("me").returns version + @searcher.version("me").should equal(version) + end + describe "when searching for nodes" do before :each do @searcher = Puppet::Node::Ldap.new diff --git a/spec/unit/indirector/yaml.rb b/spec/unit/indirector/yaml.rb index 2e0b453d7..b61332485 100755 --- a/spec/unit/indirector/yaml.rb +++ b/spec/unit/indirector/yaml.rb @@ -24,6 +24,16 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do Puppet.settings.stubs(:value).with(:yamldir).returns(@dir) end + it "should use the mtime of the written file as the version" do + stat = mock 'stat' + FileTest.stubs(:exist?).returns true + File.expects(:stat).returns stat + time = Time.now + stat.expects(:mtime).returns time + + @store.version(:me).should equal(time) + end + describe Puppet::Indirector::Yaml, " when choosing file location" do it "should store all files in a single file root set in the Puppet defaults" do @@ -98,4 +108,4 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do proc { @store.find(@subject.name) }.should raise_error(Puppet::Error) end end -end
\ No newline at end of file +end diff --git a/spec/unit/node.rb b/spec/unit/node.rb index 0ce702936..4861cb9e3 100755 --- a/spec/unit/node.rb +++ b/spec/unit/node.rb @@ -127,6 +127,10 @@ describe Puppet::Node, " when indirecting" do Puppet::Node.indirection.terminus_class.should == :plain end + it "should use yaml for caching" do + Puppet::Node.indirection.cache_class.should == :yaml + end + after do Puppet::Indirector::Indirection.clear_cache end |