0
@@ -62,6 +62,19 @@ class SessionTest < Net::SFTP::TestCase
0
assert_successful_open("/path/to/file", "r", :permissions => 0765)
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
+ 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
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
+ 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
+ response = assert_synchronous_command(:close!, "handle")
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
+ 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
+ data = assert_synchronous_command(:read!, "handle", 512123, 1024)
0
+ assert_equal "this is some data!", data
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
+ data = assert_synchronous_command(:read!, "handle", 512123, 1024)
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
+ 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
+ response = assert_synchronous_command(:write!, "handle", 512123, "this is some data!")
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
+ 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
+ attrs = assert_synchronous_command(:lstat!, "/path/to/file")
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
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
+ 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
+ attrs = assert_synchronous_command(:fstat!, "handle")
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
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
+ 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
+ response = assert_synchronous_command(:setstat!, "/path/to/file", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901)
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
+ 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
+ response = assert_synchronous_command(:fsetstat!, "handle", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901)
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
+ 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
+ handle = assert_synchronous_command(:opendir!, "/path/to/dir")
0
+ assert_equal "handle", handle
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
+ 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
+ names = assert_synchronous_command(:readdir!, "handle")
0
+ assert_equal 2, names.length
0
+ assert_equal %w(first next), names.map { |n| n.name }
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
+ 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
+ response = assert_synchronous_command(:remove!, "/path/to/file")
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
+ 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
+ response = assert_synchronous_command(:mkdir!, "/path/to/dir", :permissions => 0765)
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
+ 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
+ response = assert_synchronous_command(:rmdir!, "/path/to/dir")
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
+ 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
+ name = assert_synchronous_command(:realpath!, "/path/to/dir")
0
+ assert_equal "dir", name.name
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
+ 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
+ attrs = assert_synchronous_command(:stat!, "/path/to/file")
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
def test_v1_rename_should_be_unimplemented
0
assert_not_implemented 1, :rename, "from", "to"
0
@@ -338,6 +522,16 @@ class SessionTest < Net::SFTP::TestCase
0
assert_command_with_callback(:rename, "from", "to", 1)
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
+ response = assert_synchronous_command(:rename!, "from", "to")
0
def test_v2_readlink_should_be_unimplemented
0
assert_not_implemented 2, :readlink, "/path/to/link"
0
@@ -351,6 +545,16 @@ class SessionTest < Net::SFTP::TestCase
0
assert_command_with_callback(:readlink, "/path/to/link")
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
+ name = assert_synchronous_command(:readlink!, "/path/to/link")
0
+ assert_equal "target", name.name
0
def test_v2_symlink_should_be_unimplemented
0
assert_not_implemented 2, :symlink, "/path/to/source", "/path/to/link"
0
@@ -373,6 +577,16 @@ class SessionTest < Net::SFTP::TestCase
0
assert_command_with_callback(:symlink, "/path/to/link", "/path/to/source")
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
+ response = assert_synchronous_command(:symlink!, "/path/to/source", "/path/to/link")
0
def test_v5_link_should_be_unimplemented
0
assert_not_implemented 5, :link, "/path/to/source", "/path/to/link", true
0
@@ -386,6 +600,16 @@ class SessionTest < Net::SFTP::TestCase
0
assert_command_with_callback(:link, "/path/to/link", "/path/to/source", true)
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
+ response = assert_synchronous_command(:link!, "/path/to/link", "/path/to/source", true)
0
def test_v5_block_should_be_unimplemented
0
assert_not_implemented 5, :block, "handle", 12345, 67890, 0xabcd
0
@@ -399,6 +623,16 @@ class SessionTest < Net::SFTP::TestCase
0
assert_command_with_callback(:block, "handle", 12345, 67890, 0xabcd)
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
+ response = assert_synchronous_command(:block!, "handle", 12345, 67890, 0xabcd)
0
def test_v5_unblock_should_be_unimplemented
0
assert_not_implemented 5, :unblock, "handle", 12345, 67890
0
@@ -412,8 +646,14 @@ class SessionTest < Net::SFTP::TestCase
0
assert_command_with_callback(:unblock, "handle", 12345, 67890)
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
+ response = assert_synchronous_command(:unblock!, "handle", 12345, 67890)
0
@@ -435,6 +675,19 @@ class SessionTest < Net::SFTP::TestCase
0
assert called, "expected callback to be invoked, but it wasn't"
0
+ def assert_synchronous_command(command, *args)
0
+ assert_scripted_command do
0
+ result = sftp.send(command, *args) do |response|
0
+ yield response if block_given?
0
+ assert_equal [:start, :done, :after], sequence, "expected #{command} to be synchronous"
0
def assert_successful_open(*args)
0
assert_command_with_callback(:open, *args) do |response|
Comments
No one has commented yet.