beaker 4.23.2 → 4.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +8 -0
- data/.rspec +1 -0
- data/.travis.yml +2 -4
- data/CHANGELOG.md +56 -2
- data/CODEOWNERS +0 -2
- data/Rakefile +1 -4
- data/beaker.gemspec +5 -5
- data/lib/beaker/host.rb +7 -1
- data/lib/beaker/host/pswindows/exec.rb +19 -4
- data/lib/beaker/host/pswindows/file.rb +3 -3
- data/lib/beaker/host/unix/exec.rb +86 -58
- data/lib/beaker/local_connection.rb +86 -0
- data/lib/beaker/ssh_connection.rb +6 -1
- data/lib/beaker/version.rb +1 -1
- data/spec/beaker/host/pswindows/exec_spec.rb +59 -6
- data/spec/beaker/host/pswindows/file_spec.rb +23 -4
- data/spec/beaker/host/unix/exec_spec.rb +175 -113
- data/spec/beaker/host_spec.rb +7 -1
- data/spec/beaker/localhost_connection_spec.rb +106 -0
- metadata +22 -13
@@ -69,8 +69,13 @@ module Beaker
|
|
69
69
|
begin
|
70
70
|
@logger.debug "Attempting ssh connection to #{host}, user: #{user}, opts: #{ssh_opts}"
|
71
71
|
|
72
|
+
# Work around net-ssh 6+ incompatibilities
|
72
73
|
if ssh_opts.include?(:strict_host_key_checking) && (Net::SSH::Version::CURRENT.major > 5)
|
73
|
-
|
74
|
+
strict_host_key_checking = ssh_opts.delete(:strict_host_key_checking)
|
75
|
+
|
76
|
+
unless ssh_opts[:verify_host_key].is_a?(Symbol)
|
77
|
+
ssh_opts[:verify_host_key] ||= strict_host_key_checking ? :always : :never
|
78
|
+
end
|
74
79
|
end
|
75
80
|
|
76
81
|
Net::SSH.start(host, user, ssh_opts)
|
data/lib/beaker/version.rb
CHANGED
@@ -29,8 +29,8 @@ module Beaker
|
|
29
29
|
it "deletes" do
|
30
30
|
path = '/path/to/delete'
|
31
31
|
corrected_path = '\\path\\to\\delete'
|
32
|
-
expect(
|
33
|
-
expect(
|
32
|
+
expect(instance).to receive(:execute).with(%(del /s /q "#{corrected_path}")).and_return(0)
|
33
|
+
expect(instance.rm_rf(path)).to eq(0)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -39,10 +39,9 @@ module Beaker
|
|
39
39
|
let(:destination) { '/destination/path/of/content' }
|
40
40
|
|
41
41
|
it 'rm first' do
|
42
|
-
expect(
|
43
|
-
expect(
|
44
|
-
expect(
|
45
|
-
|
42
|
+
expect(instance).to receive(:execute).with("del /s /q \"\\destination\\path\\of\\content\"").and_return(0)
|
43
|
+
expect(instance).to receive(:execute).with("move /y #{origin.gsub(/\//, '\\')} #{destination.gsub(/\//, '\\')}").and_return(0)
|
44
|
+
expect(instance.mv(origin, destination)).to eq(0)
|
46
45
|
end
|
47
46
|
|
48
47
|
it 'does not rm' do
|
@@ -99,5 +98,59 @@ module Beaker
|
|
99
98
|
to be == "set \"LD_PATH=/:/tmp\" && "
|
100
99
|
end
|
101
100
|
end
|
101
|
+
|
102
|
+
describe '#which' do
|
103
|
+
before do
|
104
|
+
allow(instance).to receive(:execute)
|
105
|
+
.with(where_command, :accept_all_exit_codes => true).and_return(result)
|
106
|
+
end
|
107
|
+
let(:where_command) { "cmd /C \"where ruby\"" }
|
108
|
+
|
109
|
+
context 'when only the environment variable PATH is used' do
|
110
|
+
let(:result) { "C:\\Ruby26-x64\\bin\\ruby.exe" }
|
111
|
+
|
112
|
+
it 'returns the correct path' do
|
113
|
+
response = instance.which('ruby')
|
114
|
+
|
115
|
+
expect(response).to eq(result)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when command is not found' do
|
120
|
+
let(:where_command) { "cmd /C \"where unknown\"" }
|
121
|
+
let(:result) { '' }
|
122
|
+
|
123
|
+
it 'return empty string if command is not found' do
|
124
|
+
response = instance.which('unknown')
|
125
|
+
|
126
|
+
expect(response).to eq(result)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#mkdir_p' do
|
132
|
+
let(:dir_path) { "C:\\tmpdir\\my_dir" }
|
133
|
+
let(:beaker_command) { instance_spy(Beaker::Command) }
|
134
|
+
let(:command) {"-Command New-Item -Path '#{dir_path}' -ItemType 'directory'"}
|
135
|
+
let(:result) { instance_spy(Beaker::Result) }
|
136
|
+
|
137
|
+
before do
|
138
|
+
allow(Beaker::Command).to receive(:new).
|
139
|
+
with('powershell.exe', array_including(command)).and_return(beaker_command)
|
140
|
+
allow(instance).to receive(:exec).with(beaker_command, :acceptable_exit_codes => [0, 1]).and_return(result)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'returns true and creates folder structure' do
|
144
|
+
allow(result).to receive(:exit_code).and_return(0)
|
145
|
+
|
146
|
+
expect(instance.mkdir_p(dir_path)).to be(true)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'returns false if failed to create directory structure' do
|
150
|
+
allow(result).to receive(:exit_code).and_return(1)
|
151
|
+
|
152
|
+
expect(instance.mkdir_p(dir_path)).to be(false)
|
153
|
+
end
|
154
|
+
end
|
102
155
|
end
|
103
156
|
end
|
@@ -25,11 +25,31 @@ module Beaker
|
|
25
25
|
let (:instance) { PSWindowsFileTest.new(opts, logger) }
|
26
26
|
|
27
27
|
describe '#cat' do
|
28
|
+
let(:path) { '/path/to/cat' }
|
29
|
+
let(:content) { 'file content' }
|
28
30
|
it 'reads output for file' do
|
29
|
-
|
30
|
-
expect(instance).to receive(:exec)
|
31
|
+
expect(instance).to receive(:exec).and_return(double(stdout: content))
|
31
32
|
expect(Beaker::Command).to receive(:new).with('powershell.exe', array_including("-Command type #{path}"))
|
32
|
-
instance.cat(path)
|
33
|
+
expect(instance.cat(path)).to eq(content)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#file_exist?' do
|
38
|
+
let(:path) { '/path/to/test/file.txt' }
|
39
|
+
context 'file exists' do
|
40
|
+
it 'returns true' do
|
41
|
+
expect(instance).to receive(:exec).and_return(double(stdout: "true\n"))
|
42
|
+
expect(Beaker::Command).to receive(:new).with("if exist #{path} echo true")
|
43
|
+
expect(instance.file_exist?(path)).to eq(true)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'file does not exist' do
|
48
|
+
it 'returns false' do
|
49
|
+
expect(instance).to receive(:exec).and_return(double(stdout: ""))
|
50
|
+
expect(Beaker::Command).to receive(:new).with("if exist #{path} echo true")
|
51
|
+
expect(instance.file_exist?(path)).to eq(false)
|
52
|
+
end
|
33
53
|
end
|
34
54
|
end
|
35
55
|
|
@@ -39,7 +59,6 @@ module Beaker
|
|
39
59
|
|
40
60
|
before do
|
41
61
|
allow(instance).to receive(:execute).with(anything)
|
42
|
-
|
43
62
|
end
|
44
63
|
|
45
64
|
context 'with dirname sent' do
|
@@ -169,6 +169,64 @@ module Beaker
|
|
169
169
|
end
|
170
170
|
|
171
171
|
describe '#reboot' do
|
172
|
+
check_cmd_output = {
|
173
|
+
:centos6 => {
|
174
|
+
:who => {
|
175
|
+
:initial => ' system boot 2020-05-13 03:51',
|
176
|
+
:success => ' system boot 2020-05-13 03:52',
|
177
|
+
},
|
178
|
+
:last => {
|
179
|
+
:initial => <<~LAST_F,
|
180
|
+
reboot system boot 2.6.32-754.29.1. Tue May 5 17:34:52 2020 - Tue May 5 17:52:48 2020 (00:17)
|
181
|
+
reboot system boot 2.6.32-754.29.1. Mon May 4 18:45:43 2020 - Mon May 5 05:35:44 2020 (4+01:50)
|
182
|
+
LAST_F
|
183
|
+
:success => <<~LAST_F,
|
184
|
+
reboot system boot 2.6.32-754.29.1. Tue May 5 17:52:48 2020 - Tue May 5 17:52:49 2020 (00:17)
|
185
|
+
reboot system boot 2.6.32-754.29.1. Mon May 4 18:45:43 2020 - Mon May 5 05:35:44 2020 (4+01:50)
|
186
|
+
LAST_F
|
187
|
+
},
|
188
|
+
},
|
189
|
+
:centos7 => {
|
190
|
+
:who => {
|
191
|
+
:initial => ' system boot 2020-05-13 03:51',
|
192
|
+
:success => ' system boot 2020-05-13 03:52',
|
193
|
+
},
|
194
|
+
:last => {
|
195
|
+
:initial => <<~LAST_F,
|
196
|
+
reboot system boot 3.10.0-1127.el7. Tue May 5 17:34:52 2020 - Tue May 5 17:52:48 2020 (00:17)
|
197
|
+
reboot system boot 3.10.0-1127.el7. Mon May 4 18:45:43 2020 - Mon May 5 05:35:44 2020 (4+01:50)
|
198
|
+
LAST_F
|
199
|
+
:success => <<~LAST_F,
|
200
|
+
reboot system boot 3.10.0-1127.el7. Tue May 5 17:52:48 2020 - Tue May 5 17:52:49 2020 (00:17)
|
201
|
+
reboot system boot 3.10.0-1127.el7. Mon May 4 18:45:43 2020 - Mon May 5 05:35:44 2020 (4+01:50)
|
202
|
+
LAST_F
|
203
|
+
},
|
204
|
+
},
|
205
|
+
:centos8 => {
|
206
|
+
:who => {
|
207
|
+
:initial => ' system boot 2020-05-13 03:51',
|
208
|
+
:success => ' system boot 2020-05-13 03:52',
|
209
|
+
},
|
210
|
+
:last => {
|
211
|
+
:initial => <<~LAST_F,
|
212
|
+
reboot system boot 4.18.0-147.8.1.e Tue May 5 17:34:52 2020 still running
|
213
|
+
reboot system boot 4.18.0-147.8.1.e Mon May 4 17:41:27 2020 - Tue May 5 17:00:00 2020 (5+00:11)
|
214
|
+
LAST_F
|
215
|
+
:success => <<~LAST_F,
|
216
|
+
reboot system boot 4.18.0-147.8.1.e Tue May 5 17:34:53 2020 still running
|
217
|
+
reboot system boot 4.18.0-147.8.1.e Mon May 4 17:41:27 2020 - Tue May 5 17:00:00 2020 (5+00:11)
|
218
|
+
LAST_F
|
219
|
+
},
|
220
|
+
},
|
221
|
+
:freebsd => {
|
222
|
+
# last -F doesn't work on freebsd so no output will be returned
|
223
|
+
:who => {
|
224
|
+
:initial => ' system boot May 13 03:51',
|
225
|
+
:success => ' system boot May 13 03:52',
|
226
|
+
}
|
227
|
+
},
|
228
|
+
}
|
229
|
+
|
172
230
|
# no-op response
|
173
231
|
let (:response) { double( 'response' ) }
|
174
232
|
let (:boot_time_initial_response) { double( 'response' ) }
|
@@ -179,7 +237,7 @@ module Beaker
|
|
179
237
|
before :each do
|
180
238
|
# stubs enough to survive the first boot_time call & output parsing
|
181
239
|
# note: just stubs input-chain between calls, parsing methods still run
|
182
|
-
allow(Beaker::Command).to receive(:new).with('who -b').and_return(:boot_time_command_stub)
|
240
|
+
allow(Beaker::Command).to receive(:new).with('last -F reboot || who -b').and_return(:boot_time_command_stub)
|
183
241
|
|
184
242
|
allow(boot_time_initial_response).to receive(:stdout).and_return(boot_time_initial_stdout)
|
185
243
|
allow(boot_time_success_response).to receive(:stdout).and_return(boot_time_success_stdout)
|
@@ -190,116 +248,128 @@ module Beaker
|
|
190
248
|
end
|
191
249
|
|
192
250
|
context 'new boot time greater than old boot time' do
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
251
|
+
check_cmd_output.each do |check_os, cmd_opts|
|
252
|
+
cmd_opts.each do |cmd_name, cmd_outputs|
|
253
|
+
context "on '#{check_os}' with the '#{cmd_name}' command" do
|
254
|
+
let (:boot_time_initial_stdout) { cmd_outputs[:initial] }
|
255
|
+
let (:boot_time_success_stdout) { cmd_outputs[:success] }
|
256
|
+
|
257
|
+
it 'passes with defaults' do
|
258
|
+
expect(instance).to receive(:sleep).with(sleep_time)
|
259
|
+
# bypass shutdown command itself
|
260
|
+
expect(instance).to receive( :exec ).with(:shutdown_command_stub, anything).and_return(response)
|
261
|
+
# allow the second boot_time and the hash arguments in exec
|
262
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).once
|
263
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_success_response).once
|
206
264
|
|
207
|
-
|
208
|
-
|
209
|
-
# bypass shutdown command itself
|
210
|
-
expect(instance).to receive( :exec ).with(:shutdown_command_stub, anything).and_return(response).once
|
211
|
-
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).once
|
212
|
-
# allow the second boot_time and the hash arguments in exec
|
213
|
-
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_success_response).once
|
265
|
+
expect(instance.reboot).to be(nil)
|
266
|
+
end
|
214
267
|
|
215
|
-
|
216
|
-
|
268
|
+
it 'passes with wait_time_parameter' do
|
269
|
+
expect(instance).to receive(:sleep).with(10)
|
270
|
+
# bypass shutdown command itself
|
271
|
+
expect(instance).to receive( :exec ).with(:shutdown_command_stub, anything).and_return(response).once
|
272
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).once
|
273
|
+
# allow the second boot_time and the hash arguments in exec
|
274
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_success_response).once
|
217
275
|
|
218
|
-
|
219
|
-
|
220
|
-
# bypass shutdown command itself
|
221
|
-
expect(instance).to receive( :exec ).with(:shutdown_command_stub, anything).and_return(response).once
|
222
|
-
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).once
|
223
|
-
# allow the second boot_time and the hash arguments in exec
|
224
|
-
expect(instance).to receive( :exec ).with(:boot_time_command_stub, hash_including(:max_connection_tries => 20)).and_return(boot_time_success_response).once
|
276
|
+
expect(instance.reboot(10)).to be(nil)
|
277
|
+
end
|
225
278
|
|
226
|
-
|
227
|
-
|
279
|
+
it 'passes with max_connection_tries parameter' do
|
280
|
+
expect(instance).to receive(:sleep).with(sleep_time)
|
281
|
+
# bypass shutdown command itself
|
282
|
+
expect(instance).to receive( :exec ).with(:shutdown_command_stub, anything).and_return(response).once
|
283
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).once
|
284
|
+
# allow the second boot_time and the hash arguments in exec
|
285
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, hash_including(:max_connection_tries => 20)).and_return(boot_time_success_response).once
|
228
286
|
|
229
|
-
|
230
|
-
|
231
|
-
allow(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).once
|
232
|
-
end
|
287
|
+
expect(instance.reboot(sleep_time, 20)).to be(nil)
|
288
|
+
end
|
233
289
|
|
234
|
-
|
235
|
-
|
236
|
-
|
290
|
+
context 'command errors' do
|
291
|
+
before :each do
|
292
|
+
allow(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).at_least(:once)
|
293
|
+
end
|
237
294
|
|
238
|
-
|
239
|
-
|
295
|
+
it 'raises a reboot failure when command fails' do
|
296
|
+
expect(instance).to receive(:sleep).at_least(:once)
|
297
|
+
expect(instance).to receive(:exec).with(:shutdown_command_stub, anything).and_raise(Host::CommandFailure).at_least(:once)
|
240
298
|
|
241
|
-
|
242
|
-
|
243
|
-
expect(instance).to receive(:exec).with(:shutdown_command_stub, anything).and_raise(Net::SSH::HostKeyError).once
|
299
|
+
expect{ instance.reboot }.to raise_error(Beaker::Host::CommandFailure)
|
300
|
+
end
|
244
301
|
|
245
|
-
|
246
|
-
|
302
|
+
it 'raises a reboot failure when we receive an unexpected error' do
|
303
|
+
expect(instance).to receive(:sleep).at_least(:once)
|
304
|
+
expect(instance).to receive(:exec).with(:shutdown_command_stub, anything).and_raise(Net::SSH::HostKeyError).at_least(:once)
|
247
305
|
|
248
|
-
|
249
|
-
|
250
|
-
let (:boot_time_initial_stdout) { 'boot bad' }
|
306
|
+
expect { instance.reboot }.to raise_error(Net::SSH::HostKeyError)
|
307
|
+
end
|
251
308
|
|
252
|
-
|
253
|
-
|
309
|
+
context 'incorrect time string' do
|
310
|
+
context 'original time' do
|
311
|
+
let (:boot_time_initial_stdout) { 'boot bad' }
|
254
312
|
|
255
|
-
|
256
|
-
|
257
|
-
|
313
|
+
it 'raises a reboot failure' do
|
314
|
+
# Handle the 'retry'
|
315
|
+
allow(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).at_least(:once)
|
258
316
|
|
259
|
-
|
260
|
-
let (:boot_time_success_stdout) { 'boot bad' }
|
317
|
+
expect(instance).not_to receive(:sleep)
|
261
318
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
319
|
+
expect { instance.reboot }.to raise_error(Beaker::Host::RebootWarning, /Found no valid times in .*/)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
context 'current time' do
|
324
|
+
let (:boot_time_success_stdout) { 'boot bad' }
|
267
325
|
|
268
|
-
|
326
|
+
it 'raises a reboot failure' do
|
327
|
+
expect(instance).to receive(:exec).with(:shutdown_command_stub, anything).and_return(response).once
|
328
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).once
|
329
|
+
# allow the second boot_time and the hash arguments in exec, repeated 10 times by default
|
330
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_success_response).at_least(:once)
|
331
|
+
|
332
|
+
expect { instance.reboot(10,9,1) }.to raise_error(Beaker::Host::RebootWarning, /Found no valid times in .*/)
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
269
336
|
end
|
270
337
|
end
|
271
338
|
end
|
272
339
|
end
|
273
340
|
end
|
274
341
|
|
275
|
-
context '
|
276
|
-
|
277
|
-
|
342
|
+
context 'system did not reboot' do
|
343
|
+
check_cmd_output.each do |check_os, cmd_opts|
|
344
|
+
cmd_opts.each do |cmd_name, cmd_outputs|
|
345
|
+
context "on '#{check_os}' with the '#{cmd_name}' command" do
|
346
|
+
let (:boot_time_initial_stdout) { cmd_outputs[:initial] }
|
347
|
+
let (:boot_time_success_stdout) { cmd_outputs[:initial] }
|
278
348
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
349
|
+
it 'raises RebootFailure' do
|
350
|
+
expect(instance).to receive(:sleep).with(sleep_time)
|
351
|
+
# bypass shutdown command itself
|
352
|
+
expect(instance).to receive( :exec ).with(:shutdown_command_stub, anything).and_return(response).once
|
283
353
|
|
284
|
-
|
285
|
-
|
286
|
-
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_success_response).exactly(18).times
|
354
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).once
|
355
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_success_response).once
|
287
356
|
|
288
|
-
|
289
|
-
|
357
|
+
expect { instance.reboot }.to raise_error(Beaker::Host::RebootFailure, /Boot time did not reset/)
|
358
|
+
end
|
290
359
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_success_response).exactly(10).times
|
360
|
+
it 'raises RebootFailure if the number of retries is changed' do
|
361
|
+
expect(instance).to receive(:sleep).with(sleep_time)
|
362
|
+
# bypass shutdown command itself
|
363
|
+
expect(instance).to receive( :exec ).with(:shutdown_command_stub, anything).and_return(response).once
|
364
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_initial_response).once
|
365
|
+
expect(instance).to receive( :exec ).with(:boot_time_command_stub, anything).and_return(boot_time_success_response).once
|
298
366
|
|
299
|
-
|
367
|
+
expect { instance.reboot(wait_time=sleep_time, max_connection_tries=9, boot_time_retries=10) }.to raise_error(Beaker::Host::RebootFailure, /Boot time did not reset/)
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
300
371
|
end
|
301
372
|
end
|
302
|
-
|
303
373
|
end
|
304
374
|
|
305
375
|
describe '#enable_remote_rsyslog' do
|
@@ -313,40 +383,32 @@ module Beaker
|
|
313
383
|
|
314
384
|
end
|
315
385
|
|
316
|
-
describe '#
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
it 'parses variation 2 of uptime string' do
|
321
|
-
expect(instance.parse_uptime("8:03 up 52 days, 20:47, 3 users, load averages: 1.36 1.42 1.40")).to be == "52 days, 20:47"
|
322
|
-
end
|
323
|
-
it 'parses variation 3 of uptime string' do
|
324
|
-
expect(instance.parse_uptime("22:19 up 54 days, 1 min, 4 users, load averages: 2.08 2.06 2.27")).to be == "54 days, 1 min"
|
386
|
+
describe '#which' do
|
387
|
+
before do
|
388
|
+
allow(instance).to receive(:execute)
|
389
|
+
.with(where_command, :accept_all_exit_codes => true).and_return(result)
|
325
390
|
end
|
326
|
-
it 'parses variation 4 of uptime string' do
|
327
|
-
expect(instance.parse_uptime("18:44:45 up 5 min, 0 users, load average: 0.14, 0.11, 0.05")).to be == "5 min"
|
328
|
-
end
|
329
|
-
it 'parses solaris\'s "just up" without time message' do
|
330
|
-
opts['platform'] = 'solaris-11-x86_64'
|
331
|
-
expect(instance.parse_uptime("10:05am up 0 users, load average: 0.66, 0.14, 0.05")).to be == "0 min"
|
332
|
-
end
|
333
|
-
end
|
334
391
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
expect(instance.uptime_int("54 days, 1 min")).to be == 77761
|
392
|
+
context 'when only the environment variable PATH is used' do
|
393
|
+
let(:where_command) { "which ruby" }
|
394
|
+
let(:result) { "/usr/bin/ruby.exe" }
|
395
|
+
|
396
|
+
it 'returns the correct path' do
|
397
|
+
response = instance.which('ruby')
|
398
|
+
|
399
|
+
expect(response).to eq(result)
|
344
400
|
end
|
345
|
-
it 'parses time segment variation 4 into a minute value' do
|
346
|
-
expect(instance.uptime_int("54 days")).to be == 77760
|
347
401
|
end
|
348
|
-
|
349
|
-
|
402
|
+
|
403
|
+
context 'when command is not found' do
|
404
|
+
let(:where_command) { "which unknown" }
|
405
|
+
let(:result) { '' }
|
406
|
+
|
407
|
+
it 'return empty string if command is not found' do
|
408
|
+
response = instance.which('unknown')
|
409
|
+
|
410
|
+
expect(response).to eq(result)
|
411
|
+
end
|
350
412
|
end
|
351
413
|
end
|
352
414
|
end
|