test/test_download.rb in net-sftp-2.1.1 vs test/test_download.rb in net-sftp-2.1.2

- old
+ new

@@ -19,10 +19,24 @@ assert_scripted_command { sftp.download(remote, local) } assert_equal text, file.string end + def test_download_file_should_transfer_remote_to_local_in_spite_of_fragmentation + local = "/path/to/local" + remote = "/path/to/remote" + text = "this is some text\n" + + expect_file_transfer(remote, text, :fragment_len => 1) + + file = StringIO.new + File.stubs(:open).with(local, "wb").returns(file) + + assert_scripted_command { sftp.download(remote, local) } + assert_equal text, file.string + end + def test_download_large_file_should_transfer_remote_to_local local = "/path/to/local" remote = "/path/to/remote" text = "0123456789" * 1024 @@ -128,16 +142,16 @@ assert_raises(ArgumentError) { sftp.download("/path/to/remote", StringIO.new, :recursive => true) } end private - def expect_file_transfer(remote, text) + def expect_file_transfer(remote, text, opts={}) expect_sftp_session :server_version => 3 do |channel| channel.sends_packet(FXP_OPEN, :long, 0, :string, remote, :long, 0x01, :long, 0) channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle") channel.sends_packet(FXP_READ, :long, 1, :string, "handle", :int64, 0, :long, 32_000) - channel.gets_packet(FXP_DATA, :long, 1, :string, text) + channel.gets_packet_in_two(opts[:fragment_len], FXP_DATA, :long, 1, :string, text) channel.sends_packet(FXP_READ, :long, 2, :string, "handle", :int64, text.bytesize, :long, 32_000) channel.gets_packet(FXP_STATUS, :long, 2, :long, 1) channel.sends_packet(FXP_CLOSE, :long, 3, :string, "handle") channel.gets_packet(FXP_STATUS, :long, 3, :long, 0) end @@ -158,10 +172,10 @@ channel.sends_packet(FXP_READ, :long, data_packet_count + 1, :string, "handle", :int64, offset, :long, requested_chunk_size) channel.gets_packet(FXP_STATUS, :long, data_packet_count + 1, :long, 1) channel.sends_packet(FXP_CLOSE, :long, data_packet_count + 2, :string, "handle") channel.gets_packet(FXP_STATUS, :long, data_packet_count + 2, :long, 0) end - + file = StringIO.new File.stubs(:open).with(local, "wb").returns(file) return file end \ No newline at end of file