diff options
author | James Turnbull <james@lovedthanlost.net> | 2008-08-01 07:11:21 +1000 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-08-01 07:11:56 +1000 |
commit | 2a3d195402900aa31843f7a7ff78026409cf43f5 (patch) | |
tree | 45950228cc66859dc858dc50b8dea80816781fb0 | |
parent | c97389d5f6748c05b88f6461b87b4d21a273ab00 (diff) | |
download | puppet-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
-rwxr-xr-x | ext/puppetlast | 27 | ||||
-rwxr-xr-x | spec/unit/indirector/yaml.rb | 29 |
2 files changed, 29 insertions, 27 deletions
diff --git a/ext/puppetlast b/ext/puppetlast index 848fdde6c..d9b698cfe 100755 --- a/ext/puppetlast +++ b/ext/puppetlast @@ -10,33 +10,6 @@ Puppet.parse_config Puppet[:name] = "puppetmasterd" Puppet::Node::Facts.terminus_class = :yaml -print "puppetlast\n" - -nodes = {} - -yfdir = Puppet.settings.value(:vardir) + "/yaml/facts" - -if yfdir - begin - Dir.chdir(yfdir) do - Dir.glob("*.yaml").each do |yaml| - data = YAML.load_file(yaml) - t = Time.now - age = t - data.version - nodes[data.name] = age.to_i - end - end - - nodes.sort.each do |node,age| - minutes = age / 60 + 0.5 - print minutes.floor.to_s + ' minutes ago: ' + node + "\n" - end - - rescue - print 'error: ' + $! + "\n" - end - Puppet::Node::Facts.search("*").sort.each do |node| puts "#{node.name} #{node.expired? ? 'cached expired, ' : ''}checked in #{((Time.now - node.values[:_timestamp]) / 60).floor} minutes ago" 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 |