diff options
| author | Markus Roberts <Markus@reality.com> | 2010-08-14 18:25:24 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-08-21 13:07:21 -0700 |
| commit | 82b4f04f6b8fee7ada275fc63e519a08e1c2b0a5 (patch) | |
| tree | 9c8aaad15269c36b612639901f0c7402a4e74294 | |
| parent | 0c3075443c80227c1e35cfb4952d3971c1c0adeb (diff) | |
| download | puppet-82b4f04f6b8fee7ada275fc63e519a08e1c2b0a5.tar.gz puppet-82b4f04f6b8fee7ada275fc63e519a08e1c2b0a5.tar.xz puppet-82b4f04f6b8fee7ada275fc63e519a08e1c2b0a5.zip | |
Maint. -- Fix test failures broken by previous commit
This basically involved adding a search method to the yaml indirector, which I
did by copying the one from ssl_file and fiddling with it until the tests
passed. Since the most straight forward way to do this required extending the
interface to the path method I added tests for the additional behaviour.
| -rw-r--r-- | lib/puppet/indirector/yaml.rb | 10 | ||||
| -rwxr-xr-x | spec/unit/indirector/yaml_spec.rb | 24 |
2 files changed, 26 insertions, 8 deletions
diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb index 13f3c1e79..23997e97a 100644 --- a/lib/puppet/indirector/yaml.rb +++ b/lib/puppet/indirector/yaml.rb @@ -42,9 +42,15 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus end # Return the path to a given node's file. - def path(name) + def path(name,ext='.yaml') base = Puppet.run_mode.master? ? Puppet[:yamldir] : Puppet[:clientyamldir] - File.join(base, self.class.indirection_name.to_s, name.to_s + ".yaml") + File.join(base, self.class.indirection_name.to_s, name.to_s + ext) + end + + def search(request) + Dir.glob(path(request.key,'')).collect do |file| + YAML.load_file(file) + end end private diff --git a/spec/unit/indirector/yaml_spec.rb b/spec/unit/indirector/yaml_spec.rb index 134d476ba..86c13c5a0 100755 --- a/spec/unit/indirector/yaml_spec.rb +++ b/spec/unit/indirector/yaml_spec.rb @@ -40,6 +40,18 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do @store.path(:me).should =~ %r{^/client/yaml/dir} end + it "should use the extension if one is specified" do + Puppet.run_mode.expects(:master?).returns true + Puppet.settings.expects(:value).with(:yamldir).returns "/server/yaml/dir" + @store.path(:me,'.farfignewton').should =~ %r{\.farfignewton$} + end + + it "should assume an extension of .yaml if none is specified" do + Puppet.run_mode.expects(:master?).returns true + Puppet.settings.expects(:value).with(:yamldir).returns "/server/yaml/dir" + @store.path(:me).should =~ %r{\.yaml$} + end + it "should store all files in a single file root set in the Puppet defaults" do @store.path(:me).should =~ %r{^#{@dir}} end @@ -120,8 +132,8 @@ describe Puppet::Indirector::Yaml, " when choosing file location" 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}) + @store.expects(:path).with(@request.key,'').returns :glob + Dir.expects(:glob).with(:glob).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] @@ -130,16 +142,16 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do 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}) + @store.expects(:path).with(@request.key,'').returns :glob + Dir.expects(:glob).with(:glob).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.expects(:path).with(@request.key,'').returns :glob + Dir.expects(:glob).with(:glob).returns [] @store.search(@request).should == [] end end |
