summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2008-08-01 07:11:21 +1000
committerJames Turnbull <james@lovedthanlost.net>2008-08-01 07:11:56 +1000
commit2a3d195402900aa31843f7a7ff78026409cf43f5 (patch)
tree45950228cc66859dc858dc50b8dea80816781fb0 /spec
parentc97389d5f6748c05b88f6461b87b4d21a273ab00 (diff)
downloadpuppet-2a3d195402900aa31843f7a7ff78026409cf43f5.tar.gz
puppet-2a3d195402900aa31843f7a7ff78026409cf43f5.tar.xz
puppet-2a3d195402900aa31843f7a7ff78026409cf43f5.zip
Specs for yaml indirector .search - I'm still learning!
Updated, I was calling .base myself instead of the actual string
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/indirector/yaml.rb29
1 files changed, 29 insertions, 0 deletions
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