summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-08-18 11:47:40 -0500
committerLuke Kanies <luke@madstop.com>2008-08-18 11:47:40 -0500
commite3971b9751141cd448a8197da024be43581f6dcd (patch)
tree3ae780db3d9dae0a4df10ec24f928bf3a844e749 /spec/unit/indirector
parent025edc5c3737f476119df4bab73ebdc68be19430 (diff)
parent2ec4e298c3274abc8eaad4230bca8d39a48d2e35 (diff)
downloadpuppet-e3971b9751141cd448a8197da024be43581f6dcd.tar.gz
puppet-e3971b9751141cd448a8197da024be43581f6dcd.tar.xz
puppet-e3971b9751141cd448a8197da024be43581f6dcd.zip
Merge branch '0.24.x'
Conflicts: CHANGELOG test/util/posixtest.rb
Diffstat (limited to 'spec/unit/indirector')
-rwxr-xr-xspec/unit/indirector/ldap.rb16
-rwxr-xr-xspec/unit/indirector/yaml.rb29
2 files changed, 42 insertions, 3 deletions
diff --git a/spec/unit/indirector/ldap.rb b/spec/unit/indirector/ldap.rb
index 52abd413a..2c4060c4d 100755
--- a/spec/unit/indirector/ldap.rb
+++ b/spec/unit/indirector/ldap.rb
@@ -113,15 +113,25 @@ describe Puppet::Indirector::Ldap do
describe "when connecting to ldap" do
confine "LDAP is not available" => Puppet.features.ldap?
+ it "should create and start a Util::Ldap::Connection instance" do
+ conn = mock 'connection', :connection => "myconn", :start => nil
+ Puppet::Util::Ldap::Connection.expects(:instance).returns conn
+
+ @searcher.connection.should == "myconn"
+ end
+
it "should only create the ldap connection when asked for it the first time" do
- @searcher.connection.should equal(@searcher.connection)
+ conn = mock 'connection', :connection => "myconn", :start => nil
+ Puppet::Util::Ldap::Connection.expects(:instance).returns conn
+
+ @searcher.connection
end
- it "should create and start a Util::Ldap::Connection instance" do
+ it "should cache the connection" do
conn = mock 'connection', :connection => "myconn", :start => nil
Puppet::Util::Ldap::Connection.expects(:instance).returns conn
- @searcher.connection.should == "myconn"
+ @searcher.connection.should equal(@searcher.connection)
end
end
diff --git a/spec/unit/indirector/yaml.rb b/spec/unit/indirector/yaml.rb
index 3875d70aa..081ae9666 100755
--- a/spec/unit/indirector/yaml.rb
+++ b/spec/unit/indirector/yaml.rb
@@ -106,4 +106,33 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do
proc { @store.find(@request) }.should raise_error(Puppet::Error)
end
end
+
+ describe Puppet::Indirector::Yaml, " when searching" do
+ it "should return an array of fact instances with one instance for each file when globbing *" do
+ @request = stub 'request', :key => "*", :instance => @subject
+ @one = mock 'one'
+ @two = mock 'two'
+ @store.expects(:base).returns "/my/yaml/dir"
+ Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns(%w{one.yaml two.yaml})
+ YAML.expects(:load_file).with("one.yaml").returns @one;
+ YAML.expects(:load_file).with("two.yaml").returns @two;
+ @store.search(@request).should == [@one, @two]
+ end
+
+ it "should return an array containing a single instance of fact when globbing 'one*'" do
+ @request = stub 'request', :key => "one*", :instance => @subject
+ @one = mock 'one'
+ @store.expects(:base).returns "/my/yaml/dir"
+ Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns(%w{one.yaml})
+ YAML.expects(:load_file).with("one.yaml").returns @one;
+ @store.search(@request).should == [@one]
+ end
+
+ it "should return an empty array when the glob doesn't match anything" do
+ @request = stub 'request', :key => "f*ilglobcanfail*", :instance => @subject
+ @store.expects(:base).returns "/my/yaml/dir"
+ Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns([])
+ @store.search(@request).should == []
+ end
+ end
end