diff options
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/integration/reports.rb | 14 | ||||
-rwxr-xr-x | spec/unit/indirector/code/report.rb | 73 | ||||
-rwxr-xr-x | spec/unit/reports.rb | 61 | ||||
-rwxr-xr-x | spec/unit/transaction/report.rb | 34 |
4 files changed, 182 insertions, 0 deletions
diff --git a/spec/integration/reports.rb b/spec/integration/reports.rb new file mode 100755 index 000000000..7351c3da1 --- /dev/null +++ b/spec/integration/reports.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-10-12. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../spec_helper' + +require 'puppet/reports' + +describe Puppet::Reports, " when using report types" do + it "should load report types as modules" do + Puppet::Reports.report(:store).should be_instance_of(Module) + end +end diff --git a/spec/unit/indirector/code/report.rb b/spec/unit/indirector/code/report.rb new file mode 100755 index 000000000..a27eaa297 --- /dev/null +++ b/spec/unit/indirector/code/report.rb @@ -0,0 +1,73 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-9-23. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/indirector/code/report' + +describe Puppet::Indirector::Code::Report do + it "should provide a method for saving reports" do + Puppet::Indirector::Code::Report.new.should respond_to(:save) + end +end + + +describe Puppet::Indirector::Code::Report, " when saving a report" do + before do + Puppet.settings.stubs(:use) + @reporter = Puppet::Indirector::Code::Report.new + end + + it "should not process the report if reports are set to 'none'" do + Puppet::Reports.expects(:report).never + Puppet.settings.expects(:value).with(:reports).returns("none") + + @reporter.save(:whatever) + end + + it "should process the report with each configured report type" do + Puppet.settings.stubs(:value).with(:reports).returns("one,two") + @reporter.send(:reports).should == %w{one two} + end +end + +describe Puppet::Indirector::Code::Report, " when processing a report" do + before do + Puppet.settings.stubs(:value).with(:reports).returns("one") + Puppet.settings.stubs(:use) + @reporter = Puppet::Indirector::Code::Report.new + + @report_type = mock 'one' + @dup_report = mock 'dupe report' + @dup_report.stubs(:process) + @report = mock 'report' + @report.expects(:dup).returns(@dup_report) + Puppet::Reports.expects(:report).with("one").returns(@report_type) + + @dup_report.expects(:extend).with(@report_type) + end + + # LAK:NOTE This is stupid, because the code is so short it doesn't + # make sense to split it out, which means I just do the same test + # three times so the spec looks right. + it "should process a duplicate of the report, not the original" do + @reporter.save(@report) + end + + it "should extend the report with the report type's module" do + @reporter.save(@report) + end + + it "should call the report type's :process method" do + @dup_report.expects(:process) + @reporter.save(@report) + end + + it "should not raise exceptions" do + Puppet.settings.stubs(:value).with(:trace).returns(false) + @dup_report.expects(:process).raises(ArgumentError) + proc { @reporter.save(@report) }.should_not raise_error + end +end diff --git a/spec/unit/reports.rb b/spec/unit/reports.rb new file mode 100755 index 000000000..f12f0d717 --- /dev/null +++ b/spec/unit/reports.rb @@ -0,0 +1,61 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../spec_helper' + +require 'puppet/reports' + +describe Puppet::Reports do + it "should instance-load report types" do + Puppet::Reports.instance_loader(:report).should be_instance_of(Puppet::Util::Autoload) + end + + it "should have a method for registering report types" do + Puppet::Reports.should respond_to(:register_report) + end + + it "should have a method for retrieving report types by name" do + Puppet::Reports.should respond_to(:report) + end + + it "should provide a method for returning documentation for all reports" do + Puppet::Reports.expects(:loaded_instances).with(:report).returns([:one, :two]) + one = mock 'one', :doc => "onedoc" + two = mock 'two', :doc => "twodoc" + Puppet::Reports.expects(:report).with(:one).returns(one) + Puppet::Reports.expects(:report).with(:two).returns(two) + + doc = Puppet::Reports.reportdocs + doc.include?("onedoc").should be_true + doc.include?("twodoc").should be_true + end +end + + +describe Puppet::Reports, " when loading report types" do + it "should use the instance loader to retrieve report types" do + Puppet::Reports.expects(:loaded_instance).with(:report, :myreporttype) + Puppet::Reports.report(:myreporttype) + end +end + +describe Puppet::Reports, " when registering report types" do + it "should evaluate the supplied block as code for a module" do + Puppet::Reports.expects(:genmodule).returns(Module.new) + Puppet::Reports.register_report(:testing) { } + end + + it "should extend the report type with the Puppet::Util::Docs module" do + mod = stub 'module', :define_method => true + + Puppet::Reports.expects(:genmodule).with { |name, options, block| options[:extend] == Puppet::Util::Docs }.returns(mod) + Puppet::Reports.register_report(:testing) { } + end + + it "should define a :report_name method in the module that returns the name of the report" do + mod = mock 'module' + mod.expects(:define_method).with(:report_name) + + Puppet::Reports.expects(:genmodule).returns(mod) + Puppet::Reports.register_report(:testing) { } + end +end diff --git a/spec/unit/transaction/report.rb b/spec/unit/transaction/report.rb new file mode 100755 index 000000000..ce8c4038d --- /dev/null +++ b/spec/unit/transaction/report.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-10-12. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/transaction/report' + +describe Puppet::Transaction::Report, " when being indirect" do + it "should redirect :find to the indirection" do + @indirection = mock 'indirection' + Puppet::Transaction::Report.stubs(:indirection).returns(@indirection) + @indirection.expects(:find).with(:report) + Puppet::Transaction::Report.find(:report) + end + + it "should redirect :save to the indirection" do + Facter.stubs(:value).returns("eh") + @indirection = mock 'indirection' + Puppet::Transaction::Report.stubs(:indirection).returns(@indirection) + report = Puppet::Transaction::Report.new + @indirection.expects(:save).with(report) + report.save + end + + it "should default to the 'code' terminus" do + Puppet::Transaction::Report.indirection.terminus_class.should == :code + end + + after do + Puppet::Indirector::Indirection.clear_cache + end +end |