summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector/report/processor_spec.rb
blob: 6184cb9b5e979ea361c3e08edb54537392b2d107 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env rspec
require 'spec_helper'

require 'puppet/indirector/report/processor'

describe Puppet::Transaction::Report::Processor do
  before do
    Puppet.settings.stubs(:use).returns(true)
  end

  it "should provide a method for saving reports" do
    Puppet::Transaction::Report::Processor.new.should respond_to(:save)
  end

  it "should provide a method for cleaning reports" do
    Puppet::Transaction::Report::Processor.new.should respond_to(:destroy)
  end

end

describe Puppet::Transaction::Report::Processor, " when processing a report" do
  before do
    Puppet.settings.stubs(:use)
    @reporter = Puppet::Transaction::Report::Processor.new
    @request = stub 'request', :instance => stub("report", :host => 'hostname'), :key => 'node'
  end

  it "should not save the report if reports are set to 'none'" do
    Puppet::Reports.expects(:report).never
    Puppet[:reports] = 'none'

    request = Puppet::Indirector::Request.new(:indirection_name, :head, "key")
    report = Puppet::Transaction::Report.new('apply')
    request.instance = report

    @reporter.save(request)
  end

  it "should save the report with each configured report type" do
    Puppet.settings.stubs(:value).with(:reports).returns("one,two")
    @reporter.send(:reports).should == %w{one two}

    Puppet::Reports.expects(:report).with('one')
    Puppet::Reports.expects(:report).with('two')

    @reporter.save(@request)
  end

  it "should destroy reports for each processor that responds to destroy" do
    Puppet.settings.stubs(:value).with(:reports).returns("http,store")
    http_report = mock()
    store_report = mock()
    store_report.expects(:destroy).with(@request.key)
    Puppet::Reports.expects(:report).with('http').returns(http_report)
    Puppet::Reports.expects(:report).with('store').returns(store_report)
    @reporter.destroy(@request)
  end
end

describe Puppet::Transaction::Report::Processor, " when processing a report" do
  before do
    Puppet[:reports] = "one"
    Puppet.settings.stubs(:use)
    @reporter = Puppet::Transaction::Report::Processor.new

    @report_type = mock 'one'
    @dup_report = mock 'dupe report'
    @dup_report.stubs(:process)
    @report = Puppet::Transaction::Report.new('apply')
    @report.expects(:dup).returns(@dup_report)

    @request = stub 'request', :instance => @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(@request)
  end

  it "should extend the report with the report type's module" do
    @reporter.save(@request)
  end

  it "should call the report type's :process method" do
    @dup_report.expects(:process)
    @reporter.save(@request)
  end

  it "should not raise exceptions" do
    Puppet[:trace] = false
    @dup_report.expects(:process).raises(ArgumentError)
    proc { @reporter.save(@request) }.should_not raise_error
  end
end