summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2008-02-18 11:54:13 -0600
committerRick Bradley <rick@rickbradley.com>2008-02-18 11:54:13 -0600
commitb4c8f996f13856ac74830fa41e4137b80e674f30 (patch)
tree4cd159714d604f19f7a163f76c08ed31151fc4cc /spec/unit
parent3cb11185168458a34adb9a8cf23bc6b7088644f8 (diff)
downloadpuppet-b4c8f996f13856ac74830fa41e4137b80e674f30.tar.gz
puppet-b4c8f996f13856ac74830fa41e4137b80e674f30.tar.xz
puppet-b4c8f996f13856ac74830fa41e4137b80e674f30.zip
converting indirector ldap node specs from setup/teardown to before/after
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/indirector/node/ldap.rb222
1 files changed, 110 insertions, 112 deletions
diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb
index 8c6888357..95b73de60 100755
--- a/spec/unit/indirector/node/ldap.rb
+++ b/spec/unit/indirector/node/ldap.rb
@@ -4,8 +4,8 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/indirector/node/ldap'
-module LdapNodeSearching
- def setup
+describe Puppet::Node::Ldap do
+ before :each do
@searcher = Puppet::Node::Ldap.new
@entries = {}
entries = @entries
@@ -24,148 +24,146 @@ module LdapNodeSearching
@name = "mynode"
Puppet::Node.stubs(:new).with(@name).returns(@node)
end
-end
-describe Puppet::Node::Ldap, " when searching for nodes" do
- include LdapNodeSearching
+ describe Puppet::Node::Ldap, " when searching for nodes" do
- it "should return nil if no results are found in ldap" do
- @connection.stubs(:search)
- @searcher.find("mynode").should be_nil
- end
+ it "should return nil if no results are found in ldap" do
+ @connection.stubs(:search)
+ @searcher.find("mynode").should be_nil
+ end
- it "should return a node object if results are found in ldap" do
- @entry.stubs(:to_hash).returns({})
- @searcher.find("mynode").should equal(@node)
- end
+ it "should return a node object if results are found in ldap" do
+ @entry.stubs(:to_hash).returns({})
+ @searcher.find("mynode").should equal(@node)
+ end
- it "should deduplicate class values" do
- @entry.stubs(:to_hash).returns({})
- @searcher.stubs(:class_attributes).returns(%w{one two})
- @entry.stubs(:vals).with("one").returns(%w{a b})
- @entry.stubs(:vals).with("two").returns(%w{b c})
- @node.expects(:classes=).with(%w{a b c})
- @searcher.find("mynode")
- end
+ it "should deduplicate class values" do
+ @entry.stubs(:to_hash).returns({})
+ @searcher.stubs(:class_attributes).returns(%w{one two})
+ @entry.stubs(:vals).with("one").returns(%w{a b})
+ @entry.stubs(:vals).with("two").returns(%w{b c})
+ @node.expects(:classes=).with(%w{a b c})
+ @searcher.find("mynode")
+ end
- it "should add any values stored in the class_attributes attributes to the node classes" do
- @entry.stubs(:to_hash).returns({})
- @searcher.stubs(:class_attributes).returns(%w{one two})
- @entry.stubs(:vals).with("one").returns(%w{a b})
- @entry.stubs(:vals).with("two").returns(%w{c d})
- @node.expects(:classes=).with(%w{a b c d})
- @searcher.find("mynode")
- end
+ it "should add any values stored in the class_attributes attributes to the node classes" do
+ @entry.stubs(:to_hash).returns({})
+ @searcher.stubs(:class_attributes).returns(%w{one two})
+ @entry.stubs(:vals).with("one").returns(%w{a b})
+ @entry.stubs(:vals).with("two").returns(%w{c d})
+ @node.expects(:classes=).with(%w{a b c d})
+ @searcher.find("mynode")
+ end
- it "should add all entry attributes as node parameters" do
- @entry.stubs(:to_hash).returns("one" => ["two"], "three" => ["four"])
- @node.expects(:parameters=).with("one" => "two", "three" => "four")
- @searcher.find("mynode")
- end
+ it "should add all entry attributes as node parameters" do
+ @entry.stubs(:to_hash).returns("one" => ["two"], "three" => ["four"])
+ @node.expects(:parameters=).with("one" => "two", "three" => "four")
+ @searcher.find("mynode")
+ end
- it "should retain false parameter values" do
- @entry.stubs(:to_hash).returns("one" => [false])
- @node.expects(:parameters=).with("one" => false)
- @searcher.find("mynode")
- end
+ it "should retain false parameter values" do
+ @entry.stubs(:to_hash).returns("one" => [false])
+ @node.expects(:parameters=).with("one" => false)
+ @searcher.find("mynode")
+ end
- it "should turn single-value parameter value arrays into single non-arrays" do
- @entry.stubs(:to_hash).returns("one" => ["a"])
- @node.expects(:parameters=).with("one" => "a")
- @searcher.find("mynode")
- end
+ it "should turn single-value parameter value arrays into single non-arrays" do
+ @entry.stubs(:to_hash).returns("one" => ["a"])
+ @node.expects(:parameters=).with("one" => "a")
+ @searcher.find("mynode")
+ end
- it "should keep multi-valued parametes as arrays" do
- @entry.stubs(:to_hash).returns("one" => ["a", "b"])
- @node.expects(:parameters=).with("one" => ["a", "b"])
- @searcher.find("mynode")
+ it "should keep multi-valued parametes as arrays" do
+ @entry.stubs(:to_hash).returns("one" => ["a", "b"])
+ @node.expects(:parameters=).with("one" => ["a", "b"])
+ @searcher.find("mynode")
+ end
end
-end
-describe Puppet::Node::Ldap, " when a parent node is specified" do
- include LdapNodeSearching
+ describe Puppet::Node::Ldap, " when a parent node is specified" do
- before do
- @parent = mock 'parent'
- @parent_parent = mock 'parent_parent'
+ before do
+ @parent = mock 'parent'
+ @parent_parent = mock 'parent_parent'
- @searcher.meta_def(:search_filter) do |name|
- return name
- end
- @connection.stubs(:search).with { |*args| args[2] == @name }.yields(@entry)
- @connection.stubs(:search).with { |*args| args[2] == 'parent' }.yields(@parent)
- @connection.stubs(:search).with { |*args| args[2] == 'parent_parent' }.yields(@parent_parent)
+ @searcher.meta_def(:search_filter) do |name|
+ return name
+ end
+ @connection.stubs(:search).with { |*args| args[2] == @name }.yields(@entry)
+ @connection.stubs(:search).with { |*args| args[2] == 'parent' }.yields(@parent)
+ @connection.stubs(:search).with { |*args| args[2] == 'parent_parent' }.yields(@parent_parent)
- @searcher.stubs(:parent_attribute).returns(:parent)
- end
+ @searcher.stubs(:parent_attribute).returns(:parent)
+ end
- it "should fail if the parent cannot be found" do
- @connection.stubs(:search).with { |*args| args[2] == 'parent' }.returns("whatever")
+ it "should fail if the parent cannot be found" do
+ @connection.stubs(:search).with { |*args| args[2] == 'parent' }.returns("whatever")
- @entry.stubs(:to_hash).returns({})
- @entry.stubs(:vals).with(:parent).returns(%w{parent})
+ @entry.stubs(:to_hash).returns({})
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
- proc { @searcher.find("mynode") }.should raise_error(Puppet::Error)
- end
+ proc { @searcher.find("mynode") }.should raise_error(Puppet::Error)
+ end
- it "should add any parent classes to the node's classes" do
- @entry.stubs(:to_hash).returns({})
- @entry.stubs(:vals).with(:parent).returns(%w{parent})
- @entry.stubs(:vals).with("classes").returns(%w{a b})
+ it "should add any parent classes to the node's classes" do
+ @entry.stubs(:to_hash).returns({})
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
+ @entry.stubs(:vals).with("classes").returns(%w{a b})
- @parent.stubs(:to_hash).returns({})
- @parent.stubs(:vals).with("classes").returns(%w{c d})
- @parent.stubs(:vals).with(:parent).returns(nil)
+ @parent.stubs(:to_hash).returns({})
+ @parent.stubs(:vals).with("classes").returns(%w{c d})
+ @parent.stubs(:vals).with(:parent).returns(nil)
- @searcher.stubs(:class_attributes).returns(%w{classes})
- @node.expects(:classes=).with(%w{a b c d})
- @searcher.find("mynode")
- end
+ @searcher.stubs(:class_attributes).returns(%w{classes})
+ @node.expects(:classes=).with(%w{a b c d})
+ @searcher.find("mynode")
+ end
- it "should add any parent parameters to the node's parameters" do
- @entry.stubs(:to_hash).returns("one" => "two")
- @entry.stubs(:vals).with(:parent).returns(%w{parent})
+ it "should add any parent parameters to the node's parameters" do
+ @entry.stubs(:to_hash).returns("one" => "two")
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
- @parent.stubs(:to_hash).returns("three" => "four")
- @parent.stubs(:vals).with(:parent).returns(nil)
+ @parent.stubs(:to_hash).returns("three" => "four")
+ @parent.stubs(:vals).with(:parent).returns(nil)
- @node.expects(:parameters=).with("one" => "two", "three" => "four")
- @searcher.find("mynode")
- end
+ @node.expects(:parameters=).with("one" => "two", "three" => "four")
+ @searcher.find("mynode")
+ end
- it "should prefer node parameters over parent parameters" do
- @entry.stubs(:to_hash).returns("one" => "two")
- @entry.stubs(:vals).with(:parent).returns(%w{parent})
+ it "should prefer node parameters over parent parameters" do
+ @entry.stubs(:to_hash).returns("one" => "two")
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
- @parent.stubs(:to_hash).returns("one" => "three")
- @parent.stubs(:vals).with(:parent).returns(nil)
+ @parent.stubs(:to_hash).returns("one" => "three")
+ @parent.stubs(:vals).with(:parent).returns(nil)
- @node.expects(:parameters=).with("one" => "two")
- @searcher.find("mynode")
- end
+ @node.expects(:parameters=).with("one" => "two")
+ @searcher.find("mynode")
+ end
- it "should recursively look up parent information" do
- @entry.stubs(:to_hash).returns("one" => "two")
- @entry.stubs(:vals).with(:parent).returns(%w{parent})
+ it "should recursively look up parent information" do
+ @entry.stubs(:to_hash).returns("one" => "two")
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
- @parent.stubs(:to_hash).returns("three" => "four")
- @parent.stubs(:vals).with(:parent).returns(['parent_parent'])
+ @parent.stubs(:to_hash).returns("three" => "four")
+ @parent.stubs(:vals).with(:parent).returns(['parent_parent'])
- @parent_parent.stubs(:to_hash).returns("five" => "six")
- @parent_parent.stubs(:vals).with(:parent).returns(nil)
- @parent_parent.stubs(:vals).with(:parent).returns(nil)
+ @parent_parent.stubs(:to_hash).returns("five" => "six")
+ @parent_parent.stubs(:vals).with(:parent).returns(nil)
+ @parent_parent.stubs(:vals).with(:parent).returns(nil)
- @node.expects(:parameters=).with("one" => "two", "three" => "four", "five" => "six")
- @searcher.find("mynode")
- end
+ @node.expects(:parameters=).with("one" => "two", "three" => "four", "five" => "six")
+ @searcher.find("mynode")
+ end
- it "should not allow loops in parent declarations" do
- @entry.stubs(:to_hash).returns("one" => "two")
- @entry.stubs(:vals).with(:parent).returns(%w{parent})
+ it "should not allow loops in parent declarations" do
+ @entry.stubs(:to_hash).returns("one" => "two")
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
- @parent.stubs(:to_hash).returns("three" => "four")
- @parent.stubs(:vals).with(:parent).returns([@name])
- proc { @searcher.find("mynode") }.should raise_error(ArgumentError)
+ @parent.stubs(:to_hash).returns("three" => "four")
+ @parent.stubs(:vals).with(:parent).returns([@name])
+ proc { @searcher.find("mynode") }.should raise_error(ArgumentError)
+ end
end
end