summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-12-06 16:53:03 +0100
committerBrice Figureau <brice-puppet@daysofwonder.com>2008-12-06 16:53:03 +0100
commit435f1e9b52e11bc558405f2102c61db84fea03c2 (patch)
tree7df108d0b3d6466490985e3136110178f5274253 /spec/unit
parent6b30171435583b1a69c4ffe7b8b1760f5585cd38 (diff)
downloadpuppet-435f1e9b52e11bc558405f2102c61db84fea03c2.tar.gz
puppet-435f1e9b52e11bc558405f2102c61db84fea03c2.tar.xz
puppet-435f1e9b52e11bc558405f2102c61db84fea03c2.zip
Fix #1483 - use REST to transmit reports over the wire
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/indirector/report/rest.rb11
-rwxr-xr-xspec/unit/transaction.rb106
2 files changed, 105 insertions, 12 deletions
diff --git a/spec/unit/indirector/report/rest.rb b/spec/unit/indirector/report/rest.rb
new file mode 100644
index 000000000..a51ebca2a
--- /dev/null
+++ b/spec/unit/indirector/report/rest.rb
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/report/rest'
+
+describe Puppet::Transaction::Report::Rest do
+ it "should be a sublcass of Puppet::Indirector::REST" do
+ Puppet::Transaction::Report::Rest.superclass.should equal(Puppet::Indirector::REST)
+ end
+end
diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb
index 196f8cbb8..2c1998587 100755
--- a/spec/unit/transaction.rb
+++ b/spec/unit/transaction.rb
@@ -5,20 +5,24 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/transaction'
describe Puppet::Transaction do
- describe "when generating resources" do
- before do
- @generator_class = mkgenerator
- @generator = mkgenerator.create(:name => "foo")
+ before do
+ @generator_class = mkgenerator
+ @generator = mkgenerator.create(:name => "foo")
- @catalog = Puppet::Node::Catalog.new
- @catalog.add_resource @generator
+ @catalog = Puppet::Node::Catalog.new
+ @catalog.add_resource @generator
- @transaction = Puppet::Transaction.new(@catalog)
- end
+ @report = stub_everything 'report'
+ Puppet::Transaction::Report.stubs(:new).returns(@report)
- after do
- Puppet::Type.rmtype(:generator)
- end
+ @transaction = Puppet::Transaction.new(@catalog)
+ end
+
+ after do
+ Puppet::Type.rmtype(:generator)
+ end
+
+ describe "when generating resources" do
it "should call the generate() method on all resources" do
@generator.expects(:generate)
@@ -102,8 +106,86 @@ describe Puppet::Transaction do
@transaction.eval_generate(@generator)
end
end
+
end
-
+
+ describe "when generating a report" do
+
+ before :each do
+ Puppet.stubs(:[]).with(:report).returns(true)
+ end
+
+ it "should create a Puppet::Transaction::Report when the Transaction is created" do
+ Puppet::Transaction::Report.expects(:new).returns(@report)
+
+ Puppet::Transaction.new(@catalog)
+ end
+
+ it "should return a Puppet::Transaction::Report" do
+ @transaction.generate_report.should == @report
+ end
+
+ it "should have a metric for resources" do
+ @report.expects(:newmetric).with { |metric,hash| metric == :resources }
+
+ @transaction.generate_report
+ end
+
+ it "should have a metric for time" do
+ @report.expects(:newmetric).with { |metric,hash| metric == :time }
+
+ @transaction.generate_report
+ end
+
+ it "should have a metric for changes" do
+ @report.expects(:newmetric).with { |metric,hash| metric == :changes }
+
+ @transaction.generate_report
+ end
+
+ it "should store the current time" do
+ now = stub 'time'
+ Time.stubs(:now).returns(now)
+
+ @report.expects(:time=).with(now)
+
+ @transaction.generate_report
+ end
+
+ end
+
+ describe "when sending a report" do
+
+ before :each do
+ @transaction.stubs(:generate_report).returns(@report)
+ Puppet.stubs(:[]).with(:report).returns(true)
+ Puppet.stubs(:[]).with(:rrdgraph).returns(false)
+ Puppet.stubs(:[]).with(:summarize).returns(false)
+ end
+
+ it "should ask the transaction for a report" do
+ @transaction.expects(:generate_report)
+
+ @transaction.send_report
+ end
+
+ it "should ask the report for a graph if rrdgraph is enable" do
+ Puppet.stubs(:[]).with(:rrdgraph).returns(true)
+
+ @report.expects(:graph)
+
+ @transaction.send_report
+ end
+
+
+ it "should call report.save" do
+ @report.expects(:save)
+
+ @transaction.send_report
+ end
+
+ end
+
def mkgenerator
# Create a bogus type that generates new instances with shorter names
type = Puppet::Type.newtype(:generator) do