This report processor was unnecessarily using Puppet to create a
single directory. This was causing complex failures in any spec
dealing with reports.

Paired-With: Paul Berry

Signed-off-by: Nick Lewis <[email protected]>
---
 lib/puppet/reports/store.rb     |   20 +-------------------
 spec/unit/reports/store_spec.rb |   31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 19 deletions(-)
 create mode 100644 spec/unit/reports/store_spec.rb

diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb
index 30f2459..99a9fc1 100644
--- a/lib/puppet/reports/store.rb
+++ b/lib/puppet/reports/store.rb
@@ -8,24 +8,6 @@ Puppet::Reports.register_report(:store) do
     to perform some maintenance on them if you use this report (it's the only
     default report)."
 
-  def mkclientdir(client, dir)
-    config = Puppet::Util::Settings.new
-
-          config.setdefaults(
-        "reportclient-#{client}".to_sym,
-      "client-#{client}-dir" => { :default => dir,
-        :mode => 0750,
-        :desc => "Client dir for #{client}",
-        :owner => 'service',
-        :group => 'service'
-      },
-
-      :noop => [false, "Used by settings internally."]
-    )
-
-    config.use("reportclient-#{client}".to_sym)
-  end
-
   def process
     # We don't want any tracking back in the fs.  Unlikely, but there
     # you go.
@@ -33,7 +15,7 @@ Puppet::Reports.register_report(:store) do
 
     dir = File.join(Puppet[:reportdir], client)
 
-    mkclientdir(client, dir) unless FileTest.exists?(dir)
+    Dir.mkdir(dir, 0750) unless FileTest.exists?(dir)
 
     # Now store the report.
     now = Time.now.gmtime
diff --git a/spec/unit/reports/store_spec.rb b/spec/unit/reports/store_spec.rb
new file mode 100644
index 0000000..1acb5ba
--- /dev/null
+++ b/spec/unit/reports/store_spec.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? 
require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+require 'puppet/reports'
+require 'time'
+
+processor = Puppet::Reports.report(:store)
+
+describe processor do
+  describe "#process" do
+    include PuppetSpec::Files
+    before :each do
+      Puppet[:reportdir] = tmpdir('reports')
+      @report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 
'yaml/report2.6.x.yaml')).extend processor
+    end
+
+    it "should create a report directory for the client if one doesn't exist" 
do
+      @report.process
+
+      File.should be_directory(File.join(Puppet[:reportdir], @report.host))
+    end
+
+    it "should write the report to the file in YAML" do
+      Time.stubs(:now).returns(Time.parse("2011-01-06 12:00:00 UTC"))
+      @report.process
+
+      File.read(File.join(Puppet[:reportdir], @report.host, 
"201101061200.yaml")).should == @report.to_yaml
+    end
+  end
+end
-- 
1.7.3.3

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to