From c825c991fd68274ae1b172f97059be616d5b057e Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 2 Jul 2008 22:03:45 -0500 Subject: Fixing the ldap node terminus to merge facts with the right name. Previously, I was merging early and changing the name later. This commit fixes it so that the node is created with the right name in the first place, so the node.fact_merge actually works. Yay for real-world testing. Signed-off-by: Luke Kanies --- spec/unit/indirector/node/ldap.rb | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb index 01d148631..ed8809e73 100755 --- a/spec/unit/indirector/node/ldap.rb +++ b/spec/unit/indirector/node/ldap.rb @@ -136,6 +136,14 @@ describe Puppet::Node::Ldap do @searcher.stubs(:name2hash).returns @result end + it "should create the node with the correct name, even if it was found by a different name" do + @searcher.expects(:name2hash).with("mynode.domain.com").returns nil + @searcher.expects(:name2hash).with("mynode").returns @result + + Puppet::Node.expects(:new).with("mynode.domain.com").returns @node + @searcher.find(@request) + end + it "should add any classes from ldap" do @result[:classes] = %w[a b c d] @node.expects(:classes=).with(%w{a b c d}) @@ -161,6 +169,19 @@ describe Puppet::Node::Ldap do @searcher.find(@request) end + it "should merge the node's facts after the parameters from ldap are assigned" do + # Make sure we've got data to start with, so the parameters are actually set. + @result[:parameters] = {} + @result[:parameters]["one"] = "yay" + + # A hackish way to enforce order. + set = false + @node.expects(:parameters=).with { |*args| set = true } + @node.expects(:fact_merge).with { |*args| raise "Facts were merged before parameters were set" unless set; true } + + @searcher.find(@request) + end + describe "and a parent node is specified" do before do @entry = {:classes => [], :parameters => {}} @@ -304,13 +325,22 @@ describe Puppet::Node::Ldap do @searcher.search @request end - it "should return a node for each processed entry" do - @searcher.expects(:ldapsearch).yields("one") - @searcher.expects(:entry2hash).with("one").returns(:name => "foo") + it "should return a node for each processed entry with the name from the entry" do + @searcher.expects(:ldapsearch).yields("whatever") + @searcher.expects(:entry2hash).with("whatever").returns(:name => "foo") result = @searcher.search(@request) result[0].should be_instance_of(Puppet::Node) result[0].name.should == "foo" end + + it "should merge each node's facts" do + node = mock 'node' + Puppet::Node.expects(:new).with("foo").returns node + node.expects(:fact_merge) + @searcher.stubs(:ldapsearch).yields("one") + @searcher.stubs(:entry2hash).with("one").returns(:name => "foo") + @searcher.search(@request) + end end end -- cgit