diff options
| author | Luke Kanies <luke@madstop.com> | 2008-06-15 20:21:51 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-06-15 20:21:51 -0500 |
| commit | 6b69a86e48be082a6d03ce69f2700c4c874e222f (patch) | |
| tree | f80f431aac5ada885d7b8d084b31a4cfe5cc70a0 /spec/unit | |
| parent | c542dc065fd618ae85bb6e8960d8819f42aefaeb (diff) | |
| parent | d3a4d9ad72ae12199163864582bfbb0f30a7f271 (diff) | |
| download | puppet-6b69a86e48be082a6d03ce69f2700c4c874e222f.tar.gz puppet-6b69a86e48be082a6d03ce69f2700c4c874e222f.tar.xz puppet-6b69a86e48be082a6d03ce69f2700c4c874e222f.zip | |
Merge branch '0.24.x'
Conflicts:
CHANGELOG
Finally adding release names to the changelog so we can keep the changes aligned in the right part of the log.
Diffstat (limited to 'spec/unit')
| -rwxr-xr-x | spec/unit/indirector/catalog/compiler.rb | 22 | ||||
| -rwxr-xr-x | spec/unit/indirector/node/exec.rb | 6 | ||||
| -rwxr-xr-x | spec/unit/indirector/node/ldap.rb | 22 | ||||
| -rwxr-xr-x | spec/unit/node.rb | 76 |
4 files changed, 45 insertions, 81 deletions
diff --git a/spec/unit/indirector/catalog/compiler.rb b/spec/unit/indirector/catalog/compiler.rb index 083a9ced5..cf7186a5a 100755 --- a/spec/unit/indirector/catalog/compiler.rb +++ b/spec/unit/indirector/catalog/compiler.rb @@ -23,8 +23,8 @@ describe Puppet::Node::Catalog::Compiler do node1 = stub 'node1', :merge => nil node2 = stub 'node2', :merge => nil compiler.stubs(:compile) - Puppet::Node.stubs(:find_by_any_name).with('node1').returns(node1) - Puppet::Node.stubs(:find_by_any_name).with('node2').returns(node2) + Puppet::Node.stubs(:find).with('node1').returns(node1) + Puppet::Node.stubs(:find).with('node2').returns(node2) compiler.find(stub('request', :key => 'node1', :options => {})) compiler.find(stub('node2request', :key => 'node2', :options => {})) @@ -69,7 +69,7 @@ describe Puppet::Node::Catalog::Compiler, " when finding nodes" do it "should look node information up via the Node class with the provided key" do @node.stubs :merge - Puppet::Node.expects(:find_by_any_name).with(@name).returns(@node) + Puppet::Node.expects(:find).with(@name).returns(@node) @compiler.find(@request) end end @@ -77,7 +77,6 @@ end describe Puppet::Node::Catalog::Compiler, " after finding nodes" do before do Puppet.expects(:version).returns(1) - Puppet.settings.stubs(:value).with(:node_name).returns("cert") Facter.expects(:value).with('fqdn').returns("my.server.com") Facter.expects(:value).with('ipaddress').returns("my.ip.address") @compiler = Puppet::Node::Catalog::Compiler.new @@ -85,7 +84,7 @@ describe Puppet::Node::Catalog::Compiler, " after finding nodes" do @node = mock 'node' @request = stub 'request', :key => @name, :options => {} @compiler.stubs(:compile) - Puppet::Node.stubs(:find_by_any_name).with(@name).returns(@node) + Puppet::Node.stubs(:find).with(@name).returns(@node) end it "should add the server's Puppet version to the node's parameters as 'serverversion'" do @@ -102,13 +101,6 @@ describe Puppet::Node::Catalog::Compiler, " after finding nodes" do @node.expects(:merge).with { |args| args["serverip"] == "my.ip.address" } @compiler.find(@request) end - - # LAK:TODO This is going to be difficult, because this whole process is so - # far removed from the actual connection that the certificate information - # will be quite hard to come by, dum by, gum by. - it "should search for the name using the client certificate's DN if the :node_name setting is set to 'cert'" do - pending "Probably will end up in the REST work" - end end describe Puppet::Node::Catalog::Compiler, " when creating catalogs" do @@ -122,18 +114,18 @@ describe Puppet::Node::Catalog::Compiler, " when creating catalogs" do @node = Puppet::Node.new @name @node.stubs(:merge) @request = stub 'request', :key => @name, :options => {} - Puppet::Node.stubs(:find_by_any_name).with(@name).returns(@node) + Puppet::Node.stubs(:find).with(@name).returns(@node) end it "should directly use provided nodes" do - Puppet::Node.expects(:find_by_any_name).never + Puppet::Node.expects(:find).never @compiler.interpreter.expects(:compile).with(@node) @request.stubs(:options).returns(:node => @node) @compiler.find(@request) end it "should fail if no node is passed and none can be found" do - Puppet::Node.stubs(:find_by_any_name).with(@name).returns(nil) + Puppet::Node.stubs(:find).with(@name).returns(nil) proc { @compiler.find(@request) }.should raise_error(ArgumentError) end diff --git a/spec/unit/indirector/node/exec.rb b/spec/unit/indirector/node/exec.rb index 09f13ab90..2276e4298 100755 --- a/spec/unit/indirector/node/exec.rb +++ b/spec/unit/indirector/node/exec.rb @@ -49,6 +49,12 @@ describe Puppet::Node::Exec do @searcher.find(@request) end + it "should convert all parameters into strings" do + @result[:parameters] = {"a" => true, "c" => 100} + @node.expects(:parameters=).with "a" => "true", "c" => "100" + @searcher.find(@request) + end + it "should set the resulting classes as the node classes" do @result[:classes] = %w{one two} @node.expects(:classes=).with %w{one two} diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb index 878039c7c..24b2dd759 100755 --- a/spec/unit/indirector/node/ldap.rb +++ b/spec/unit/indirector/node/ldap.rb @@ -21,14 +21,32 @@ describe Puppet::Node::Ldap do @searcher.stubs(:search_base).returns(:yay) @searcher.stubs(:search_filter).returns(:filter) - @node = mock 'node' + @name = "mynode.domain.com" + @node = stub 'node', :name => @name @node.stubs(:fact_merge) - @name = "mynode" Puppet::Node.stubs(:new).with(@name).returns(@node) @request = stub 'request', :key => @name end + it "should search first for the provided key" do + @searcher.expects(:entry2hash).with("mynode.domain.com").returns({}) + @searcher.find(@request) + end + + it "should search for the short version of the provided key if the key looks like a hostname and no results are found for the key itself" do + @searcher.expects(:entry2hash).with("mynode.domain.com").returns(nil) + @searcher.expects(:entry2hash).with("mynode").returns({}) + @searcher.find(@request) + end + + it "should search for default information if no information can be found for the key" do + @searcher.expects(:entry2hash).with("mynode.domain.com").returns(nil) + @searcher.expects(:entry2hash).with("mynode").returns(nil) + @searcher.expects(:entry2hash).with("default").returns({}) + @searcher.find(@request) + end + it "should return nil if no results are found in ldap" do @connection.stubs(:search) @searcher.find(@request).should be_nil diff --git a/spec/unit/node.rb b/spec/unit/node.rb index 4a41dadf9..70aa8bd9a 100755 --- a/spec/unit/node.rb +++ b/spec/unit/node.rb @@ -54,11 +54,6 @@ describe Puppet::Node, "when initializing" do Puppet.settings.stubs(:value).with(:environments).returns("myenv") proc { Puppet::Node.new("testing", :environment => "other") }.should raise_error(ArgumentError) end - - it "should accept names passed in" do - @node = Puppet::Node.new("testing", :names => ["myenv"]) - @node.names.should == ["myenv"] - end end describe Puppet::Node, "when returning the environment" do @@ -152,42 +147,33 @@ describe Puppet::Node, "when indirecting" do end end -describe Puppet::Node do - # LAK:NOTE This is used to keep track of when a given node has connected, - # so we can report on nodes that do not appear to connecting to the - # central server. - it "should provide a method for noting that the node has connected" -end - describe Puppet::Node, "when generating the list of names to search through" do before do - @facts = Puppet::Node::Facts.new("foo", "hostname" => "yay", "domain" => "domain.com") - @node = Puppet::Node.new("foo") - - Puppet::Node.stubs(:node_facts).returns @facts.values + @node = Puppet::Node.new("foo.domain.com") + @node.parameters = {"hostname" => "yay", "domain" => "domain.com"} end it "should return an array of names" do - Puppet::Node.node_names("foo").should be_instance_of(Array) + @node.names.should be_instance_of(Array) end it "should have the node's fqdn as the second name" do - Puppet::Node.node_names("foo.domain.com")[1].should == "yay.domain.com" + @node.names[1].should == "yay.domain.com" end it "should set the fqdn to the node's 'fqdn' fact if it is available" do - @facts.values["fqdn"] = "boo.domain.com" - Puppet::Node.node_names("foo")[1].should == "boo.domain.com" + @node.parameters["fqdn"] = "boo.domain.com" + @node.names[1].should == "boo.domain.com" end it "should set the fqdn to the node's hostname and domain if no fqdn is available" do - Puppet::Node.node_names("foo")[1].should == "yay.domain.com" + @node.names[1].should == "yay.domain.com" end it "should contain an entry for each name available by stripping a segment of the fqdn" do - @facts.values["fqdn"] = "foo.deep.sub.domain.com" - Puppet::Node.node_names("foo")[2].should == "foo.deep.sub.domain" - Puppet::Node.node_names("foo")[3].should == "foo.deep.sub" + @node.parameters["fqdn"] = "foo.deep.sub.domain.com" + @node.names[2].should == "foo.deep.sub.domain" + @node.names[3].should == "foo.deep.sub" end describe "and :node_name is set to 'cert'" do @@ -196,7 +182,7 @@ describe Puppet::Node, "when generating the list of names to search through" do end it "should use the passed-in key as the first value" do - Puppet::Node.node_names("foo")[0].should == "foo" + @node.names[0].should == "foo.domain.com" end end @@ -206,45 +192,7 @@ describe Puppet::Node, "when generating the list of names to search through" do end it "should use the node's 'hostname' fact as the first value" do - Puppet::Node.node_names("foo")[0].should == "yay" + @node.names[0].should == "yay" end end end - -describe Puppet::Node, "when searching for nodes" do - before do - @facts = Puppet::Node::Facts.new("foo", "hostname" => "yay", "domain" => "domain.com") - @node = Puppet::Node.new("foo") - Puppet::Node::Facts.stubs(:find).with("foo").returns(@facts) - end - - it "should use the 'node_names' method to get its list of names to search" do - Puppet::Node.expects(:node_names).with{ |*args| args[0] == "foo" }.returns %w{a b} - Puppet::Node.stubs(:find) - Puppet::Node.find_by_any_name("foo") - end - - it "should return the first node found using the generated list of names" do - Puppet::Node.expects(:node_names).returns %w{a b} - Puppet::Node.expects(:find).with("a").returns(nil) - Puppet::Node.expects(:find).with("b").returns(@node) - Puppet::Node.find_by_any_name("foo").should equal(@node) - end - - it "should attempt to find a default node if no names are found" do - names = [] - Puppet::Node.stubs(:find).with do |name| - names << name - end.returns(nil) - Puppet::Node.find_by_any_name("foo") - names[-1].should == "default" - end - - it "should set the node name to the provided key" do - Puppet::Node.stubs(:node_names).returns %w{a b} - Puppet::Node.stubs(:find).returns @node - - @node.expects(:name=).with("foo") - Puppet::Node.find_by_any_name("foo") - end -end |
