ztk 3.0.4 → 3.1.0
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/lib/ztk/profiler/core.rb +8 -3
- data/lib/ztk/version.rb +1 -1
- data/spec/ztk/ansi_spec.rb +3 -3
- data/spec/ztk/background_spec.rb +22 -22
- data/spec/ztk/base_spec.rb +1 -1
- data/spec/ztk/benchmark_spec.rb +13 -20
- data/spec/ztk/command_spec.rb +48 -61
- data/spec/ztk/config_spec.rb +16 -9
- data/spec/ztk/locator_spec.rb +3 -3
- data/spec/ztk/logger_spec.rb +40 -35
- data/spec/ztk/parallel_spec.rb +20 -20
- data/spec/ztk/profiler_spec.rb +100 -0
- data/spec/ztk/rescue_retry_spec.rb +18 -18
- data/spec/ztk/spinner_spec.rb +3 -3
- data/spec/ztk/ssh_spec.rb +87 -548
- data/spec/ztk/tcp_socket_check_spec.rb +11 -11
- data/spec/ztk/template_spec.rb +14 -13
- data/spec/ztk/ui_spec.rb +9 -9
- data/spec/ztk/version_spec.rb +2 -2
- metadata +4 -2
@@ -27,7 +27,7 @@ describe ZTK::RescueRetry do
|
|
27
27
|
describe "class" do
|
28
28
|
|
29
29
|
it "should be ZTK::RescueRetry" do
|
30
|
-
subject.
|
30
|
+
expect(subject).to be ZTK::RescueRetry
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -35,42 +35,42 @@ describe ZTK::RescueRetry do
|
|
35
35
|
describe "behaviour" do
|
36
36
|
|
37
37
|
it "should throw an exception if executed without a block" do
|
38
|
-
|
38
|
+
expect do
|
39
39
|
ZTK::RescueRetry.try(:tries => 5)
|
40
|
-
|
40
|
+
end.to raise_error ZTK::RescueRetryError
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should retry on all exceptions by default if one is not supplied" do
|
44
44
|
$counter = 0
|
45
|
-
|
45
|
+
expect do
|
46
46
|
ZTK::RescueRetry.try(:tries => 3) do
|
47
47
|
$counter += 1
|
48
48
|
raise "TestException"
|
49
49
|
end
|
50
|
-
|
51
|
-
$counter.
|
50
|
+
end.to raise_error "TestException"
|
51
|
+
expect($counter).to be == 3
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should retry on supplied exception" do
|
55
55
|
$counter = 0
|
56
|
-
|
56
|
+
expect do
|
57
57
|
ZTK::RescueRetry.try(:tries => 3, :on => EOFError) do
|
58
58
|
$counter += 1
|
59
59
|
raise EOFError
|
60
60
|
end
|
61
|
-
|
62
|
-
$counter.
|
61
|
+
end.to raise_error EOFError
|
62
|
+
expect($counter).to be == 3
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should not retry on exception if it does not match the supplied exception" do
|
66
66
|
$counter = 0
|
67
|
-
|
67
|
+
expect do
|
68
68
|
ZTK::RescueRetry.try(:tries => 3, :on => EOFError) do
|
69
69
|
$counter += 1
|
70
70
|
raise "TestException"
|
71
71
|
end
|
72
|
-
|
73
|
-
$counter.
|
72
|
+
end.to raise_error "TestException"
|
73
|
+
expect($counter).to be == 1
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should call our lambda when it catches an exception and retries" do
|
@@ -78,25 +78,25 @@ describe ZTK::RescueRetry do
|
|
78
78
|
on_retry_m = lambda { |exception|
|
79
79
|
$counter += 1
|
80
80
|
}
|
81
|
-
|
81
|
+
expect do
|
82
82
|
ZTK::RescueRetry.try(:tries => 3, :on => EOFError, :on_retry => on_retry_m) do
|
83
83
|
raise EOFError
|
84
84
|
end
|
85
|
-
|
86
|
-
$counter.
|
85
|
+
end.to raise_error EOFError
|
86
|
+
expect($counter).to be == 2
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should not retry exceptions that are ignored" do
|
90
90
|
$counter = 0
|
91
91
|
|
92
|
-
|
92
|
+
expect do
|
93
93
|
ZTK::RescueRetry.try(:tries => 3, :raise => EOFError) do
|
94
94
|
$counter += 1
|
95
95
|
raise EOFError
|
96
96
|
end
|
97
|
-
|
97
|
+
end.to raise_error EOFError
|
98
98
|
|
99
|
-
$counter.
|
99
|
+
expect($counter).to be == 1
|
100
100
|
end
|
101
101
|
|
102
102
|
end
|
data/spec/ztk/spinner_spec.rb
CHANGED
@@ -27,7 +27,7 @@ describe ZTK::Spinner do
|
|
27
27
|
describe "class" do
|
28
28
|
|
29
29
|
it "should be ZTK::Spinner" do
|
30
|
-
subject.
|
30
|
+
expect(subject).to be ZTK::Spinner
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -35,9 +35,9 @@ describe ZTK::Spinner do
|
|
35
35
|
describe "behaviour" do
|
36
36
|
|
37
37
|
it "should throw an exception if executed without a block" do
|
38
|
-
|
38
|
+
expect do
|
39
39
|
ZTK::Spinner.spin
|
40
|
-
|
40
|
+
end.to raise_error ZTK::SpinnerError
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
data/spec/ztk/ssh_spec.rb
CHANGED
@@ -22,15 +22,9 @@ require "spec_helper"
|
|
22
22
|
|
23
23
|
describe ZTK::SSH do
|
24
24
|
|
25
|
-
|
26
|
-
@ui = ZTK::UI.new(
|
27
|
-
:stdout => StringIO.new,
|
28
|
-
:stderr => StringIO.new,
|
29
|
-
:stdin => StringIO.new
|
30
|
-
)
|
31
|
-
end
|
25
|
+
let(:ui) { ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new, :stdin => StringIO.new) }
|
32
26
|
|
33
|
-
subject { ZTK::SSH.new
|
27
|
+
subject { ZTK::SSH.new }
|
34
28
|
|
35
29
|
describe "class" do
|
36
30
|
|
@@ -40,485 +34,105 @@ describe ZTK::SSH do
|
|
40
34
|
|
41
35
|
end
|
42
36
|
|
43
|
-
|
44
|
-
describe "direct SSH behaviour" do
|
45
|
-
|
46
|
-
describe "execute" do
|
47
|
-
|
48
|
-
it "should be able to connect to 127.0.0.1 as the current user and execute a command (your key must be in ssh-agent)" do
|
49
|
-
subject.config do |config|
|
50
|
-
config.ui = @ui
|
51
|
-
|
52
|
-
config.user = ENV["USER"]
|
53
|
-
config.host_name = "127.0.0.1"
|
54
|
-
end
|
55
|
-
|
56
|
-
data = %x(hostname).chomp
|
57
|
-
|
58
|
-
status = subject.exec("hostname")
|
59
|
-
status.exit_code.should == 0
|
60
|
-
@ui.stdout.rewind
|
61
|
-
@ui.stdout.read.chomp.should == data
|
62
|
-
|
63
|
-
expect(subject.close).to be true
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should timeout after the period specified" do
|
67
|
-
subject.config do |config|
|
68
|
-
config.ui = @ui
|
69
|
-
|
70
|
-
config.user = ENV["USER"]
|
71
|
-
config.host_name = "127.0.0.1"
|
72
|
-
config.timeout = WAIT_SMALL
|
73
|
-
end
|
74
|
-
hostname = %x(hostname).chomp
|
75
|
-
lambda { subject.exec("hostname ; sleep 10") }.should raise_error ZTK::SSHError
|
76
|
-
|
77
|
-
expect(subject.close).to be true
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should throw an exception if the exit status is not as expected" do
|
81
|
-
subject.config do |config|
|
82
|
-
config.ui = @ui
|
83
|
-
|
84
|
-
config.user = ENV["USER"]
|
85
|
-
config.host_name = "127.0.0.1"
|
86
|
-
end
|
87
|
-
lambda { subject.exec("/bin/bash -c 'exit 64'") }.should raise_error ZTK::SSHError
|
88
|
-
|
89
|
-
expect(subject.close).to be true
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should return a instance of an OpenStruct object" do
|
93
|
-
subject.config do |config|
|
94
|
-
config.ui = @ui
|
95
|
-
|
96
|
-
config.user = ENV["USER"]
|
97
|
-
config.host_name = "127.0.0.1"
|
98
|
-
end
|
99
|
-
result = subject.exec(%q{echo "Hello World"})
|
100
|
-
result.should be_an_instance_of OpenStruct
|
101
|
-
|
102
|
-
expect(subject.close).to be true
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should return the exit code" do
|
106
|
-
subject.config do |config|
|
107
|
-
config.ui = @ui
|
108
|
-
|
109
|
-
config.user = ENV["USER"]
|
110
|
-
config.host_name = "127.0.0.1"
|
111
|
-
end
|
112
|
-
data = 64
|
113
|
-
|
114
|
-
result = subject.exec(%Q{/bin/bash -c 'exit #{data}'}, :exit_code => data)
|
115
|
-
result.exit_code.should == data
|
116
|
-
|
117
|
-
expect(subject.close).to be true
|
118
|
-
end
|
37
|
+
[ :direct, :proxy ].each do |connection_type|
|
119
38
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
config.host_name = "127.0.0.1"
|
126
|
-
end
|
127
|
-
data = "Hello World @ #{Time.now.utc}"
|
39
|
+
before(:each) do
|
40
|
+
subject.config do |config|
|
41
|
+
config.ui = ui
|
42
|
+
config.user = ENV["USER"]
|
43
|
+
config.host_name = "127.0.0.1"
|
128
44
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
expect(subject.close).to be true
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should allow us to change the expected exit code" do
|
136
|
-
subject.config do |config|
|
137
|
-
config.ui = @ui
|
138
|
-
|
139
|
-
config.user = ENV["USER"]
|
140
|
-
config.host_name = "127.0.0.1"
|
141
|
-
end
|
142
|
-
data = 32
|
143
|
-
result = subject.exec(%Q{/bin/bash -c 'exit #{data}'}, :exit_code => data)
|
144
|
-
|
145
|
-
expect(subject.close).to be true
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should allow us to execute a bootstrap script" do
|
149
|
-
subject.config do |config|
|
150
|
-
config.ui = @ui
|
151
|
-
|
152
|
-
config.user = ENV["USER"]
|
153
|
-
config.host_name = "127.0.0.1"
|
154
|
-
end
|
155
|
-
data = "Hello World @ #{Time.now.utc}"
|
156
|
-
|
157
|
-
result = subject.bootstrap(<<-EOBOOTSTRAP)
|
158
|
-
echo "#{data}" >&1
|
159
|
-
EOBOOTSTRAP
|
160
|
-
|
161
|
-
expect(result.output).to match(/#{data}/)
|
162
|
-
|
163
|
-
expect(subject.close).to be true
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should allow us to write a file" do
|
167
|
-
subject.config do |config|
|
168
|
-
config.ui = @ui
|
169
|
-
|
170
|
-
config.user = ENV["USER"]
|
171
|
-
config.host_name = "127.0.0.1"
|
172
|
-
end
|
173
|
-
data = "Hello World @ #{Time.now.utc}"
|
174
|
-
test_filename = File.join("", "tmp", "test_file.txt")
|
175
|
-
|
176
|
-
subject.file(:target => test_filename) do |f|
|
177
|
-
f.write(data)
|
178
|
-
end
|
179
|
-
|
180
|
-
result = subject.exec(%Q{cat #{test_filename}})
|
181
|
-
|
182
|
-
expect(result.output).to match(/#{data}/)
|
183
|
-
|
184
|
-
expect(subject.close).to be true
|
185
|
-
end
|
186
|
-
|
187
|
-
describe "stdout" do
|
188
|
-
|
189
|
-
it "should capture STDOUT (with PTY) and send it to the STDOUT pipe" do
|
190
|
-
subject.config do |config|
|
191
|
-
config.ui = @ui
|
192
|
-
|
193
|
-
config.user = ENV["USER"]
|
194
|
-
config.host_name = "127.0.0.1"
|
195
|
-
end
|
196
|
-
data = "Hello World @ #{Time.now.utc}"
|
197
|
-
|
198
|
-
subject.exec(%Q{echo "#{data}" >&1})
|
199
|
-
|
200
|
-
@ui.stdout.rewind
|
201
|
-
expect(@ui.stdout.read).to match(/#{data}/)
|
202
|
-
|
203
|
-
@ui.stderr.rewind
|
204
|
-
expect(@ui.stderr.read).to be_empty
|
205
|
-
|
206
|
-
@ui.stdin.rewind
|
207
|
-
expect(@ui.stdin.read).to be_empty
|
208
|
-
|
209
|
-
expect(subject.close).to be true
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should capture STDOUT (without PTY) and send it to the STDOUT pipe" do
|
213
|
-
subject.config do |config|
|
214
|
-
config.ui = @ui
|
215
|
-
|
216
|
-
config.user = ENV["USER"]
|
217
|
-
config.host_name = "127.0.0.1"
|
218
|
-
|
219
|
-
config.request_pty = false
|
220
|
-
end
|
221
|
-
data = "Hello World @ #{Time.now.utc}"
|
222
|
-
|
223
|
-
subject.exec(%Q{echo "#{data}" >&1})
|
224
|
-
|
225
|
-
@ui.stdout.rewind
|
226
|
-
expect(@ui.stdout.read).to match(/#{data}/)
|
227
|
-
|
228
|
-
@ui.stderr.rewind
|
229
|
-
expect(@ui.stderr.read).to be_empty
|
230
|
-
|
231
|
-
@ui.stdin.rewind
|
232
|
-
expect(@ui.stdin.read).to be_empty
|
233
|
-
|
234
|
-
expect(subject.close).to be true
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
describe "stderr" do
|
240
|
-
|
241
|
-
it "should capture STDERR (with PTY) and send it to the STDOUT pipe" do
|
242
|
-
subject.config do |config|
|
243
|
-
config.ui = @ui
|
244
|
-
|
245
|
-
config.user = ENV["USER"]
|
246
|
-
config.host_name = "127.0.0.1"
|
247
|
-
end
|
248
|
-
data = "Hello World @ #{Time.now.utc}"
|
249
|
-
|
250
|
-
subject.exec(%Q{echo "#{data}" >&2})
|
251
|
-
|
252
|
-
@ui.stdout.rewind
|
253
|
-
expect(@ui.stdout.read).to match(/#{data}/)
|
254
|
-
|
255
|
-
@ui.stderr.rewind
|
256
|
-
expect(@ui.stderr.read).to be_empty
|
257
|
-
|
258
|
-
@ui.stdin.rewind
|
259
|
-
expect(@ui.stdin.read).to be_empty
|
260
|
-
|
261
|
-
expect(subject.close).to be true
|
262
|
-
end
|
263
|
-
|
264
|
-
it "should capture STDERR (without PTY) and send it to the STDERR pipe" do
|
265
|
-
subject.config do |config|
|
266
|
-
config.ui = @ui
|
267
|
-
|
268
|
-
config.user = ENV["USER"]
|
269
|
-
config.host_name = "127.0.0.1"
|
270
|
-
|
271
|
-
config.request_pty = false
|
272
|
-
end
|
273
|
-
data = "Hello World @ #{Time.now.utc}"
|
274
|
-
|
275
|
-
subject.exec(%Q{echo "#{data}" >&2})
|
276
|
-
|
277
|
-
@ui.stdout.rewind
|
278
|
-
expect(@ui.stdout.read).to be_empty
|
279
|
-
|
280
|
-
@ui.stderr.rewind
|
281
|
-
expect(@ui.stderr.read).to match(/#{data}/)
|
282
|
-
|
283
|
-
@ui.stdin.rewind
|
284
|
-
expect(@ui.stdin.read).to be_empty
|
285
|
-
|
286
|
-
expect(subject.close).to be true
|
287
|
-
end
|
288
|
-
|
289
|
-
end
|
290
|
-
|
291
|
-
end
|
292
|
-
|
293
|
-
describe "upload" do
|
294
|
-
|
295
|
-
[true, false].each do |use_scp|
|
296
|
-
it "should be able to upload a file to 127.0.0.1 as the current user using #{use_scp ? 'scp' : 'sftp'} (your key must be in ssh-agent)" do
|
297
|
-
subject.config do |config|
|
298
|
-
config.ui = @ui
|
299
|
-
|
300
|
-
config.user = ENV["USER"]
|
301
|
-
config.host_name = "127.0.0.1"
|
302
|
-
end
|
303
|
-
|
304
|
-
data = "Hello World @ #{Time.now.utc}"
|
305
|
-
|
306
|
-
remote_temp = Tempfile.new('remote')
|
307
|
-
remote_file = File.join(ZTK::Locator.root, "tmp", File.basename(remote_temp.path.dup))
|
308
|
-
remote_temp.close
|
309
|
-
File.exists?(remote_file) && File.delete(remote_file)
|
310
|
-
|
311
|
-
local_temp = Tempfile.new('local')
|
312
|
-
local_file = File.join(ZTK::Locator.root, "tmp", File.basename(local_temp.path.dup))
|
313
|
-
local_temp.close
|
314
|
-
if RUBY_VERSION < "1.9.3"
|
315
|
-
File.open(local_file, 'w') do |file|
|
316
|
-
file.puts(data)
|
317
|
-
end
|
318
|
-
else
|
319
|
-
IO.write(local_file, data)
|
320
|
-
end
|
321
|
-
|
322
|
-
File.exists?(remote_file).should == false
|
323
|
-
subject.upload(local_file, remote_file, :use_scp => use_scp)
|
324
|
-
File.exists?(remote_file).should == true
|
325
|
-
|
326
|
-
File.exists?(remote_file) && File.delete(remote_file)
|
327
|
-
File.exists?(local_file) && File.delete(local_file)
|
328
|
-
|
329
|
-
expect(subject.close).to be true
|
45
|
+
if connection_type == :proxy
|
46
|
+
config.proxy_user = ENV["USER"]
|
47
|
+
config.proxy_host_name = "127.0.0.1"
|
330
48
|
end
|
331
49
|
end
|
332
|
-
|
333
50
|
end
|
334
51
|
|
335
|
-
describe "
|
52
|
+
describe "#console (#{connection_type})" do
|
336
53
|
|
337
|
-
|
338
|
-
|
339
|
-
subject.config do |config|
|
340
|
-
config.ui = @ui
|
54
|
+
it "should execute a console" do
|
55
|
+
expect(Kernel).to receive(:exec)
|
341
56
|
|
342
|
-
|
343
|
-
config.host_name = "127.0.0.1"
|
344
|
-
end
|
345
|
-
|
346
|
-
data = "Hello World @ #{Time.now.utc}"
|
347
|
-
|
348
|
-
local_temp = Tempfile.new('local')
|
349
|
-
local_file = File.join(ZTK::Locator.root, "tmp", File.basename(local_temp.path.dup))
|
350
|
-
local_temp.close
|
351
|
-
File.exists?(local_file) && File.delete(local_file)
|
352
|
-
|
353
|
-
remote_temp = Tempfile.new('remote')
|
354
|
-
remote_file = File.join(ZTK::Locator.root, "tmp", File.basename(remote_temp.path.dup))
|
355
|
-
remote_temp.close
|
356
|
-
if RUBY_VERSION < "1.9.3"
|
357
|
-
File.open(remote_file, 'w') do |file|
|
358
|
-
file.puts(data)
|
359
|
-
end
|
360
|
-
else
|
361
|
-
IO.write(remote_file, data)
|
362
|
-
end
|
363
|
-
|
364
|
-
File.exists?(local_file).should == false
|
365
|
-
subject.download(remote_file, local_file, :use_scp => use_scp)
|
366
|
-
File.exists?(local_file).should == true
|
367
|
-
|
368
|
-
File.exists?(local_file) && File.delete(local_file)
|
369
|
-
File.exists?(remote_file) && File.delete(remote_file)
|
370
|
-
|
371
|
-
expect(subject.close).to be true
|
372
|
-
end
|
57
|
+
subject.console
|
373
58
|
end
|
374
59
|
|
375
60
|
end
|
376
61
|
|
377
|
-
|
378
|
-
|
379
|
-
describe "proxy SSH behaviour" do
|
380
|
-
|
381
|
-
describe "execute" do
|
382
|
-
|
383
|
-
it "should be able to proxy through 127.0.0.1, connecting to 127.0.0.1 as the current user and execute a command (your key must be in ssh-agent)" do
|
384
|
-
subject.config do |config|
|
385
|
-
config.ui = @ui
|
386
|
-
|
387
|
-
config.user = ENV["USER"]
|
388
|
-
config.host_name = "127.0.0.1"
|
389
|
-
config.proxy_user = ENV["USER"]
|
390
|
-
config.proxy_host_name = "127.0.0.1"
|
391
|
-
end
|
62
|
+
describe "#execute (#{connection_type})" do
|
392
63
|
|
393
|
-
|
64
|
+
it "should be able to connect to 127.0.0.1 as the current user and execute a command (your key must be in ssh-agent)" do
|
65
|
+
data = %x(hostname).chomp
|
394
66
|
|
395
67
|
status = subject.exec("hostname")
|
396
|
-
status.exit_code.
|
397
|
-
@ui.stdout.rewind
|
398
|
-
@ui.stdout.read.chomp.should == data
|
68
|
+
expect(status.exit_code).to be == 0
|
399
69
|
|
400
|
-
|
70
|
+
ui.stdout.rewind
|
71
|
+
expect(ui.stdout.read.chomp).to match(data)
|
72
|
+
|
73
|
+
expect(subject.close).to be == true
|
401
74
|
end
|
402
75
|
|
403
76
|
it "should timeout after the period specified" do
|
404
|
-
subject.config
|
405
|
-
config.ui = @ui
|
77
|
+
subject.config.timeout = WAIT_SMALL
|
406
78
|
|
407
|
-
|
408
|
-
config.host_name = "127.0.0.1"
|
409
|
-
config.proxy_user = ENV["USER"]
|
410
|
-
config.proxy_host_name = "127.0.0.1"
|
411
|
-
config.timeout = WAIT_SMALL
|
412
|
-
end
|
413
|
-
hostname = %x(hostname).chomp
|
414
|
-
lambda { subject.exec("hostname ; sleep 10") }.should raise_error ZTK::SSHError
|
79
|
+
expect{ subject.exec("sleep 10") }.to raise_error ZTK::SSHError
|
415
80
|
|
416
|
-
expect(subject.close).to be true
|
81
|
+
expect(subject.close).to be == true
|
417
82
|
end
|
418
83
|
|
419
84
|
it "should throw an exception if the exit status is not as expected" do
|
420
|
-
subject.
|
421
|
-
config.ui = @ui
|
85
|
+
expect{ subject.exec("exit 42") }.to raise_error ZTK::SSHError
|
422
86
|
|
423
|
-
|
424
|
-
config.host_name = "127.0.0.1"
|
425
|
-
config.proxy_user = ENV["USER"]
|
426
|
-
config.proxy_host_name = "127.0.0.1"
|
427
|
-
end
|
428
|
-
lambda { subject.exec("/bin/bash -c 'exit 64'") }.should raise_error ZTK::SSHError
|
429
|
-
|
430
|
-
expect(subject.close).to be true
|
87
|
+
expect(subject.close).to be == true
|
431
88
|
end
|
432
89
|
|
433
90
|
it "should return a instance of an OpenStruct object" do
|
434
|
-
subject.
|
435
|
-
|
436
|
-
|
437
|
-
config.user = ENV["USER"]
|
438
|
-
config.host_name = "127.0.0.1"
|
439
|
-
config.proxy_user = ENV["USER"]
|
440
|
-
config.proxy_host_name = "127.0.0.1"
|
441
|
-
end
|
442
|
-
result = subject.exec(%q{echo "Hello World"})
|
443
|
-
result.should be_an_instance_of OpenStruct
|
91
|
+
result = subject.exec(%{echo "Hello World"})
|
92
|
+
expect(result).to be_an_instance_of OpenStruct
|
444
93
|
|
445
|
-
expect(subject.close).to be true
|
94
|
+
expect(subject.close).to be == true
|
446
95
|
end
|
447
96
|
|
448
97
|
it "should return the exit code" do
|
449
|
-
subject.config do |config|
|
450
|
-
config.ui = @ui
|
451
|
-
|
452
|
-
config.user = ENV["USER"]
|
453
|
-
config.host_name = "127.0.0.1"
|
454
|
-
config.proxy_user = ENV["USER"]
|
455
|
-
config.proxy_host_name = "127.0.0.1"
|
456
|
-
end
|
457
98
|
data = 64
|
458
99
|
|
459
|
-
result = subject.exec(%
|
460
|
-
result.exit_code.
|
100
|
+
result = subject.exec(%{exit #{data}}, :exit_code => data)
|
101
|
+
expect(result.exit_code).to be == data
|
461
102
|
|
462
|
-
expect(subject.close).to be true
|
103
|
+
expect(subject.close).to be == true
|
463
104
|
end
|
464
105
|
|
465
106
|
it "should return the output" do
|
466
|
-
subject.config do |config|
|
467
|
-
config.ui = @ui
|
468
|
-
|
469
|
-
config.user = ENV["USER"]
|
470
|
-
config.host_name = "127.0.0.1"
|
471
|
-
config.proxy_user = ENV["USER"]
|
472
|
-
config.proxy_host_name = "127.0.0.1"
|
473
|
-
end
|
474
107
|
data = "Hello World @ #{Time.now.utc}"
|
475
108
|
|
476
109
|
result = subject.exec(%Q{echo "#{data}"})
|
477
|
-
result.output.match(data)
|
110
|
+
expect(result.output).to match(data)
|
478
111
|
|
479
|
-
expect(subject.close).to be true
|
112
|
+
expect(subject.close).to be == true
|
480
113
|
end
|
481
114
|
|
482
115
|
it "should allow us to change the expected exit code" do
|
483
|
-
subject.config do |config|
|
484
|
-
config.ui = @ui
|
485
|
-
|
486
|
-
config.user = ENV["USER"]
|
487
|
-
config.host_name = "127.0.0.1"
|
488
|
-
config.proxy_user = ENV["USER"]
|
489
|
-
config.proxy_host_name = "127.0.0.1"
|
490
|
-
end
|
491
116
|
data = 32
|
492
|
-
result = subject.exec(%Q{/bin/bash -c 'exit #{data}'}, :exit_code => data)
|
493
117
|
|
494
|
-
|
118
|
+
result = subject.exec(%{exit #{data}}, :exit_code => data)
|
119
|
+
expect(result.exit_code).to be == data
|
120
|
+
|
121
|
+
expect(subject.close).to be == true
|
495
122
|
end
|
496
123
|
|
497
124
|
it "should allow us to execute a bootstrap script" do
|
498
|
-
subject.config do |config|
|
499
|
-
config.ui = @ui
|
500
|
-
|
501
|
-
config.user = ENV["USER"]
|
502
|
-
config.host_name = "127.0.0.1"
|
503
|
-
end
|
504
125
|
data = "Hello World @ #{Time.now.utc}"
|
505
126
|
|
506
127
|
result = subject.bootstrap(<<-EOBOOTSTRAP)
|
507
128
|
echo "#{data}" >&1
|
508
129
|
EOBOOTSTRAP
|
130
|
+
expect(result.output.chomp).to match(data)
|
509
131
|
|
510
|
-
expect(
|
511
|
-
|
512
|
-
expect(subject.close).to be true
|
132
|
+
expect(subject.close).to be == true
|
513
133
|
end
|
514
134
|
|
515
135
|
it "should allow us to write a file" do
|
516
|
-
subject.config do |config|
|
517
|
-
config.ui = @ui
|
518
|
-
|
519
|
-
config.user = ENV["USER"]
|
520
|
-
config.host_name = "127.0.0.1"
|
521
|
-
end
|
522
136
|
data = "Hello World @ #{Time.now.utc}"
|
523
137
|
test_filename = File.join("", "tmp", "test_file.txt")
|
524
138
|
|
@@ -526,140 +140,74 @@ EOBOOTSTRAP
|
|
526
140
|
f.write(data)
|
527
141
|
end
|
528
142
|
|
529
|
-
result = subject.exec(%
|
143
|
+
result = subject.exec(%{cat #{test_filename}})
|
144
|
+
expect(result.output.chomp).to match(data)
|
530
145
|
|
531
|
-
expect(
|
532
|
-
|
533
|
-
expect(subject.close).to be true
|
146
|
+
expect(subject.close).to be == true
|
534
147
|
end
|
535
148
|
|
536
|
-
|
537
|
-
|
538
|
-
it "should capture STDOUT (with PTY) and send it to the STDOUT pipe" do
|
539
|
-
subject.config do |config|
|
540
|
-
config.ui = @ui
|
149
|
+
end #execute
|
541
150
|
|
542
|
-
|
543
|
-
config.host_name = "127.0.0.1"
|
544
|
-
config.proxy_user = ENV["USER"]
|
545
|
-
config.proxy_host_name = "127.0.0.1"
|
546
|
-
end
|
547
|
-
data = "Hello World @ #{Time.now.utc}"
|
151
|
+
describe "#ui (#{connection_type})" do
|
548
152
|
|
549
|
-
|
153
|
+
describe "#stdout (#{connection_type})" do
|
550
154
|
|
551
|
-
|
552
|
-
expect(@ui.stdout.read).to match(/#{data}/)
|
155
|
+
[true, false].each do |request_pty|
|
553
156
|
|
554
|
-
|
555
|
-
|
157
|
+
it "should capture STDOUT #{request_pty ? "with" : "without"} PTY and send it to the STDOUT pipe" do
|
158
|
+
subject.config.request_pty = request_pty
|
159
|
+
data = "Hello World @ #{Time.now.utc}"
|
556
160
|
|
557
|
-
|
558
|
-
expect(@ui.stdin.read).to be_empty
|
161
|
+
subject.exec(%{echo "#{data}" >&1})
|
559
162
|
|
560
|
-
|
561
|
-
|
163
|
+
ui.stdout.rewind
|
164
|
+
expect(ui.stdout.read).to match(data)
|
562
165
|
|
563
|
-
|
564
|
-
|
565
|
-
config.ui = @ui
|
166
|
+
ui.stderr.rewind
|
167
|
+
expect(ui.stderr.read).to be_empty
|
566
168
|
|
567
|
-
|
568
|
-
|
569
|
-
config.proxy_user = ENV["USER"]
|
570
|
-
config.proxy_host_name = "127.0.0.1"
|
169
|
+
ui.stdin.rewind
|
170
|
+
expect(ui.stdin.read).to be_empty
|
571
171
|
|
572
|
-
|
172
|
+
expect(subject.close).to be == true
|
573
173
|
end
|
574
|
-
data = "Hello World @ #{Time.now.utc}"
|
575
|
-
|
576
|
-
subject.exec(%Q{echo "#{data}" >&1})
|
577
|
-
|
578
|
-
@ui.stdout.rewind
|
579
|
-
expect(@ui.stdout.read).to match(/#{data}/)
|
580
174
|
|
581
|
-
@ui.stderr.rewind
|
582
|
-
expect(@ui.stderr.read).to be_empty
|
583
|
-
|
584
|
-
@ui.stdin.rewind
|
585
|
-
expect(@ui.stdin.read).to be_empty
|
586
|
-
|
587
|
-
expect(subject.close).to be true
|
588
175
|
end
|
589
176
|
|
590
|
-
end
|
591
|
-
|
592
|
-
describe "stderr" do
|
593
|
-
|
594
|
-
it "should capture STDERR (with PTY) and send it to the STDOUT pipe" do
|
595
|
-
subject.config do |config|
|
596
|
-
config.ui = @ui
|
597
|
-
|
598
|
-
config.user = ENV["USER"]
|
599
|
-
config.host_name = "127.0.0.1"
|
600
|
-
config.proxy_user = ENV["USER"]
|
601
|
-
config.proxy_host_name = "127.0.0.1"
|
602
|
-
end
|
603
|
-
data = "Hello World @ #{Time.now.utc}"
|
177
|
+
end #stdout
|
604
178
|
|
605
|
-
|
179
|
+
describe "#stderr (#{connection_type})" do
|
606
180
|
|
607
|
-
|
608
|
-
expect(@ui.stdout.read).to match(/#{data}/)
|
181
|
+
[true, false].each do |request_pty|
|
609
182
|
|
610
|
-
|
611
|
-
|
183
|
+
it "should capture STDERR #{request_pty ? "with" : "without"} PTY and send it to the #{request_pty ? "STDOUT" : "STDERR"} pipe" do
|
184
|
+
subject.config.request_pty = request_pty
|
185
|
+
data = "Hello World @ #{Time.now.utc}"
|
612
186
|
|
613
|
-
|
614
|
-
expect(@ui.stdin.read).to be_empty
|
187
|
+
subject.exec(%{echo "#{data}" >&2})
|
615
188
|
|
616
|
-
|
617
|
-
|
189
|
+
ui.stdout.rewind
|
190
|
+
expect(ui.stdout.read).to (request_pty ? match(data) : be_empty)
|
618
191
|
|
619
|
-
|
620
|
-
|
621
|
-
config.ui = @ui
|
192
|
+
ui.stderr.rewind
|
193
|
+
expect(ui.stderr.read).to (request_pty ? be_empty : match(data))
|
622
194
|
|
623
|
-
|
624
|
-
|
625
|
-
config.proxy_user = ENV["USER"]
|
626
|
-
config.proxy_host_name = "127.0.0.1"
|
195
|
+
ui.stdin.rewind
|
196
|
+
expect(ui.stdin.read).to be_empty
|
627
197
|
|
628
|
-
|
198
|
+
expect(subject.close).to be == true
|
629
199
|
end
|
630
|
-
data = "Hello World @ #{Time.now.utc}"
|
631
|
-
|
632
|
-
subject.exec(%Q{echo "#{data}" >&2})
|
633
|
-
|
634
|
-
@ui.stdout.rewind
|
635
|
-
expect(@ui.stdout.read).to be_empty
|
636
200
|
|
637
|
-
@ui.stderr.rewind
|
638
|
-
expect(@ui.stderr.read).to match(/#{data}/)
|
639
|
-
|
640
|
-
@ui.stdin.rewind
|
641
|
-
expect(@ui.stdin.read).to be_empty
|
642
|
-
|
643
|
-
expect(subject.close).to be true
|
644
201
|
end
|
645
202
|
|
646
|
-
end
|
203
|
+
end #stderr
|
647
204
|
|
648
|
-
end
|
205
|
+
end #ui
|
649
206
|
|
650
|
-
describe "upload" do
|
207
|
+
describe "#upload (#{connection_type})" do
|
651
208
|
|
652
209
|
[true, false].each do |use_scp|
|
653
|
-
it "should be able to upload a file to 127.0.0.1 as the current user #{use_scp ? 'scp' : 'sftp'} (your key must be in ssh-agent)" do
|
654
|
-
subject.config do |config|
|
655
|
-
config.ui = @ui
|
656
|
-
|
657
|
-
config.user = ENV["USER"]
|
658
|
-
config.host_name = "127.0.0.1"
|
659
|
-
config.proxy_user = ENV["USER"]
|
660
|
-
config.proxy_host_name = "127.0.0.1"
|
661
|
-
end
|
662
|
-
|
210
|
+
it "should be able to upload a file to 127.0.0.1 as the current user using #{use_scp ? 'scp' : 'sftp'} (your key must be in ssh-agent)" do
|
663
211
|
data = "Hello World @ #{Time.now.utc}"
|
664
212
|
|
665
213
|
remote_temp = Tempfile.new('remote')
|
@@ -678,32 +226,23 @@ EOBOOTSTRAP
|
|
678
226
|
IO.write(local_file, data)
|
679
227
|
end
|
680
228
|
|
681
|
-
File.exists?(remote_file).
|
229
|
+
expect(File.exists?(remote_file)).to be false
|
682
230
|
subject.upload(local_file, remote_file, :use_scp => use_scp)
|
683
|
-
File.exists?(remote_file).
|
231
|
+
expect(File.exists?(remote_file)).to be == true
|
684
232
|
|
685
233
|
File.exists?(remote_file) && File.delete(remote_file)
|
686
234
|
File.exists?(local_file) && File.delete(local_file)
|
687
235
|
|
688
|
-
expect(subject.close).to be true
|
236
|
+
expect(subject.close).to be == true
|
689
237
|
end
|
690
238
|
end
|
691
239
|
|
692
|
-
end
|
240
|
+
end #upload
|
693
241
|
|
694
|
-
describe "download" do
|
242
|
+
describe "#download (#{connection_type})" do
|
695
243
|
|
696
244
|
[true, false].each do |use_scp|
|
697
245
|
it "should be able to download a file from 127.0.0.1 as the current user using #{use_scp ? 'scp' : 'sftp'} (your key must be in ssh-agent)" do
|
698
|
-
subject.config do |config|
|
699
|
-
config.ui = @ui
|
700
|
-
|
701
|
-
config.user = ENV["USER"]
|
702
|
-
config.host_name = "127.0.0.1"
|
703
|
-
config.proxy_user = ENV["USER"]
|
704
|
-
config.proxy_host_name = "127.0.0.1"
|
705
|
-
end
|
706
|
-
|
707
246
|
data = "Hello World @ #{Time.now.utc}"
|
708
247
|
|
709
248
|
local_temp = Tempfile.new('local')
|
@@ -722,18 +261,18 @@ EOBOOTSTRAP
|
|
722
261
|
IO.write(remote_file, data)
|
723
262
|
end
|
724
263
|
|
725
|
-
File.exists?(local_file).
|
264
|
+
expect(File.exists?(local_file)).to be false
|
726
265
|
subject.download(remote_file, local_file, :use_scp => use_scp)
|
727
|
-
File.exists?(local_file).
|
266
|
+
expect(File.exists?(local_file)).to be == true
|
728
267
|
|
729
268
|
File.exists?(local_file) && File.delete(local_file)
|
730
269
|
File.exists?(remote_file) && File.delete(remote_file)
|
731
270
|
|
732
|
-
expect(subject.close).to be true
|
271
|
+
expect(subject.close).to be == true
|
733
272
|
end
|
734
273
|
end
|
735
274
|
|
736
|
-
end
|
275
|
+
end #download
|
737
276
|
|
738
277
|
end
|
739
278
|
|