public
Description: Pure Ruby implementation of an SFTP (protocols 1-6) client
Homepage: http://rubyforge.org/projects/net-ssh
Clone URL: git://github.com/jamis/net-sftp.git
Add tests on the synchronous versions of the SFTP operation methods
jamis (author)
Thu Mar 13 14:09:13 -0700 2008
commit  24b25f0b5d79369cc54f2f6291b2f64b01180e0c
tree    693530b181ef02b8c2e4864398f743af716c6b72
parent  5771cca6376148b67d66b8bc00cd159056094a03
...
495
496
497
498
499
 
 
500
501
502
...
628
629
630
 
 
 
631
632
633
...
495
496
497
 
 
498
499
500
501
502
...
628
629
630
631
632
633
634
635
636
0
@@ -495,8 +495,8 @@ module Net; module SFTP
0
       # return the Response object for the request.
0
       #
0
       # sftp.rmdir!("/path/to/directory")
0
- def rmdir!(path, attrs={}, &callback)
0
- wait_for(rmdir(path, attrs, &callback))
0
+ def rmdir!(path, &callback)
0
+ wait_for(rmdir(path, &callback))
0
       end
0
 
0
       # :call-seq:
0
@@ -628,6 +628,9 @@ module Net; module SFTP
0
       # point to the path +existing_path+.
0
       #
0
       # sftp.link("/path/to/symlink", "/path/to/file", true).wait
0
+ #
0
+ # Note that #link is only available for SFTP protocol 6 and higher. You
0
+ # can use #symlink for protocols 3 and higher.
0
       def link(new_link_path, existing_path, symlink=true, &callback)
0
         request :link, new_link_path, existing_path, symlink, &callback
0
       end
...
62
63
64
 
 
 
 
 
 
 
 
 
 
 
 
 
65
66
67
...
71
72
73
 
 
 
 
 
 
 
 
 
 
74
75
76
...
83
84
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
87
88
...
94
95
96
 
 
 
 
 
 
 
 
 
 
97
98
99
...
129
130
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
133
134
...
164
165
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
168
169
...
191
192
193
 
 
 
 
 
 
 
 
 
 
194
195
196
...
218
219
220
 
 
 
 
 
 
 
 
 
 
221
222
223
...
227
228
229
 
 
 
 
 
 
 
 
 
 
230
231
232
...
236
237
238
 
 
 
 
 
 
 
 
 
 
 
 
 
239
240
241
...
245
246
247
 
 
 
 
 
 
 
 
 
 
248
249
250
...
254
255
256
 
 
 
 
 
 
 
 
 
 
257
258
259
...
263
264
265
 
 
 
 
 
 
 
 
 
 
266
267
268
...
272
273
274
 
 
 
 
 
 
 
 
 
 
275
276
277
...
307
308
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
311
312
...
338
339
340
 
 
 
 
 
 
 
 
 
 
341
342
343
...
351
352
353
 
 
 
 
 
 
 
 
 
 
354
355
356
...
373
374
375
 
 
 
 
 
 
 
 
 
 
376
377
378
...
386
387
388
 
 
 
 
 
 
 
 
 
 
389
390
391
...
399
400
401
 
 
 
 
 
 
 
 
 
 
402
403
404
...
412
413
414
415
416
 
 
 
 
 
 
 
 
417
418
419
...
435
436
437
 
 
 
 
 
 
 
 
 
 
 
 
 
438
439
440
...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
...
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
...
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
...
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
...
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
...
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
...
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
...
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
...
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
...
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
...
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
...
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
...
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
...
646
647
648
 
 
649
650
651
652
653
654
655
656
657
658
659
...
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
0
@@ -62,6 +62,19 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_successful_open("/path/to/file", "r", :permissions => 0765)
0
   end
0
 
0
+ def test_open_bang_should_block_and_return_handle
0
+ expect_open("/path/to/file", "r", nil)
0
+ handle = assert_synchronous_command(:open!, "/path/to/file", "r")
0
+ assert_equal "handle", handle
0
+ end
0
+
0
+ def test_open_bang_should_block_and_raise_exception_on_error
0
+ expect_open("/path/to/file", "r", nil, :fail => 5)
0
+ assert_raises(Net::SFTP::StatusException) do
0
+ assert_synchronous_command(:open!, "/path/to/file", "r")
0
+ end
0
+ end
0
+
0
   def test_close_should_send_close_request_and_invoke_callback
0
     expect_sftp_session do |channel|
0
       channel.sends_packet(FXP_CLOSE, :long, 0, :string, "handle")
0
@@ -71,6 +84,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:close, "handle") { |r| assert r.ok? }
0
   end
0
 
0
+ def test_close_bang_should_block_and_return_response
0
+ expect_sftp_session do |channel|
0
+ channel.sends_packet(FXP_CLOSE, :long, 0, :string, "handle")
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:close!, "handle")
0
+ assert response.ok?
0
+ end
0
+
0
   def test_read_should_send_read_request_and_invoke_callback
0
     expect_sftp_session do |channel|
0
       channel.sends_packet(FXP_READ, :long, 0, :string, "handle", :int64, 512123, :long, 1024)
0
@@ -83,6 +106,26 @@ class SessionTest < Net::SFTP::TestCase
0
     end
0
   end
0
 
0
+ def test_read_bang_should_block_and_return_data
0
+ expect_sftp_session do |channel|
0
+ channel.sends_packet(FXP_READ, :long, 0, :string, "handle", :int64, 512123, :long, 1024)
0
+ channel.gets_packet(FXP_DATA, :long, 0, :string, "this is some data!")
0
+ end
0
+
0
+ data = assert_synchronous_command(:read!, "handle", 512123, 1024)
0
+ assert_equal "this is some data!", data
0
+ end
0
+
0
+ def test_read_bang_should_block_and_return_nil_on_eof
0
+ expect_sftp_session do |channel|
0
+ channel.sends_packet(FXP_READ, :long, 0, :string, "handle", :int64, 512123, :long, 1024)
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 1)
0
+ end
0
+
0
+ data = assert_synchronous_command(:read!, "handle", 512123, 1024)
0
+ assert_nil data
0
+ end
0
+
0
   def test_write_should_send_write_request_and_invoke_callback
0
     expect_sftp_session do |channel|
0
       channel.sends_packet(FXP_WRITE, :long, 0, :string, "handle", :int64, 512123, :string, "this is some data!")
0
@@ -94,6 +137,16 @@ class SessionTest < Net::SFTP::TestCase
0
     end
0
   end
0
 
0
+ def test_write_bang_should_block_and_return_response
0
+ expect_sftp_session do |channel|
0
+ channel.sends_packet(FXP_WRITE, :long, 0, :string, "handle", :int64, 512123, :string, "this is some data!")
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:write!, "handle", 512123, "this is some data!")
0
+ assert response.ok?
0
+ end
0
+
0
   def test_v1_lstat_should_send_lstat_request_and_invoke_callback
0
     expect_sftp_session :server_version => 1 do |channel|
0
       channel.sends_packet(FXP_LSTAT, :long, 0, :string, "/path/to/file")
0
@@ -129,6 +182,22 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:lstat, "/path/to/file", 0x1)
0
   end
0
 
0
+ def test_lstat_bang_should_block_and_return_attrs
0
+ expect_sftp_session :server_version => 1 do |channel|
0
+ channel.sends_packet(FXP_LSTAT, :long, 0, :string, "/path/to/file")
0
+ channel.gets_packet(FXP_ATTRS, :long, 0, :long, 0xF, :int64, 123456, :long, 1, :long, 2, :long, 0765, :long, 123456789, :long, 234567890)
0
+ end
0
+
0
+ attrs = assert_synchronous_command(:lstat!, "/path/to/file")
0
+
0
+ assert_equal 123456, attrs.size
0
+ assert_equal 1, attrs.uid
0
+ assert_equal 2, attrs.gid
0
+ assert_equal 0765, attrs.permissions
0
+ assert_equal 123456789, attrs.atime
0
+ assert_equal 234567890, attrs.mtime
0
+ end
0
+
0
   def test_v1_fstat_should_send_fstat_request_and_invoke_callback
0
     expect_sftp_session :server_version => 1 do |channel|
0
       channel.sends_packet(FXP_FSTAT, :long, 0, :string, "handle")
0
@@ -164,6 +233,22 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:fstat, "handle", 0x1)
0
   end
0
 
0
+ def test_fstat_bang_should_block_and_return_attrs
0
+ expect_sftp_session :server_version => 1 do |channel|
0
+ channel.sends_packet(FXP_FSTAT, :long, 0, :string, "handle")
0
+ channel.gets_packet(FXP_ATTRS, :long, 0, :long, 0xF, :int64, 123456, :long, 1, :long, 2, :long, 0765, :long, 123456789, :long, 234567890)
0
+ end
0
+
0
+ attrs = assert_synchronous_command(:fstat!, "handle")
0
+
0
+ assert_equal 123456, attrs.size
0
+ assert_equal 1, attrs.uid
0
+ assert_equal 2, attrs.gid
0
+ assert_equal 0765, attrs.permissions
0
+ assert_equal 123456789, attrs.atime
0
+ assert_equal 234567890, attrs.mtime
0
+ end
0
+
0
   def test_v1_setstat_should_send_v1_attributes
0
     expect_sftp_session :server_version => 1 do |channel|
0
       channel.sends_packet(FXP_SETSTAT, :long, 0, :string, "/path/to/file", :long, 0xc, :long, 0765, :long, 1234567890, :long, 2345678901)
0
@@ -191,6 +276,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:setstat, "/path/to/file", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901, :mime_type => "text/plain")
0
   end
0
 
0
+ def test_setstat_bang_should_block_and_return_response
0
+ expect_sftp_session :server_version => 1 do |channel|
0
+ channel.sends_packet(FXP_SETSTAT, :long, 0, :string, "/path/to/file", :long, 0xc, :long, 0765, :long, 1234567890, :long, 2345678901)
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:setstat!, "/path/to/file", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901)
0
+ assert response.ok?
0
+ end
0
+
0
   def test_v1_fsetstat_should_send_v1_attributes
0
     expect_sftp_session :server_version => 1 do |channel|
0
       channel.sends_packet(FXP_FSETSTAT, :long, 0, :string, "handle", :long, 0xc, :long, 0765, :long, 1234567890, :long, 2345678901)
0
@@ -218,6 +313,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:fsetstat, "handle", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901, :mime_type => "text/plain")
0
   end
0
 
0
+ def test_fsetstat_bang_should_block_and_return_response
0
+ expect_sftp_session :server_version => 1 do |channel|
0
+ channel.sends_packet(FXP_FSETSTAT, :long, 0, :string, "handle", :long, 0xc, :long, 0765, :long, 1234567890, :long, 2345678901)
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:fsetstat!, "handle", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901)
0
+ assert response.ok?
0
+ end
0
+
0
   def test_opendir_should_send_opendir_request_and_invoke_callback
0
     expect_sftp_session do |channel|
0
       channel.sends_packet(FXP_OPENDIR, :long, 0, :string, "/path/to/dir")
0
@@ -227,6 +332,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:opendir, "/path/to/dir")
0
   end
0
 
0
+ def test_opendir_bang_should_block_and_return_handle
0
+ expect_sftp_session do |channel|
0
+ channel.sends_packet(FXP_OPENDIR, :long, 0, :string, "/path/to/dir")
0
+ channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle")
0
+ end
0
+
0
+ handle = assert_synchronous_command(:opendir!, "/path/to/dir")
0
+ assert_equal "handle", handle
0
+ end
0
+
0
   def test_readdir_should_send_readdir_request_and_invoke_callback
0
     expect_sftp_session do |channel|
0
       channel.sends_packet(FXP_READDIR, :long, 0, :string, "handle")
0
@@ -236,6 +351,19 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:readdir, "handle") { |r| assert r.eof? }
0
   end
0
 
0
+ def test_readdir_bang_should_block_and_return_names_array
0
+ expect_sftp_session :server_version => 1 do |channel|
0
+ channel.sends_packet(FXP_READDIR, :long, 0, :string, "handle")
0
+ channel.gets_packet(FXP_NAME, :long, 0, :long, 2,
0
+ :string, "first", :string, "longfirst", :long, 0x0,
0
+ :string, "next", :string, "longnext", :long, 0x0)
0
+ end
0
+
0
+ names = assert_synchronous_command(:readdir!, "handle")
0
+ assert_equal 2, names.length
0
+ assert_equal %w(first next), names.map { |n| n.name }
0
+ end
0
+
0
   def test_remove_should_send_remove_packet
0
     expect_sftp_session do |channel|
0
       channel.sends_packet(FXP_REMOVE, :long, 0, :string, "/path/to/file")
0
@@ -245,6 +373,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:remove, "/path/to/file")
0
   end
0
 
0
+ def test_remove_bang_should_block_and_return_response
0
+ expect_sftp_session do |channel|
0
+ channel.sends_packet(FXP_REMOVE, :long, 0, :string, "/path/to/file")
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:remove!, "/path/to/file")
0
+ assert response.ok?
0
+ end
0
+
0
   def test_mkdir_should_send_mkdir_packet
0
     expect_sftp_session do |channel|
0
       channel.sends_packet(FXP_MKDIR, :long, 0, :string, "/path/to/dir", :long, 0x4, :byte, 1, :long, 0765)
0
@@ -254,6 +392,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:mkdir, "/path/to/dir", :permissions => 0765)
0
   end
0
 
0
+ def test_mkdir_bang_should_block_and_return_response
0
+ expect_sftp_session do |channel|
0
+ channel.sends_packet(FXP_MKDIR, :long, 0, :string, "/path/to/dir", :long, 0x4, :byte, 1, :long, 0765)
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:mkdir!, "/path/to/dir", :permissions => 0765)
0
+ assert response.ok?
0
+ end
0
+
0
   def test_rmdir_should_send_rmdir_packet
0
     expect_sftp_session do |channel|
0
       channel.sends_packet(FXP_RMDIR, :long, 0, :string, "/path/to/dir")
0
@@ -263,6 +411,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:rmdir, "/path/to/dir")
0
   end
0
 
0
+ def test_rmdir_bang_should_block_and_return_response
0
+ expect_sftp_session do |channel|
0
+ channel.sends_packet(FXP_RMDIR, :long, 0, :string, "/path/to/dir")
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:rmdir!, "/path/to/dir")
0
+ assert response.ok?
0
+ end
0
+
0
   def test_realpath_should_send_realpath_packet
0
     expect_sftp_session do |channel|
0
       channel.sends_packet(FXP_REALPATH, :long, 0, :string, "/path/to/dir")
0
@@ -272,6 +430,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:realpath, "/path/to/dir")
0
   end
0
 
0
+ def test_realpath_bang_should_block_and_return_names_item
0
+ expect_sftp_session do |channel|
0
+ channel.sends_packet(FXP_REALPATH, :long, 0, :string, "/path/to/dir")
0
+ channel.gets_packet(FXP_NAME, :long, 0, :long, 1, :string, "dir", :long, 0x0, :long, 2)
0
+ end
0
+
0
+ name = assert_synchronous_command(:realpath!, "/path/to/dir")
0
+ assert_equal "dir", name.name
0
+ end
0
+
0
   def test_v1_stat_should_send_stat_request_and_invoke_callback
0
     expect_sftp_session :server_version => 1 do |channel|
0
       channel.sends_packet(FXP_STAT, :long, 0, :string, "/path/to/file")
0
@@ -307,6 +475,22 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:stat, "/path/to/file", 0x1)
0
   end
0
 
0
+ def test_stat_bang_should_block_and_return_attrs
0
+ expect_sftp_session :server_version => 1 do |channel|
0
+ channel.sends_packet(FXP_STAT, :long, 0, :string, "/path/to/file")
0
+ channel.gets_packet(FXP_ATTRS, :long, 0, :long, 0xF, :int64, 123456, :long, 1, :long, 2, :long, 0765, :long, 123456789, :long, 234567890)
0
+ end
0
+
0
+ attrs = assert_synchronous_command(:stat!, "/path/to/file")
0
+
0
+ assert_equal 123456, attrs.size
0
+ assert_equal 1, attrs.uid
0
+ assert_equal 2, attrs.gid
0
+ assert_equal 0765, attrs.permissions
0
+ assert_equal 123456789, attrs.atime
0
+ assert_equal 234567890, attrs.mtime
0
+ end
0
+
0
   def test_v1_rename_should_be_unimplemented
0
     assert_not_implemented 1, :rename, "from", "to"
0
   end
0
@@ -338,6 +522,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:rename, "from", "to", 1)
0
   end
0
 
0
+ def test_rename_bang_should_block_and_return_response
0
+ expect_sftp_session :server_version => 2 do |channel|
0
+ channel.sends_packet(FXP_RENAME, :long, 0, :string, "from", :string, "to")
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:rename!, "from", "to")
0
+ assert response.ok?
0
+ end
0
+
0
   def test_v2_readlink_should_be_unimplemented
0
     assert_not_implemented 2, :readlink, "/path/to/link"
0
   end
0
@@ -351,6 +545,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:readlink, "/path/to/link")
0
   end
0
 
0
+ def test_readlink_bang_should_block_and_return_name
0
+ expect_sftp_session :server_version => 3 do |channel|
0
+ channel.sends_packet(FXP_READLINK, :long, 0, :string, "/path/to/link")
0
+ channel.gets_packet(FXP_NAME, :long, 0, :long, 1, :string, "target", :string, "longtarget", :long, 0x0)
0
+ end
0
+
0
+ name = assert_synchronous_command(:readlink!, "/path/to/link")
0
+ assert_equal "target", name.name
0
+ end
0
+
0
   def test_v2_symlink_should_be_unimplemented
0
     assert_not_implemented 2, :symlink, "/path/to/source", "/path/to/link"
0
   end
0
@@ -373,6 +577,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:symlink, "/path/to/link", "/path/to/source")
0
   end
0
 
0
+ def test_symlink_bang_should_block_and_return_response
0
+ expect_sftp_session :server_version => 3 do |channel|
0
+ channel.sends_packet(FXP_SYMLINK, :long, 0, :string, "/path/to/source", :string, "/path/to/link")
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:symlink!, "/path/to/source", "/path/to/link")
0
+ assert response.ok?
0
+ end
0
+
0
   def test_v5_link_should_be_unimplemented
0
     assert_not_implemented 5, :link, "/path/to/source", "/path/to/link", true
0
   end
0
@@ -386,6 +600,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:link, "/path/to/link", "/path/to/source", true)
0
   end
0
 
0
+ def test_link_bang_should_block_and_return_response
0
+ expect_sftp_session :server_version => 6 do |channel|
0
+ channel.sends_packet(FXP_LINK, :long, 0, :string, "/path/to/link", :string, "/path/to/source", :bool, true)
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:link!, "/path/to/link", "/path/to/source", true)
0
+ assert response.ok?
0
+ end
0
+
0
   def test_v5_block_should_be_unimplemented
0
     assert_not_implemented 5, :block, "handle", 12345, 67890, 0xabcd
0
   end
0
@@ -399,6 +623,16 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:block, "handle", 12345, 67890, 0xabcd)
0
   end
0
 
0
+ def test_block_bang_should_block_and_return_response
0
+ expect_sftp_session :server_version => 6 do |channel|
0
+ channel.sends_packet(FXP_BLOCK, :long, 0, :string, "handle", :int64, 12345, :int64, 67890, :long, 0xabcd)
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:block!, "handle", 12345, 67890, 0xabcd)
0
+ assert response.ok?
0
+ end
0
+
0
   def test_v5_unblock_should_be_unimplemented
0
     assert_not_implemented 5, :unblock, "handle", 12345, 67890
0
   end
0
@@ -412,8 +646,14 @@ class SessionTest < Net::SFTP::TestCase
0
     assert_command_with_callback(:unblock, "handle", 12345, 67890)
0
   end
0
 
0
- def test_send_packet_and_other_methods
0
- flunk "these need to be written yet!"
0
+ def test_unblock_bang_should_block_and_return_response
0
+ expect_sftp_session :server_version => 6 do |channel|
0
+ channel.sends_packet(FXP_UNBLOCK, :long, 0, :string, "handle", :int64, 12345, :int64, 67890)
0
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
0
+ end
0
+
0
+ response = assert_synchronous_command(:unblock!, "handle", 12345, 67890)
0
+ assert response.ok?
0
   end
0
 
0
   private
0
@@ -435,6 +675,19 @@ class SessionTest < Net::SFTP::TestCase
0
       assert called, "expected callback to be invoked, but it wasn't"
0
     end
0
 
0
+ def assert_synchronous_command(command, *args)
0
+ assert_scripted_command do
0
+ sequence = [:start]
0
+ result = sftp.send(command, *args) do |response|
0
+ sequence << :done
0
+ yield response if block_given?
0
+ end
0
+ sequence << :after
0
+ assert_equal [:start, :done, :after], sequence, "expected #{command} to be synchronous"
0
+ return result
0
+ end
0
+ end
0
+
0
     def assert_successful_open(*args)
0
       assert_command_with_callback(:open, *args) do |response|
0
         assert response.ok?

Comments

    No one has commented yet.