Skip to content

Commit

Permalink
[#3409] fix test failures from ldap environment patch
Browse files Browse the repository at this point in the history
  • Loading branch information
jes5199 authored and test branch committed Feb 17, 2010
1 parent a7884b4 commit e6709da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/indirector/node/ldap.rb
Expand Up @@ -207,7 +207,7 @@ def find_and_merge_parent(parent, information)
if information[:environment]
name_env = information[:environment]
else
name_env = production
name_env = 'production'
end

parent_info = name2hash(parent,name_env,'parent')
Expand Down
38 changes: 18 additions & 20 deletions spec/unit/indirector/node/ldap.rb
Expand Up @@ -23,16 +23,17 @@
end

it "should convert the hostname into a search filter" do
entry = stub 'entry', :dn => 'cn=mynode.domain.com,ou=hosts,dc=madstop,dc=com', :vals => %w{}, :to_hash => {}
entry = stub 'entry', :dn => 'cn=mynode.domain.com,ou=hosts,dc=madstop,dc=com', :vals => %w{}, :to_hash => {"environment" => 'production'}
@searcher.expects(:ldapsearch).with("(&(objectclass=puppetClient)(cn=#{@name}))").yields entry
@searcher.name2hash(@name)
@searcher.name2hash(@name, 'production', 'parent')
end

it "should convert any found entry into a hash" do
entry = stub 'entry', :dn => 'cn=mynode.domain.com,ou=hosts,dc=madstop,dc=com', :vals => %w{}, :to_hash => {}
entry = stub 'entry', :dn => 'cn=mynode.domain.com,ou=hosts,dc=madstop,dc=com', :vals => %w{}, :to_hash => {"environment" => 'production'}
@searcher.expects(:ldapsearch).with("(&(objectclass=puppetClient)(cn=#{@name}))").yields entry
@searcher.expects(:entry2hash).with(entry).returns "myhash"
@searcher.name2hash(@name).should == "myhash"
myhash = {"myhash" => true, :environment => 'production'}
@searcher.expects(:entry2hash).with(entry).returns myhash
@searcher.name2hash(@name, 'production', 'parent').should == myhash
end

# This heavily tests our entry2hash method, so we don't have to stub out the stupid entry information any more.
Expand Down Expand Up @@ -127,20 +128,20 @@
end

it "should search first for the provided key" do
@searcher.expects(:name2hash).with("mynode.domain.com").returns({})
@searcher.expects(:name2hash).with("mynode.domain.com", 'production', 'child').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(:name2hash).with("mynode.domain.com").returns(nil)
@searcher.expects(:name2hash).with("mynode").returns({})
@searcher.expects(:name2hash).with("mynode.domain.com", 'production', 'child').returns(nil)
@searcher.expects(:name2hash).with("mynode", 'production', 'child').returns({})
@searcher.find(@request)
end

it "should search for default information if no information can be found for the key" do
@searcher.expects(:name2hash).with("mynode.domain.com").returns(nil)
@searcher.expects(:name2hash).with("mynode").returns(nil)
@searcher.expects(:name2hash).with("default").returns({})
@searcher.expects(:name2hash).with("mynode.domain.com", 'production', 'child').returns(nil)
@searcher.expects(:name2hash).with("mynode", 'production', 'child').returns(nil)
@searcher.expects(:name2hash).with("default", 'production', 'child').returns({})
@searcher.find(@request)
end

Expand All @@ -161,8 +162,8 @@
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
@searcher.expects(:name2hash).with("mynode.domain.com", 'production', 'child').returns nil
@searcher.expects(:name2hash).with("mynode", 'production', 'child').returns @result

Puppet::Node.expects(:new).with("mynode.domain.com").returns @node
@searcher.find(@request)
Expand Down Expand Up @@ -212,26 +213,23 @@
@parent = {:classes => [], :parameters => {}}
@parent_parent = {:classes => [], :parameters => {}}

@searcher.stubs(:name2hash).with(@name).returns(@entry)
@searcher.stubs(:name2hash).with('parent').returns(@parent)
@searcher.stubs(:name2hash).with('parent_parent').returns(@parent_parent)
@searcher.stubs(:name2hash).with{|name, env, mode| name == @name}.returns(@entry)
@searcher.stubs(:name2hash).with{|name, env, mode| name == 'parent'}.returns(@parent)
@searcher.stubs(:name2hash).with{|name, env, mode| name == 'parent_parent'}.returns(@parent_parent)

@searcher.stubs(:parent_attribute).returns(:parent)
end

it "should search for the parent node" do
@entry[:parent] = "parent"

@searcher.expects(:name2hash).with(@name).returns @entry
@searcher.expects(:name2hash).with('parent').returns @parent

@searcher.find(@request)
end

it "should fail if the parent cannot be found" do
@entry[:parent] = "parent"

@searcher.expects(:name2hash).with('parent').returns nil
@searcher.expects(:name2hash).with('parent', 'production', 'parent').returns nil

proc { @searcher.find(@request) }.should raise_error(Puppet::Error)
end
Expand Down

0 comments on commit e6709da

Please sign in to comment.