ztk 1.0.11 → 1.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.
@@ -0,0 +1,51 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary@jovelabs.net>
4
+ # Copyright: Copyright (c) Zachary Patten
5
+ # License: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ ################################################################################
20
+
21
+ require "spec_helper"
22
+
23
+ describe ZTK::Locator do
24
+
25
+ subject { ZTK::Locator }
26
+
27
+ describe "class" do
28
+
29
+ it "should be ZTK::Locator" do
30
+ subject.should be ZTK::Locator
31
+ end
32
+
33
+ describe "methods" do
34
+
35
+ describe "#find" do
36
+
37
+ it "should find root" do
38
+ subject.find("root").should == "/root"
39
+ end
40
+
41
+ it "should find home" do
42
+ subject.find("home").should == "/home"
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ end
data/spec/ztk/ssh_spec.rb CHANGED
@@ -22,7 +22,15 @@ require "spec_helper"
22
22
 
23
23
  describe ZTK::SSH do
24
24
 
25
- subject { ZTK::SSH.new }
25
+ before(:each) do
26
+ @ui = ZTK::UI.new(
27
+ :stdout => StringIO.new,
28
+ :stderr => StringIO.new,
29
+ :stdin => StringIO.new
30
+ )
31
+ end
32
+
33
+ subject { ZTK::SSH.new(:ui => @ui) }
26
34
 
27
35
  describe "class" do
28
36
 
@@ -39,7 +47,7 @@ describe ZTK::SSH do
39
47
 
40
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
41
49
  subject.config do |config|
42
- config.ui = $ui
50
+ config.ui = @ui
43
51
 
44
52
  config.user = ENV["USER"]
45
53
  config.host_name = "127.0.0.1"
@@ -49,13 +57,13 @@ describe ZTK::SSH do
49
57
 
50
58
  status = subject.exec("hostname")
51
59
  status.exit_code.should == 0
52
- $ui.stdout.rewind
53
- $ui.stdout.read.chomp.should == data
60
+ @ui.stdout.rewind
61
+ @ui.stdout.read.chomp.should == data
54
62
  end
55
63
 
56
64
  it "should timeout after the period specified" do
57
65
  subject.config do |config|
58
- config.ui = $ui
66
+ config.ui = @ui
59
67
 
60
68
  config.user = ENV["USER"]
61
69
  config.host_name = "127.0.0.1"
@@ -67,7 +75,7 @@ describe ZTK::SSH do
67
75
 
68
76
  it "should throw an exception if the exit status is not as expected" do
69
77
  subject.config do |config|
70
- config.ui = $ui
78
+ config.ui = @ui
71
79
 
72
80
  config.user = ENV["USER"]
73
81
  config.host_name = "127.0.0.1"
@@ -77,7 +85,7 @@ describe ZTK::SSH do
77
85
 
78
86
  it "should return a instance of an OpenStruct object" do
79
87
  subject.config do |config|
80
- config.ui = $ui
88
+ config.ui = @ui
81
89
 
82
90
  config.user = ENV["USER"]
83
91
  config.host_name = "127.0.0.1"
@@ -88,7 +96,7 @@ describe ZTK::SSH do
88
96
 
89
97
  it "should return the exit code" do
90
98
  subject.config do |config|
91
- config.ui = $ui
99
+ config.ui = @ui
92
100
 
93
101
  config.user = ENV["USER"]
94
102
  config.host_name = "127.0.0.1"
@@ -101,7 +109,7 @@ describe ZTK::SSH do
101
109
 
102
110
  it "should return the output" do
103
111
  subject.config do |config|
104
- config.ui = $ui
112
+ config.ui = @ui
105
113
 
106
114
  config.user = ENV["USER"]
107
115
  config.host_name = "127.0.0.1"
@@ -114,7 +122,7 @@ describe ZTK::SSH do
114
122
 
115
123
  it "should allow us to change the expected exit code" do
116
124
  subject.config do |config|
117
- config.ui = $ui
125
+ config.ui = @ui
118
126
 
119
127
  config.user = ENV["USER"]
120
128
  config.host_name = "127.0.0.1"
@@ -127,7 +135,7 @@ describe ZTK::SSH do
127
135
 
128
136
  it "should capture STDOUT (with PTY) and send it to the STDOUT pipe" do
129
137
  subject.config do |config|
130
- config.ui = $ui
138
+ config.ui = @ui
131
139
 
132
140
  config.user = ENV["USER"]
133
141
  config.host_name = "127.0.0.1"
@@ -136,19 +144,19 @@ describe ZTK::SSH do
136
144
 
137
145
  subject.exec(%Q{echo "#{data}" -f >&1})
138
146
 
139
- $ui.stdout.rewind
140
- $ui.stdout.read.match(data).should_not be nil
147
+ @ui.stdout.rewind
148
+ @ui.stdout.read.match(data).should_not be nil
141
149
 
142
- $ui.stderr.rewind
143
- $ui.stderr.read.match(data).should be nil
150
+ @ui.stderr.rewind
151
+ @ui.stderr.read.match(data).should be nil
144
152
 
145
- $ui.stdin.rewind
146
- $ui.stdin.read.match(data).should be nil
153
+ @ui.stdin.rewind
154
+ @ui.stdin.read.match(data).should be nil
147
155
  end
148
156
 
149
157
  it "should capture STDOUT (without PTY) and send it to the STDOUT pipe" do
150
158
  subject.config do |config|
151
- config.ui = $ui
159
+ config.ui = @ui
152
160
 
153
161
  config.user = ENV["USER"]
154
162
  config.host_name = "127.0.0.1"
@@ -159,14 +167,14 @@ describe ZTK::SSH do
159
167
 
160
168
  subject.exec(%Q{echo "#{data}" -f >&1})
161
169
 
162
- $ui.stdout.rewind
163
- $ui.stdout.read.match(data).should_not be nil
170
+ @ui.stdout.rewind
171
+ @ui.stdout.read.match(data).should_not be nil
164
172
 
165
- $ui.stderr.rewind
166
- $ui.stderr.read.match(data).should be nil
173
+ @ui.stderr.rewind
174
+ @ui.stderr.read.match(data).should be nil
167
175
 
168
- $ui.stdin.rewind
169
- $ui.stdin.read.match(data).should be nil
176
+ @ui.stdin.rewind
177
+ @ui.stdin.read.match(data).should be nil
170
178
  end
171
179
 
172
180
  end
@@ -175,7 +183,7 @@ describe ZTK::SSH do
175
183
 
176
184
  it "should capture STDERR (with PTY) and send it to the STDOUT pipe" do
177
185
  subject.config do |config|
178
- config.ui = $ui
186
+ config.ui = @ui
179
187
 
180
188
  config.user = ENV["USER"]
181
189
  config.host_name = "127.0.0.1"
@@ -184,19 +192,19 @@ describe ZTK::SSH do
184
192
 
185
193
  subject.exec(%Q{echo "#{data}" -f >&2})
186
194
 
187
- $ui.stdout.rewind
188
- $ui.stdout.read.match(data).should_not be nil
195
+ @ui.stdout.rewind
196
+ @ui.stdout.read.match(data).should_not be nil
189
197
 
190
- $ui.stderr.rewind
191
- $ui.stderr.read.match(data).should be nil
198
+ @ui.stderr.rewind
199
+ @ui.stderr.read.match(data).should be nil
192
200
 
193
- $ui.stdin.rewind
194
- $ui.stdin.read.match(data).should be nil
201
+ @ui.stdin.rewind
202
+ @ui.stdin.read.match(data).should be nil
195
203
  end
196
204
 
197
205
  it "should capture STDERR (without PTY) and send it to the STDERR pipe" do
198
206
  subject.config do |config|
199
- config.ui = $ui
207
+ config.ui = @ui
200
208
 
201
209
  config.user = ENV["USER"]
202
210
  config.host_name = "127.0.0.1"
@@ -207,14 +215,14 @@ describe ZTK::SSH do
207
215
 
208
216
  subject.exec(%Q{echo "#{data}" -f >&2})
209
217
 
210
- $ui.stdout.rewind
211
- $ui.stdout.read.match(data).should be nil
218
+ @ui.stdout.rewind
219
+ @ui.stdout.read.match(data).should be nil
212
220
 
213
- $ui.stderr.rewind
214
- $ui.stderr.read.match(data).should_not be nil
221
+ @ui.stderr.rewind
222
+ @ui.stderr.read.match(data).should_not be nil
215
223
 
216
- $ui.stdin.rewind
217
- $ui.stdin.read.match(data).should be nil
224
+ @ui.stdin.rewind
225
+ @ui.stdin.read.match(data).should be nil
218
226
  end
219
227
 
220
228
  end
@@ -225,7 +233,7 @@ describe ZTK::SSH do
225
233
 
226
234
  it "should be able to upload a file to 127.0.0.1 as the current user (your key must be in ssh-agent)" do
227
235
  subject.config do |config|
228
- config.ui = $ui
236
+ config.ui = @ui
229
237
 
230
238
  config.user = ENV["USER"]
231
239
  config.host_name = "127.0.0.1"
@@ -253,7 +261,7 @@ describe ZTK::SSH do
253
261
 
254
262
  it "should be able to download a file from 127.0.0.1 as the current user (your key must be in ssh-agent)" do
255
263
  subject.config do |config|
256
- config.ui = $ui
264
+ config.ui = @ui
257
265
 
258
266
  config.user = ENV["USER"]
259
267
  config.host_name = "127.0.0.1"
@@ -285,7 +293,7 @@ describe ZTK::SSH do
285
293
 
286
294
  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
287
295
  subject.config do |config|
288
- config.ui = $ui
296
+ config.ui = @ui
289
297
 
290
298
  config.user = ENV["USER"]
291
299
  config.host_name = "127.0.0.1"
@@ -297,13 +305,13 @@ describe ZTK::SSH do
297
305
 
298
306
  status = subject.exec("hostname")
299
307
  status.exit_code.should == 0
300
- $ui.stdout.rewind
301
- $ui.stdout.read.chomp.should == data
308
+ @ui.stdout.rewind
309
+ @ui.stdout.read.chomp.should == data
302
310
  end
303
311
 
304
312
  it "should timeout after the period specified" do
305
313
  subject.config do |config|
306
- config.ui = $ui
314
+ config.ui = @ui
307
315
 
308
316
  config.user = ENV["USER"]
309
317
  config.host_name = "127.0.0.1"
@@ -317,7 +325,7 @@ describe ZTK::SSH do
317
325
 
318
326
  it "should throw an exception if the exit status is not as expected" do
319
327
  subject.config do |config|
320
- config.ui = $ui
328
+ config.ui = @ui
321
329
 
322
330
  config.user = ENV["USER"]
323
331
  config.host_name = "127.0.0.1"
@@ -329,7 +337,7 @@ describe ZTK::SSH do
329
337
 
330
338
  it "should return a instance of an OpenStruct object" do
331
339
  subject.config do |config|
332
- config.ui = $ui
340
+ config.ui = @ui
333
341
 
334
342
  config.user = ENV["USER"]
335
343
  config.host_name = "127.0.0.1"
@@ -342,7 +350,7 @@ describe ZTK::SSH do
342
350
 
343
351
  it "should return the exit code" do
344
352
  subject.config do |config|
345
- config.ui = $ui
353
+ config.ui = @ui
346
354
 
347
355
  config.user = ENV["USER"]
348
356
  config.host_name = "127.0.0.1"
@@ -357,7 +365,7 @@ describe ZTK::SSH do
357
365
 
358
366
  it "should return the output" do
359
367
  subject.config do |config|
360
- config.ui = $ui
368
+ config.ui = @ui
361
369
 
362
370
  config.user = ENV["USER"]
363
371
  config.host_name = "127.0.0.1"
@@ -372,7 +380,7 @@ describe ZTK::SSH do
372
380
 
373
381
  it "should allow us to change the expected exit code" do
374
382
  subject.config do |config|
375
- config.ui = $ui
383
+ config.ui = @ui
376
384
 
377
385
  config.user = ENV["USER"]
378
386
  config.host_name = "127.0.0.1"
@@ -387,7 +395,7 @@ describe ZTK::SSH do
387
395
 
388
396
  it "should capture STDOUT (with PTY) and send it to the STDOUT pipe" do
389
397
  subject.config do |config|
390
- config.ui = $ui
398
+ config.ui = @ui
391
399
 
392
400
  config.user = ENV["USER"]
393
401
  config.host_name = "127.0.0.1"
@@ -398,19 +406,19 @@ describe ZTK::SSH do
398
406
 
399
407
  subject.exec(%Q{echo "#{data}" -f >&1})
400
408
 
401
- $ui.stdout.rewind
402
- $ui.stdout.read.match(data).should_not be nil
409
+ @ui.stdout.rewind
410
+ @ui.stdout.read.match(data).should_not be nil
403
411
 
404
- $ui.stderr.rewind
405
- $ui.stderr.read.match(data).should be nil
412
+ @ui.stderr.rewind
413
+ @ui.stderr.read.match(data).should be nil
406
414
 
407
- $ui.stdin.rewind
408
- $ui.stdin.read.match(data).should be nil
415
+ @ui.stdin.rewind
416
+ @ui.stdin.read.match(data).should be nil
409
417
  end
410
418
 
411
419
  it "should capture STDOUT (without PTY) and send it to the STDOUT pipe" do
412
420
  subject.config do |config|
413
- config.ui = $ui
421
+ config.ui = @ui
414
422
 
415
423
  config.user = ENV["USER"]
416
424
  config.host_name = "127.0.0.1"
@@ -423,14 +431,14 @@ describe ZTK::SSH do
423
431
 
424
432
  subject.exec(%Q{echo "#{data}" -f >&1})
425
433
 
426
- $ui.stdout.rewind
427
- $ui.stdout.read.match(data).should_not be nil
434
+ @ui.stdout.rewind
435
+ @ui.stdout.read.match(data).should_not be nil
428
436
 
429
- $ui.stderr.rewind
430
- $ui.stderr.read.match(data).should be nil
437
+ @ui.stderr.rewind
438
+ @ui.stderr.read.match(data).should be nil
431
439
 
432
- $ui.stdin.rewind
433
- $ui.stdin.read.match(data).should be nil
440
+ @ui.stdin.rewind
441
+ @ui.stdin.read.match(data).should be nil
434
442
  end
435
443
 
436
444
  end
@@ -439,7 +447,7 @@ describe ZTK::SSH do
439
447
 
440
448
  it "should capture STDERR (with PTY) and send it to the STDOUT pipe" do
441
449
  subject.config do |config|
442
- config.ui = $ui
450
+ config.ui = @ui
443
451
 
444
452
  config.user = ENV["USER"]
445
453
  config.host_name = "127.0.0.1"
@@ -450,19 +458,19 @@ describe ZTK::SSH do
450
458
 
451
459
  subject.exec(%Q{echo "#{data}" -f >&2})
452
460
 
453
- $ui.stdout.rewind
454
- $ui.stdout.read.match(data).should_not be nil
461
+ @ui.stdout.rewind
462
+ @ui.stdout.read.match(data).should_not be nil
455
463
 
456
- $ui.stderr.rewind
457
- $ui.stderr.read.match(data).should be nil
464
+ @ui.stderr.rewind
465
+ @ui.stderr.read.match(data).should be nil
458
466
 
459
- $ui.stdin.rewind
460
- $ui.stdin.read.match(data).should be nil
467
+ @ui.stdin.rewind
468
+ @ui.stdin.read.match(data).should be nil
461
469
  end
462
470
 
463
471
  it "should capture STDERR (without PTY) and send it to the STDERR pipe" do
464
472
  subject.config do |config|
465
- config.ui = $ui
473
+ config.ui = @ui
466
474
 
467
475
  config.user = ENV["USER"]
468
476
  config.host_name = "127.0.0.1"
@@ -475,14 +483,14 @@ describe ZTK::SSH do
475
483
 
476
484
  subject.exec(%Q{echo "#{data}" -f >&2})
477
485
 
478
- $ui.stdout.rewind
479
- $ui.stdout.read.match(data).should be nil
486
+ @ui.stdout.rewind
487
+ @ui.stdout.read.match(data).should be nil
480
488
 
481
- $ui.stderr.rewind
482
- $ui.stderr.read.match(data).should_not be nil
489
+ @ui.stderr.rewind
490
+ @ui.stderr.read.match(data).should_not be nil
483
491
 
484
- $ui.stdin.rewind
485
- $ui.stdin.read.match(data).should be nil
492
+ @ui.stdin.rewind
493
+ @ui.stdin.read.match(data).should be nil
486
494
  end
487
495
 
488
496
  end
@@ -493,7 +501,7 @@ describe ZTK::SSH do
493
501
 
494
502
  it "should be able to upload a file to 127.0.0.1 as the current user (your key must be in ssh-agent)" do
495
503
  subject.config do |config|
496
- config.ui = $ui
504
+ config.ui = @ui
497
505
 
498
506
  config.user = ENV["USER"]
499
507
  config.host_name = "127.0.0.1"
@@ -523,7 +531,7 @@ describe ZTK::SSH do
523
531
 
524
532
  it "should be able to download a file from 127.0.0.1 as the current user (your key must be in ssh-agent)" do
525
533
  subject.config do |config|
526
- config.ui = $ui
534
+ config.ui = @ui
527
535
 
528
536
  config.user = ENV["USER"]
529
537
  config.host_name = "127.0.0.1"