summaryrefslogtreecommitdiffstats
path: root/spec/unit/network/xmlrpc/client.rb
blob: e20c66c25130f9c38c3d9fa7e9181f372fcde852 (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
#!/usr/bin/env ruby
#
#  Created by Luke Kanies on 2007-11-26.
#  Copyright (c) 2007. All rights reserved.

require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/network/xmlrpc/client'

describe Puppet::Network::XMLRPCClient, " when managing http instances" do
    it "should return an http instance created with the passed host and port" do
        http = stub 'http', :use_ssl= => nil, :read_timeout= => nil, :open_timeout= => nil
        Net::HTTP.expects(:new).with("me", 54321, nil, nil).returns(http)
        Puppet::Network::XMLRPCClient.http_instance("me", 54321).should equal(http)
    end

    it "should enable ssl on the http instance" do
        Puppet::Network::XMLRPCClient.http_instance("me", 54321).use_ssl.should be_true
    end

    it "should set the read timeout" do
        Puppet::Network::XMLRPCClient.http_instance("me", 54321).read_timeout.should == 120
    end

    it "should set the open timeout" do
        Puppet::Network::XMLRPCClient.http_instance("me", 54321).open_timeout.should == 120
    end

    it "should create the http instance with the proxy host and port set if the http_proxy is not set to 'none'" do
        Puppet.settings.stubs(:value).with(:http_keepalive).returns(true)
        Puppet.settings.stubs(:value).with(:http_proxy_host).returns("myhost")
        Puppet.settings.stubs(:value).with(:http_proxy_port).returns(432)
        Puppet::Network::XMLRPCClient.http_instance("me", 54321).open_timeout.should == 120
    end

    it "should default to keep-alive being enabled" do
        Puppet.settings[:http_keepalive].should be_true
    end

    it "should cache http instances if keepalive is enabled" do
        Puppet.settings.stubs(:value).with(:http_keepalive).returns(true)
        Puppet.settings.stubs(:value).with(:http_proxy_host).returns("myhost")
        Puppet.settings.stubs(:value).with(:http_proxy_port).returns(432)
        old = Puppet::Network::XMLRPCClient.http_instance("me", 54321)
        Puppet::Network::XMLRPCClient.http_instance("me", 54321).should equal(old)
    end

    it "should not cache http instances if keepalive is not enabled" do
        Puppet.settings.stubs(:value).with(:http_keepalive).returns(false)
        Puppet.settings.stubs(:value).with(:http_proxy_host).returns("myhost")
        Puppet.settings.stubs(:value).with(:http_proxy_port).returns(432)
        old = Puppet::Network::XMLRPCClient.http_instance("me", 54321)
        Puppet::Network::XMLRPCClient.http_instance("me", 54321).should_not equal(old)
    end

    it "should have a mechanism for clearing the http cache" do
        Puppet.settings.stubs(:value).with(:http_keepalive).returns(true)
        Puppet.settings.stubs(:value).with(:http_proxy_host).returns("myhost")
        Puppet.settings.stubs(:value).with(:http_proxy_port).returns(432)
        old = Puppet::Network::XMLRPCClient.http_instance("me", 54321)
        Puppet::Network::XMLRPCClient.http_instance("me", 54321).should equal(old)
        old = Puppet::Network::XMLRPCClient.http_instance("me", 54321)
        Puppet::Network::XMLRPCClient.clear_http_instances
        Puppet::Network::XMLRPCClient.http_instance("me", 54321).should_not equal(old)
    end

    after do
        Puppet::Network::XMLRPCClient.clear_http_instances
    end
end