2
2
require 'spec_helper'
4
3
require 'puppet/reports'
6
# FakeHTTP fakes the behavior of Net::HTTP#request and acts as a sensor for an
7
# otherwise difficult to trace method call.
12
REQUESTS[req.path] = req
16
5
processor = Puppet::Reports.report(:http)
18
7
describe processor do
19
before { Net::HTTP.any_instance.stubs(:start).yields(FakeHTTP) }
20
8
subject { Puppet::Transaction::Report.new("apply").extend(processor) }
22
it { should respond_to(:process) }
24
10
it "should use the reporturl setting's host and port" do
25
11
uri = URI.parse(Puppet[:reporturl])
26
12
Net::HTTP.expects(:new).with(uri.host, uri.port).returns(stub_everything('http'))
31
before { subject.process }
34
it "should use the path specified by the 'reporturl' setting" do
35
reports_request.path.should == URI.parse(Puppet[:reporturl]).path
40
it "should be the report as YAML" do
41
reports_request.body.should == subject.to_yaml
45
describe "content type" do
46
it "should be 'application/x-yaml'" do
47
reports_request.content_type.should == "application/x-yaml"
16
describe "when making a request" do
17
let(:http) { mock "http" }
18
let(:httpok) { Net::HTTPOK.new('1.1', 200, '') }
21
Net::HTTP.any_instance.expects(:start).yields(http)
24
it "should use the path specified by the 'reporturl' setting" do
25
http.expects(:request).with {|req|
26
req.path.should == URI.parse(Puppet[:reporturl]).path
32
it "should give the body as the report as YAML" do
33
http.expects(:request).with {|req|
34
req.body.should == subject.to_yaml
40
it "should set content-type to 'application/x-yaml'" do
41
http.expects(:request).with {|req|
42
req.content_type.should == "application/x-yaml"
48
Net::HTTPResponse::CODE_TO_OBJ.each do |code, klass|
49
if code.to_i >= 200 and code.to_i < 300
50
it "should succeed on http code #{code}" do
51
response = klass.new('1.1', code, '')
52
http.expects(:request).returns(response)
54
Puppet.expects(:err).never
60
it "should log error on http code #{code}" do
61
response = klass.new('1.1', code, '')
62
http.expects(:request).returns(response)
54
def reports_request; FakeHTTP::REQUESTS[URI.parse(Puppet[:reporturl]).path] end