|
4 | 4 | require 'puppet/application/agent'
|
5 | 5 | require 'puppet/daemon'
|
6 | 6 |
|
| 7 | +class TestAgentClientClass |
| 8 | + def initialize(transaction_uuid = nil, job_id = nil); end |
| 9 | + def run(options = {}); end |
| 10 | +end |
| 11 | + |
7 | 12 | describe Puppet::Application::Agent do
|
8 | 13 | include PuppetSpec::Files
|
9 | 14 |
|
|
12 | 17 | before :each do
|
13 | 18 | @puppetd = Puppet::Application[:agent]
|
14 | 19 |
|
15 |
| - @agent = double('agent') |
| 20 | + @client = TestAgentClientClass.new |
| 21 | + allow(TestAgentClientClass).to receive(:new).and_return(@client) |
| 22 | + |
| 23 | + @agent = Puppet::Agent.new(TestAgentClientClass, false) |
16 | 24 | allow(Puppet::Agent).to receive(:new).and_return(@agent)
|
17 | 25 |
|
18 |
| - @daemon = Puppet::Daemon.new(@agent, nil) |
| 26 | + Puppet[:pidfile] = tmpfile('pidfile') |
| 27 | + @daemon = Puppet::Daemon.new(@agent, Puppet::Util::Pidlock.new(Puppet[:pidfile])) |
19 | 28 | allow(@daemon).to receive(:daemonize)
|
20 |
| - allow(@daemon).to receive(:start) |
21 | 29 | allow(@daemon).to receive(:stop)
|
| 30 | + # simulate one run so we don't infinite looptwo runs of the agent, then return so we don't infinite loop |
| 31 | + allow(@daemon).to receive(:run_event_loop) do |
| 32 | + @agent.run(splay: false) |
| 33 | + end |
22 | 34 | allow(Puppet::Daemon).to receive(:new).and_return(@daemon)
|
23 | 35 | Puppet[:daemonize] = false
|
24 | 36 |
|
|
92 | 104 | end
|
93 | 105 |
|
94 | 106 | describe "when handling options" do
|
95 |
| - before do |
96 |
| - allow(@puppetd.command_line).to receive(:args).and_return([]) |
97 |
| - end |
98 |
| - |
99 | 107 | [:enable, :debug, :fqdn, :test, :verbose, :digest].each do |option|
|
100 | 108 | it "should declare handle_#{option} method" do
|
101 | 109 | expect(@puppetd).to respond_to("handle_#{option}".to_sym)
|
|
127 | 135 | end
|
128 | 136 |
|
129 | 137 | it "should set waitforcert to 0 with --onetime and if --waitforcert wasn't given" do
|
130 |
| - allow(@agent).to receive(:run).and_return(2) |
| 138 | + allow(@client).to receive(:run).and_return(2) |
131 | 139 | Puppet[:onetime] = true
|
132 | 140 |
|
133 |
| - expect(Puppet::SSL::StateMachine).to receive(:new).with(waitforcert: 0).and_return(machine) |
| 141 | + expect(Puppet::SSL::StateMachine).to receive(:new).with(hash_including(waitforcert: 0)).and_return(machine) |
134 | 142 |
|
135 | 143 | expect { execute_agent }.to exit_with 0
|
136 | 144 | end
|
137 | 145 |
|
138 | 146 | it "should use supplied waitforcert when --onetime is specified" do
|
139 |
| - allow(@agent).to receive(:run).and_return(2) |
| 147 | + allow(@client).to receive(:run).and_return(2) |
140 | 148 | Puppet[:onetime] = true
|
141 | 149 | @puppetd.handle_waitforcert(60)
|
142 | 150 |
|
143 |
| - expect(Puppet::SSL::StateMachine).to receive(:new).with(waitforcert: 60).and_return(machine) |
| 151 | + expect(Puppet::SSL::StateMachine).to receive(:new).with(hash_including(waitforcert: 60)).and_return(machine) |
144 | 152 |
|
145 | 153 | expect { execute_agent }.to exit_with 0
|
146 | 154 | end
|
147 | 155 |
|
148 | 156 | it "should use a default value for waitforcert when --onetime and --waitforcert are not specified" do
|
149 |
| - expect(Puppet::SSL::StateMachine).to receive(:new).with(waitforcert: 120).and_return(machine) |
| 157 | + allow(@client).to receive(:run).and_return(2) |
| 158 | + |
| 159 | + expect(Puppet::SSL::StateMachine).to receive(:new).with(hash_including(waitforcert: 120)).and_return(machine) |
150 | 160 |
|
151 | 161 | execute_agent
|
152 | 162 | end
|
153 | 163 |
|
154 | 164 | it "should register ssl OIDs" do
|
155 |
| - expect(Puppet::SSL::StateMachine).to receive(:new).with(waitforcert: 120).and_return(double(ensure_client_certificate: nil)) |
| 165 | + expect(Puppet::SSL::StateMachine).to receive(:new).with(hash_including(waitforcert: 120)).and_return(machine) |
156 | 166 | expect(Puppet::SSL::Oids).to receive(:register_puppet_oids)
|
157 | 167 |
|
158 | 168 | execute_agent
|
|
161 | 171 | it "should use the waitforcert setting when checking for a signed certificate" do
|
162 | 172 | Puppet[:waitforcert] = 10
|
163 | 173 |
|
164 |
| - expect(Puppet::SSL::StateMachine).to receive(:new).with(waitforcert: 10).and_return(machine) |
| 174 | + expect(Puppet::SSL::StateMachine).to receive(:new).with(hash_including(waitforcert: 10)).and_return(machine) |
165 | 175 |
|
166 | 176 | execute_agent
|
167 | 177 | end
|
|
413 | 423 | end
|
414 | 424 |
|
415 | 425 | it "should wait for a certificate" do
|
416 |
| - @puppetd.options[:waitforcert] = 123 |
| 426 | + Puppet[:waitforcert] = 123 |
417 | 427 |
|
418 |
| - expect(Puppet::SSL::StateMachine).to receive(:new).with(waitforcert: 123).and_return(machine) |
| 428 | + expect(Puppet::SSL::StateMachine).to receive(:new).with(hash_including(waitforcert: 123)).and_return(machine) |
419 | 429 |
|
420 | 430 | execute_agent
|
421 | 431 | end
|
|
0 commit comments