redcar 0.3.7.1 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +16 -0
- data/README.md +5 -0
- data/ROADMAP.md +7 -9
- data/Rakefile +55 -22
- data/lib/redcar.rb +12 -6
- data/lib/redcar/installer.rb +119 -44
- data/plugins/application/features/step_definitions/speedbar_steps.rb +62 -0
- data/plugins/application/features/step_definitions/tree_steps.rb +3 -3
- data/plugins/application/features/support/env.rb +2 -1
- data/plugins/application/lib/application/notebook.rb +53 -7
- data/plugins/application/lib/application/speedbar.rb +12 -0
- data/plugins/application/lib/application/tab.rb +16 -5
- data/plugins/application/lib/application/treebook.rb +21 -1
- data/plugins/application_swt/lib/application_swt.rb +12 -2
- data/plugins/application_swt/lib/application_swt/html_tab.rb +4 -0
- data/plugins/application_swt/lib/application_swt/notebook.rb +5 -3
- data/plugins/application_swt/lib/application_swt/speedbar.rb +15 -27
- data/plugins/application_swt/lib/application_swt/swt_wrapper.rb +1 -0
- data/plugins/application_swt/lib/application_swt/tab.rb +1 -0
- data/plugins/application_swt/lib/application_swt/treebook.rb +36 -8
- data/plugins/application_swt/lib/application_swt/window.rb +24 -18
- data/plugins/auto_completer/lib/auto_completer.rb +5 -20
- data/plugins/core/lib/core.rb +7 -4
- data/plugins/core/lib/core/observable_struct.rb +2 -2
- data/plugins/declarations/lib/declarations.rb +3 -17
- data/plugins/document_search/features/search.feature +163 -0
- data/plugins/document_search/features/support/env.rb +4 -0
- data/plugins/document_search/lib/document_search.rb +121 -0
- data/plugins/document_search/plugin.rb +8 -0
- data/plugins/edit_view/features/line_delimiter.feature +7 -0
- data/plugins/edit_view/features/step_definitions/editing_steps.rb +49 -1
- data/plugins/edit_view/features/step_definitions/tab_steps.rb +10 -11
- data/plugins/edit_view/features/switch_tabs.feature +61 -10
- data/plugins/edit_view/lib/edit_view.rb +4 -0
- data/plugins/edit_view/lib/edit_view/document.rb +56 -0
- data/plugins/edit_view/lib/edit_view/document/command.rb +1 -1
- data/plugins/edit_view/lib/edit_view/edit_tab.rb +0 -8
- data/plugins/edit_view_swt/lib/edit_view_swt.rb +4 -0
- data/plugins/html_view/lib/html_controller.rb +19 -1
- data/plugins/html_view/lib/html_view.rb +28 -1
- data/plugins/html_view/lib/html_view/html_tab.rb +10 -1
- data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +3 -1
- data/plugins/project/features/open_directory_tree.feature +3 -3
- data/plugins/project/lib/project.rb +4 -6
- data/plugins/project/lib/project/commands.rb +17 -0
- data/plugins/project/lib/project/dir_controller.rb +2 -1
- data/plugins/project/lib/project/dir_mirror.rb +8 -0
- data/plugins/project/lib/project/manager.rb +2 -0
- data/plugins/project/plugin.rb +2 -1
- data/plugins/project/vendor/net-sftp/Manifest +55 -0
- data/plugins/project/vendor/net-sftp/Rakefile +30 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp.rb +70 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/constants.rb +187 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/errors.rb +39 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/dir.rb +93 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/download.rb +364 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/file.rb +176 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/file_factory.rb +60 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/upload.rb +387 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/packet.rb +21 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol.rb +32 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/attributes.rb +315 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/base.rb +268 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/name.rb +43 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/02/base.rb +31 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/03/base.rb +35 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/attributes.rb +152 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/base.rb +94 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/name.rb +67 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/05/base.rb +66 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/06/attributes.rb +107 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/06/base.rb +63 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/base.rb +50 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/request.rb +91 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/response.rb +76 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/session.rb +951 -0
- data/plugins/project/vendor/net-sftp/lib/net/sftp/version.rb +18 -0
- data/plugins/project/vendor/net-sftp/setup.rb +1331 -0
- data/plugins/project/vendor/net-sftp/test/common.rb +171 -0
- data/plugins/project/vendor/net-sftp/test/protocol/01/test_attributes.rb +97 -0
- data/plugins/project/vendor/net-sftp/test/protocol/01/test_base.rb +210 -0
- data/plugins/project/vendor/net-sftp/test/protocol/01/test_name.rb +27 -0
- data/plugins/project/vendor/net-sftp/test/protocol/02/test_base.rb +26 -0
- data/plugins/project/vendor/net-sftp/test/protocol/03/test_base.rb +27 -0
- data/plugins/project/vendor/net-sftp/test/protocol/04/test_attributes.rb +148 -0
- data/plugins/project/vendor/net-sftp/test/protocol/04/test_base.rb +74 -0
- data/plugins/project/vendor/net-sftp/test/protocol/04/test_name.rb +53 -0
- data/plugins/project/vendor/net-sftp/test/protocol/05/test_base.rb +62 -0
- data/plugins/project/vendor/net-sftp/test/protocol/06/test_attributes.rb +124 -0
- data/plugins/project/vendor/net-sftp/test/protocol/06/test_base.rb +51 -0
- data/plugins/project/vendor/net-sftp/test/protocol/test_base.rb +42 -0
- data/plugins/project/vendor/net-sftp/test/test_all.rb +7 -0
- data/plugins/project/vendor/net-sftp/test/test_dir.rb +47 -0
- data/plugins/project/vendor/net-sftp/test/test_download.rb +252 -0
- data/plugins/project/vendor/net-sftp/test/test_file.rb +159 -0
- data/plugins/project/vendor/net-sftp/test/test_file_factory.rb +48 -0
- data/plugins/project/vendor/net-sftp/test/test_packet.rb +9 -0
- data/plugins/project/vendor/net-sftp/test/test_protocol.rb +17 -0
- data/plugins/project/vendor/net-sftp/test/test_request.rb +71 -0
- data/plugins/project/vendor/net-sftp/test/test_response.rb +53 -0
- data/plugins/project/vendor/net-sftp/test/test_session.rb +741 -0
- data/plugins/project/vendor/net-sftp/test/test_upload.rb +219 -0
- data/plugins/project/vendor/net-ssh/Manifest +110 -0
- data/plugins/project/vendor/net-ssh/Rakefile +85 -0
- data/plugins/project/vendor/net-ssh/Rudyfile +96 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh.rb +215 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/agent.rb +179 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/constants.rb +18 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/key_manager.rb +193 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/abstract.rb +60 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/password.rb +39 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/publickey.rb +92 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/pageant.rb +183 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/session.rb +134 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/buffer.rb +340 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/buffered_io.rb +198 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/config.rb +202 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/channel.rb +630 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/constants.rb +33 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/session.rb +597 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/term.rb +178 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/errors.rb +85 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/key_factory.rb +102 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/known_hosts.rb +129 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/loggable.rb +61 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/packet.rb +102 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/prompt.rb +93 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/command.rb +75 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/errors.rb +14 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/http.rb +94 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/socks4.rb +70 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/socks5.rb +142 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/ruby_compat.rb +43 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/service/forward.rb +288 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test.rb +89 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/channel.rb +129 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/extensions.rb +152 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/kex.rb +44 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/local_packet.rb +51 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/packet.rb +81 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/remote_packet.rb +38 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/script.rb +157 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/test/socket.rb +64 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/algorithms.rb +384 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/cipher_factory.rb +97 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/constants.rb +30 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac.rb +31 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/abstract.rb +79 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/md5.rb +12 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/none.rb +15 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/sha1.rb +13 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/identity_cipher.rb +55 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex.rb +13 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/openssl.rb +128 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/packet_stream.rb +235 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/server_version.rb +71 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/session.rb +276 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/state.rb +206 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/lenient.rb +30 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/null.rb +12 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/strict.rb +53 -0
- data/plugins/project/vendor/net-ssh/lib/net/ssh/version.rb +62 -0
- data/plugins/project/vendor/net-ssh/net-ssh.gemspec +138 -0
- data/plugins/project/vendor/net-ssh/setup.rb +1585 -0
- data/plugins/project/vendor/net-ssh/support/arcfour_check.rb +20 -0
- data/plugins/project/vendor/net-ssh/support/ssh_tunnel_bug.rb +65 -0
- data/plugins/project/vendor/net-ssh/test/README.txt +42 -0
- data/plugins/project/vendor/net-ssh/test/authentication/methods/common.rb +28 -0
- data/plugins/project/vendor/net-ssh/test/authentication/methods/test_abstract.rb +51 -0
- data/plugins/project/vendor/net-ssh/test/authentication/methods/test_hostbased.rb +114 -0
- data/plugins/project/vendor/net-ssh/test/authentication/methods/test_keyboard_interactive.rb +98 -0
- data/plugins/project/vendor/net-ssh/test/authentication/methods/test_password.rb +50 -0
- data/plugins/project/vendor/net-ssh/test/authentication/methods/test_publickey.rb +127 -0
- data/plugins/project/vendor/net-ssh/test/authentication/test_agent.rb +205 -0
- data/plugins/project/vendor/net-ssh/test/authentication/test_key_manager.rb +105 -0
- data/plugins/project/vendor/net-ssh/test/authentication/test_session.rb +93 -0
- data/plugins/project/vendor/net-ssh/test/common.rb +107 -0
- data/plugins/project/vendor/net-ssh/test/configs/eqsign +3 -0
- data/plugins/project/vendor/net-ssh/test/configs/exact_match +8 -0
- data/plugins/project/vendor/net-ssh/test/configs/host_plus +10 -0
- data/plugins/project/vendor/net-ssh/test/configs/multihost +4 -0
- data/plugins/project/vendor/net-ssh/test/configs/nohost +19 -0
- data/plugins/project/vendor/net-ssh/test/configs/numeric_host +4 -0
- data/plugins/project/vendor/net-ssh/test/configs/wild_cards +14 -0
- data/plugins/project/vendor/net-ssh/test/connection/test_channel.rb +467 -0
- data/plugins/project/vendor/net-ssh/test/connection/test_session.rb +488 -0
- data/plugins/project/vendor/net-ssh/test/manual/test_forward.rb +185 -0
- data/plugins/project/vendor/net-ssh/test/test_all.rb +9 -0
- data/plugins/project/vendor/net-ssh/test/test_buffer.rb +336 -0
- data/plugins/project/vendor/net-ssh/test/test_buffered_io.rb +63 -0
- data/plugins/project/vendor/net-ssh/test/test_config.rb +117 -0
- data/plugins/project/vendor/net-ssh/test/test_key_factory.rb +67 -0
- data/plugins/project/vendor/net-ssh/test/transport/hmac/test_md5.rb +39 -0
- data/plugins/project/vendor/net-ssh/test/transport/hmac/test_md5_96.rb +25 -0
- data/plugins/project/vendor/net-ssh/test/transport/hmac/test_none.rb +34 -0
- data/plugins/project/vendor/net-ssh/test/transport/hmac/test_sha1.rb +34 -0
- data/plugins/project/vendor/net-ssh/test/transport/hmac/test_sha1_96.rb +25 -0
- data/plugins/project/vendor/net-ssh/test/transport/kex/test_diffie_hellman_group1_sha1.rb +146 -0
- data/plugins/project/vendor/net-ssh/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +92 -0
- data/plugins/project/vendor/net-ssh/test/transport/test_algorithms.rb +302 -0
- data/plugins/project/vendor/net-ssh/test/transport/test_cipher_factory.rb +213 -0
- data/plugins/project/vendor/net-ssh/test/transport/test_hmac.rb +34 -0
- data/plugins/project/vendor/net-ssh/test/transport/test_identity_cipher.rb +40 -0
- data/plugins/project/vendor/net-ssh/test/transport/test_packet_stream.rb +441 -0
- data/plugins/project/vendor/net-ssh/test/transport/test_server_version.rb +78 -0
- data/plugins/project/vendor/net-ssh/test/transport/test_session.rb +315 -0
- data/plugins/project/vendor/net-ssh/test/transport/test_state.rb +173 -0
- data/plugins/redcar/plugin.rb +3 -1
- data/plugins/redcar/redcar.rb +108 -121
- data/plugins/redcar_debug/lib/redcar_debug.rb +2 -0
- data/plugins/runnables/lib/runnables.rb +80 -23
- data/plugins/runnables/lib/runnables/command_output_controller.rb +102 -0
- data/plugins/runnables/lib/runnables/running_process_checker.rb +34 -0
- data/plugins/runnables/{plugin_no_load.rb → plugin.rb} +2 -1
- data/plugins/runnables/vendor/session-2.4.0/HISTORY +73 -0
- data/plugins/runnables/vendor/session-2.4.0/README +89 -0
- data/plugins/runnables/vendor/session-2.4.0/TODO +3 -0
- data/plugins/runnables/vendor/session-2.4.0/VERSION +1 -0
- data/plugins/runnables/vendor/session-2.4.0/gemspec.rb +22 -0
- data/plugins/runnables/vendor/session-2.4.0/install.rb +143 -0
- data/plugins/runnables/vendor/session-2.4.0/lib/session.rb +757 -0
- data/plugins/runnables/vendor/session-2.4.0/sample/bash.rb +60 -0
- data/plugins/runnables/vendor/session-2.4.0/sample/driver.rb +47 -0
- data/plugins/runnables/vendor/session-2.4.0/sample/session_idl.rb +25 -0
- data/plugins/runnables/vendor/session-2.4.0/sample/session_sh.rb +29 -0
- data/plugins/runnables/vendor/session-2.4.0/sample/sh0.rb +23 -0
- data/plugins/runnables/vendor/session-2.4.0/sample/stdin.rb +17 -0
- data/plugins/runnables/vendor/session-2.4.0/sample/threadtest.rb +42 -0
- data/plugins/runnables/vendor/session-2.4.0/session-2.4.0.gem +0 -0
- data/plugins/runnables/vendor/session-2.4.0/test/session.rb +227 -0
- data/plugins/runnables/views/command_output.html.erb +32 -0
- data/plugins/task_manager/lib/task_manager.rb +2 -0
- data/plugins/textmate/lib/textmate/plist.rb +1 -1
- data/plugins/textmate/lib/textmate/snippet.rb +1 -0
- data/plugins/tree/lib/tree/mirror.rb +8 -1
- data/plugins/tree_view_swt/lib/tree_view_swt.rb +29 -2
- metadata +191 -6
- data/plugins/declarations/TODO +0 -3
- data/plugins/redcar/spec/redcar/redcar_spec.rb +0 -70
- data/plugins/redcar/spec/spec_helper.rb +0 -4
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'common'
|
2
|
+
require 'protocol/05/test_base'
|
3
|
+
|
4
|
+
class Protocol::V06::TestBase < Protocol::V05::TestBase
|
5
|
+
include Net::SFTP::Constants::OpenFlags
|
6
|
+
include Net::SFTP::Constants
|
7
|
+
|
8
|
+
def test_version
|
9
|
+
assert_equal 6, @base.version
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_parse_attrs_packet_should_use_correct_attributes_class
|
13
|
+
Net::SFTP::Protocol::V06::Attributes.expects(:from_buffer).with(:packet).returns(:result)
|
14
|
+
assert_equal({ :attrs => :result }, @base.parse_attrs_packet(:packet))
|
15
|
+
end
|
16
|
+
|
17
|
+
undef test_link_should_raise_not_implemented_error
|
18
|
+
undef test_block_should_raise_not_implemented_error
|
19
|
+
undef test_unblock_should_raise_not_implemented_error
|
20
|
+
undef test_symlink_should_send_symlink_packet
|
21
|
+
|
22
|
+
def test_link_should_send_link_packet
|
23
|
+
@session.expects(:send_packet).with(FXP_LINK, :long, 0, :string, "/path/to/link", :string, "/path/to/file", :bool, true)
|
24
|
+
assert_equal 0, @base.link("/path/to/link", "/path/to/file", true)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_symlink_should_send_link_packet_as_symlink
|
28
|
+
@session.expects(:send_packet).with(FXP_LINK, :long, 0, :string, "/path/to/link", :string, "/path/to/file", :bool, true)
|
29
|
+
assert_equal 0, @base.symlink("/path/to/link", "/path/to/file")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_block_should_send_block_packet
|
33
|
+
@session.expects(:send_packet).with(FXP_BLOCK, :long, 0, :string, "handle", :int64, 1234, :int64, 4567, :long, 0x40)
|
34
|
+
assert_equal 0, @base.block("handle", 1234, 4567, 0x40)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_unblock_should_send_unblock_packet
|
38
|
+
@session.expects(:send_packet).with(FXP_UNBLOCK, :long, 0, :string, "handle", :int64, 1234, :int64, 4567)
|
39
|
+
assert_equal 0, @base.unblock("handle", 1234, 4567)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def driver
|
45
|
+
Net::SFTP::Protocol::V06::Base
|
46
|
+
end
|
47
|
+
|
48
|
+
def attributes
|
49
|
+
Net::SFTP::Protocol::V06::Attributes
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'common'
|
2
|
+
|
3
|
+
class Protocol::TestBase < Net::SFTP::TestCase
|
4
|
+
def setup
|
5
|
+
@base = Net::SFTP::Protocol::Base.new(stub('session', :logger => nil))
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_parse_with_status_packet_should_delegate_to_parse_status_packet
|
9
|
+
packet = stub('packet', :type => FXP_STATUS)
|
10
|
+
@base.expects(:parse_status_packet).with(packet).returns(:result)
|
11
|
+
assert_equal :result, @base.parse(packet)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_parse_with_handle_packet_should_delegate_to_parse_handle_packet
|
15
|
+
packet = stub('packet', :type => FXP_HANDLE)
|
16
|
+
@base.expects(:parse_handle_packet).with(packet).returns(:result)
|
17
|
+
assert_equal :result, @base.parse(packet)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_parse_with_data_packet_should_delegate_to_parse_data_packet
|
21
|
+
packet = stub('packet', :type => FXP_DATA)
|
22
|
+
@base.expects(:parse_data_packet).with(packet).returns(:result)
|
23
|
+
assert_equal :result, @base.parse(packet)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_parse_with_name_packet_should_delegate_to_parse_name_packet
|
27
|
+
packet = stub('packet', :type => FXP_NAME)
|
28
|
+
@base.expects(:parse_name_packet).with(packet).returns(:result)
|
29
|
+
assert_equal :result, @base.parse(packet)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_parse_with_attrs_packet_should_delegate_to_parse_attrs_packet
|
33
|
+
packet = stub('packet', :type => FXP_ATTRS)
|
34
|
+
@base.expects(:parse_attrs_packet).with(packet).returns(:result)
|
35
|
+
assert_equal :result, @base.parse(packet)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_parse_with_unknown_packet_should_raise_exception
|
39
|
+
packet = stub('packet', :type => FXP_WRITE)
|
40
|
+
assert_raises(NotImplementedError) { @base.parse(packet) }
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'common'
|
2
|
+
|
3
|
+
class DirOperationsTest < Net::SFTP::TestCase
|
4
|
+
def setup
|
5
|
+
@sftp = mock("sftp")
|
6
|
+
@dir = Net::SFTP::Operations::Dir.new(@sftp)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_foreach_should_iterate_over_all_entries_in_directory
|
10
|
+
@sftp.expects(:opendir!).with("/path/to/remote").returns("handle")
|
11
|
+
@sftp.expects(:readdir!).with("handle").returns([:e1, :e2, :e3], [:e4, :e5], nil).times(3)
|
12
|
+
@sftp.expects(:close!).with("handle")
|
13
|
+
|
14
|
+
entries = []
|
15
|
+
@dir.foreach("/path/to/remote") { |entry| entries << entry }
|
16
|
+
assert_equal [:e1, :e2, :e3, :e4, :e5], entries
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_entries_should_return_all_entries_in_a_single_array
|
20
|
+
@sftp.expects(:opendir!).with("/path/to/remote").returns("handle")
|
21
|
+
@sftp.expects(:readdir!).with("handle").returns([:e1, :e2, :e3], [:e4, :e5], nil).times(3)
|
22
|
+
@sftp.expects(:close!).with("handle")
|
23
|
+
|
24
|
+
assert_equal [:e1, :e2, :e3, :e4, :e5], @dir.entries("/path/to/remote")
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_glob_should_search_under_path_for_matching_entries
|
28
|
+
@sftp.expects(:opendir!).with("/path/to/remote").returns("handle")
|
29
|
+
@sftp.expects(:opendir!).with("/path/to/remote/e3").returns("handle-e3")
|
30
|
+
@sftp.expects(:opendir!).with("/path/to/remote/e5").returns("handle-e5")
|
31
|
+
@sftp.expects(:readdir!).with("handle").returns([n(".", true), n("..", true), n("e1"), n("e2"), n("e3", true)], [n("e4"), n("e5", true)], nil).times(3)
|
32
|
+
@sftp.expects(:readdir!).with("handle-e3").returns([n(".", true), n("..", true), n("e3e1"), n("e3e2")], nil).times(2)
|
33
|
+
@sftp.expects(:readdir!).with("handle-e5").returns([n(".", true), n("..", true), n("e5e1"), n("e5e2"), n("e5e3")], nil).times(2)
|
34
|
+
@sftp.expects(:close!).with("handle")
|
35
|
+
@sftp.expects(:close!).with("handle-e3")
|
36
|
+
@sftp.expects(:close!).with("handle-e5")
|
37
|
+
|
38
|
+
assert_equal %w(e3/e3e2 e5/e5e2), @dir.glob("/path/to/remote", "**/e?e2").map { |e| e.name }
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def n(name, directory=false)
|
44
|
+
Net::SFTP::Protocol::V01::Name.new(name.to_s, "longname for #{name}",
|
45
|
+
Net::SFTP::Protocol::V01::Attributes.new(:permissions => directory ? 040755 : 0100644))
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
require "common"
|
2
|
+
|
3
|
+
class DownloadTest < Net::SFTP::TestCase
|
4
|
+
def setup
|
5
|
+
prepare_progress!
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_download_file_should_transfer_remote_to_local
|
9
|
+
local = "/path/to/local"
|
10
|
+
remote = "/path/to/remote"
|
11
|
+
text = "this is some text\n"
|
12
|
+
|
13
|
+
expect_file_transfer(remote, text)
|
14
|
+
|
15
|
+
file = StringIO.new
|
16
|
+
File.stubs(:open).with(local, "wb").returns(file)
|
17
|
+
|
18
|
+
assert_scripted_command { sftp.download(remote, local) }
|
19
|
+
assert_equal text, file.string
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_download_large_file_should_transfer_remote_to_local
|
23
|
+
local = "/path/to/local"
|
24
|
+
remote = "/path/to/remote"
|
25
|
+
text = "0123456789" * 1024
|
26
|
+
|
27
|
+
file = prepare_large_file_download(local, remote, text)
|
28
|
+
|
29
|
+
assert_scripted_command { sftp.download(remote, local, :read_size => 1024) }
|
30
|
+
assert_equal text, file.string
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_download_large_file_with_progress_should_report_progress
|
34
|
+
local = "/path/to/local"
|
35
|
+
remote = "/path/to/remote"
|
36
|
+
text = "0123456789" * 1024
|
37
|
+
|
38
|
+
file = prepare_large_file_download(local, remote, text)
|
39
|
+
|
40
|
+
assert_scripted_command do
|
41
|
+
sftp.download(remote, local, :read_size => 1024) do |*args|
|
42
|
+
record_progress(args)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_equal text, file.string
|
47
|
+
|
48
|
+
assert_progress_reported_open :remote => "/path/to/remote"
|
49
|
+
assert_progress_reported_get 0, 1024
|
50
|
+
assert_progress_reported_get 1024, 1024
|
51
|
+
assert_progress_reported_get 2048, 1024
|
52
|
+
assert_progress_reported_get 3072, 1024
|
53
|
+
assert_progress_reported_get 4096, 1024
|
54
|
+
assert_progress_reported_get 5120, 1024
|
55
|
+
assert_progress_reported_get 6144, 1024
|
56
|
+
assert_progress_reported_get 7168, 1024
|
57
|
+
assert_progress_reported_get 8192, 1024
|
58
|
+
assert_progress_reported_get 9216, 1024
|
59
|
+
assert_progress_reported_close
|
60
|
+
assert_progress_reported_finish
|
61
|
+
assert_no_more_reported_events
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_download_directory_should_mirror_directory_locally
|
65
|
+
file1, file2 = prepare_directory_tree_download("/path/to/local", "/path/to/remote")
|
66
|
+
|
67
|
+
assert_scripted_command do
|
68
|
+
sftp.download("/path/to/remote", "/path/to/local", :recursive => true)
|
69
|
+
end
|
70
|
+
|
71
|
+
assert_equal "contents of file1", file1.string
|
72
|
+
assert_equal "contents of file2", file2.string
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_download_directory_with_progress_should_report_progress
|
76
|
+
file1, file2 = prepare_directory_tree_download("/path/to/local", "/path/to/remote")
|
77
|
+
|
78
|
+
assert_scripted_command do
|
79
|
+
sftp.download("/path/to/remote", "/path/to/local", :recursive => true) do |*args|
|
80
|
+
record_progress(args)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
assert_equal "contents of file1", file1.string
|
85
|
+
assert_equal "contents of file2", file2.string
|
86
|
+
|
87
|
+
assert_progress_reported_mkdir "/path/to/local"
|
88
|
+
assert_progress_reported_mkdir "/path/to/local/subdir1"
|
89
|
+
assert_progress_reported_open :remote => "/path/to/remote/file1"
|
90
|
+
assert_progress_reported_open :remote => "/path/to/remote/subdir1/file2"
|
91
|
+
assert_progress_reported_get 0, "contents of file1"
|
92
|
+
assert_progress_reported_close :remote => "/path/to/remote/file1"
|
93
|
+
assert_progress_reported_get 0, "contents of file2"
|
94
|
+
assert_progress_reported_close :remote => "/path/to/remote/subdir1/file2"
|
95
|
+
assert_progress_reported_finish
|
96
|
+
assert_no_more_reported_events
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_download_file_should_transfer_remote_to_local_buffer
|
100
|
+
remote = "/path/to/remote"
|
101
|
+
text = "this is some text\n"
|
102
|
+
|
103
|
+
expect_file_transfer(remote, text)
|
104
|
+
|
105
|
+
local = StringIO.new
|
106
|
+
|
107
|
+
assert_scripted_command { sftp.download(remote, local) }
|
108
|
+
assert_equal text, local.string
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_download_directory_to_buffer_should_fail
|
112
|
+
expect_sftp_session :server_version => 3
|
113
|
+
assert_raises(ArgumentError) { sftp.download("/path/to/remote", StringIO.new, :recursive => true) }
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def expect_file_transfer(remote, text)
|
119
|
+
expect_sftp_session :server_version => 3 do |channel|
|
120
|
+
channel.sends_packet(FXP_OPEN, :long, 0, :string, remote, :long, 0x01, :long, 0)
|
121
|
+
channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle")
|
122
|
+
channel.sends_packet(FXP_READ, :long, 1, :string, "handle", :int64, 0, :long, 32_000)
|
123
|
+
channel.gets_packet(FXP_DATA, :long, 1, :string, text)
|
124
|
+
channel.sends_packet(FXP_READ, :long, 2, :string, "handle", :int64, 32_000, :long, 32_000)
|
125
|
+
channel.gets_packet(FXP_STATUS, :long, 2, :long, 1)
|
126
|
+
channel.sends_packet(FXP_CLOSE, :long, 3, :string, "handle")
|
127
|
+
channel.gets_packet(FXP_STATUS, :long, 3, :long, 0)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def prepare_large_file_download(local, remote, text)
|
132
|
+
expect_sftp_session :server_version => 3 do |channel|
|
133
|
+
channel.sends_packet(FXP_OPEN, :long, 0, :string, remote, :long, 0x01, :long, 0)
|
134
|
+
channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle")
|
135
|
+
10.times do |n|
|
136
|
+
channel.sends_packet(FXP_READ, :long, n+1, :string, "handle", :int64, n*1024, :long, 1024)
|
137
|
+
channel.gets_packet(FXP_DATA, :long, n+1, :string, text[n*1024,1024])
|
138
|
+
end
|
139
|
+
channel.sends_packet(FXP_READ, :long, 11, :string, "handle", :int64, 10240, :long, 1024)
|
140
|
+
channel.gets_packet(FXP_STATUS, :long, 11, :long, 1)
|
141
|
+
channel.sends_packet(FXP_CLOSE, :long, 12, :string, "handle")
|
142
|
+
channel.gets_packet(FXP_STATUS, :long, 12, :long, 0)
|
143
|
+
end
|
144
|
+
|
145
|
+
file = StringIO.new
|
146
|
+
File.stubs(:open).with(local, "wb").returns(file)
|
147
|
+
|
148
|
+
return file
|
149
|
+
end
|
150
|
+
|
151
|
+
# 0:OPENDIR(remote) ->
|
152
|
+
# <- 0:HANDLE("dir1")
|
153
|
+
# 1:READDIR("dir1") ->
|
154
|
+
# <- 1:NAME("..", ".", "subdir1", "file1")
|
155
|
+
# 2:OPENDIR(remote/subdir1) ->
|
156
|
+
# 3:OPEN(remote/file1) ->
|
157
|
+
# 4:READDIR("dir1") ->
|
158
|
+
# <- 2:HANDLE("dir2")
|
159
|
+
# 5:READDIR("dir2") ->
|
160
|
+
# <- 3:HANDLE("file1")
|
161
|
+
# 6:READ("file1", 0, 32k) ->
|
162
|
+
# <- 4:STATUS(1)
|
163
|
+
# 7:CLOSE("dir1") ->
|
164
|
+
# <- 5:NAME("..", ".", "file2")
|
165
|
+
# 8:OPEN(remote/subdir1/file2) ->
|
166
|
+
# 9:READDIR("dir2") ->
|
167
|
+
# <- 6:DATA("blah blah blah")
|
168
|
+
# 10:READ("file1", n, 32k)
|
169
|
+
# <- 7:STATUS(0)
|
170
|
+
# <- 8:HANDLE("file2")
|
171
|
+
# 11:READ("file2", 0, 32k) ->
|
172
|
+
# <- 9:STATUS(1)
|
173
|
+
# 12:CLOSE("dir2") ->
|
174
|
+
# <- 10:STATUS(1)
|
175
|
+
# 13:CLOSE("file1") ->
|
176
|
+
# <- 11:DATA("blah blah blah")
|
177
|
+
# 14:READ("file2", n, 32k) ->
|
178
|
+
# <- 12:STATUS(0)
|
179
|
+
# <- 13:STATUS(0)
|
180
|
+
# <- 14:STATUS(1)
|
181
|
+
# 15:CLOSE("file2") ->
|
182
|
+
# <- 15:STATUS(0)
|
183
|
+
|
184
|
+
def prepare_directory_tree_download(local, remote)
|
185
|
+
expect_sftp_session :server_version => 3 do |channel|
|
186
|
+
channel.sends_packet(FXP_OPENDIR, :long, 0, :string, remote)
|
187
|
+
channel.gets_packet(FXP_HANDLE, :long, 0, :string, "dir1")
|
188
|
+
|
189
|
+
channel.sends_packet(FXP_READDIR, :long, 1, :string, "dir1")
|
190
|
+
channel.gets_packet(FXP_NAME, :long, 1, :long, 4,
|
191
|
+
:string, "..", :string, "drwxr-xr-x 4 bob bob 136 Aug 1 ..", :long, 0x04, :long, 040755,
|
192
|
+
:string, ".", :string, "drwxr-xr-x 4 bob bob 136 Aug 1 .", :long, 0x04, :long, 040755,
|
193
|
+
:string, "subdir1", :string, "drwxr-xr-x 4 bob bob 136 Aug 1 subdir1", :long, 0x04, :long, 040755,
|
194
|
+
:string, "file1", :string, "-rw-rw-r-- 1 bob bob 100 Aug 1 file1", :long, 0x04, :long, 0100644)
|
195
|
+
|
196
|
+
channel.sends_packet(FXP_OPENDIR, :long, 2, :string, File.join(remote, "subdir1"))
|
197
|
+
channel.sends_packet(FXP_OPEN, :long, 3, :string, File.join(remote, "file1"), :long, 0x01, :long, 0)
|
198
|
+
channel.sends_packet(FXP_READDIR, :long, 4, :string, "dir1")
|
199
|
+
|
200
|
+
channel.gets_packet(FXP_HANDLE, :long, 2, :string, "dir2")
|
201
|
+
channel.sends_packet(FXP_READDIR, :long, 5, :string, "dir2")
|
202
|
+
|
203
|
+
channel.gets_packet(FXP_HANDLE, :long, 3, :string, "file1")
|
204
|
+
channel.sends_packet(FXP_READ, :long, 6, :string, "file1", :int64, 0, :long, 32_000)
|
205
|
+
|
206
|
+
channel.gets_packet(FXP_STATUS, :long, 4, :long, 1)
|
207
|
+
channel.sends_packet(FXP_CLOSE, :long, 7, :string, "dir1")
|
208
|
+
|
209
|
+
channel.gets_packet(FXP_NAME, :long, 5, :long, 3,
|
210
|
+
:string, "..", :string, "drwxr-xr-x 4 bob bob 136 Aug 1 ..", :long, 0x04, :long, 040755,
|
211
|
+
:string, ".", :string, "drwxr-xr-x 4 bob bob 136 Aug 1 .", :long, 0x04, :long, 040755,
|
212
|
+
:string, "file2", :string, "-rw-rw-r-- 1 bob bob 100 Aug 1 file2", :long, 0x04, :long, 0100644)
|
213
|
+
|
214
|
+
channel.sends_packet(FXP_OPEN, :long, 8, :string, File.join(remote, "subdir1", "file2"), :long, 0x01, :long, 0)
|
215
|
+
channel.sends_packet(FXP_READDIR, :long, 9, :string, "dir2")
|
216
|
+
|
217
|
+
channel.gets_packet(FXP_DATA, :long, 6, :string, "contents of file1")
|
218
|
+
channel.sends_packet(FXP_READ, :long, 10, :string, "file1", :int64, 32_000, :long, 32_000)
|
219
|
+
|
220
|
+
channel.gets_packet(FXP_STATUS, :long, 7, :long, 0)
|
221
|
+
channel.gets_packet(FXP_HANDLE, :long, 8, :string, "file2")
|
222
|
+
channel.sends_packet(FXP_READ, :long, 11, :string, "file2", :int64, 0, :long, 32_000)
|
223
|
+
|
224
|
+
channel.gets_packet(FXP_STATUS, :long, 9, :long, 1)
|
225
|
+
channel.sends_packet(FXP_CLOSE, :long, 12, :string, "dir2")
|
226
|
+
|
227
|
+
channel.gets_packet(FXP_STATUS, :long, 10, :long, 1)
|
228
|
+
channel.sends_packet(FXP_CLOSE, :long, 13, :string, "file1")
|
229
|
+
|
230
|
+
channel.gets_packet(FXP_DATA, :long, 11, :string, "contents of file2")
|
231
|
+
channel.sends_packet(FXP_READ, :long, 14, :string, "file2", :int64, 32_000, :long, 32_000)
|
232
|
+
|
233
|
+
channel.gets_packet(FXP_STATUS, :long, 12, :long, 0)
|
234
|
+
channel.gets_packet(FXP_STATUS, :long, 13, :long, 0)
|
235
|
+
channel.gets_packet(FXP_STATUS, :long, 14, :long, 1)
|
236
|
+
channel.sends_packet(FXP_CLOSE, :long, 15, :string, "file2")
|
237
|
+
channel.gets_packet(FXP_STATUS, :long, 15, :long, 0)
|
238
|
+
end
|
239
|
+
|
240
|
+
File.expects(:directory?).with(local).returns(false)
|
241
|
+
File.expects(:directory?).with(File.join(local, "subdir1")).returns(false)
|
242
|
+
Dir.expects(:mkdir).with(local)
|
243
|
+
Dir.expects(:mkdir).with(File.join(local, "subdir1"))
|
244
|
+
|
245
|
+
file1 = StringIO.new
|
246
|
+
file2 = StringIO.new
|
247
|
+
File.expects(:open).with(File.join(local, "file1"), "wb").returns(file1)
|
248
|
+
File.expects(:open).with(File.join(local, "subdir1", "file2"), "wb").returns(file2)
|
249
|
+
|
250
|
+
[file1, file2]
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'common'
|
2
|
+
|
3
|
+
class FileOperationsTest < Net::SFTP::TestCase
|
4
|
+
def setup
|
5
|
+
@sftp = mock("sftp")
|
6
|
+
@file = Net::SFTP::Operations::File.new(@sftp, "handle")
|
7
|
+
@save_dollar_fslash, $/ = $/, "\n"
|
8
|
+
@save_dollar_bslash, $\ = $\, nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
$/ = @save_dollar_fslash
|
13
|
+
$\ = @save_dollar_bslash
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_pos_assignment_should_set_position
|
17
|
+
@file.pos = 15
|
18
|
+
assert_equal 15, @file.pos
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_pos_assignment_should_reset_eof
|
22
|
+
@sftp.expects(:read!).with("handle", 0, 8192).returns(nil)
|
23
|
+
assert !@file.eof?
|
24
|
+
@file.read
|
25
|
+
assert @file.eof?
|
26
|
+
@file.pos = 0
|
27
|
+
assert !@file.eof?
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_close_should_close_handle_and_set_handle_to_nil
|
31
|
+
assert_equal "handle", @file.handle
|
32
|
+
@sftp.expects(:close!).with("handle")
|
33
|
+
@file.close
|
34
|
+
assert_nil @file.handle
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_eof_should_be_false_if_at_eof_but_data_remains_in_buffer
|
38
|
+
@sftp.expects(:read!).returns("hello world", nil)
|
39
|
+
@file.read(1)
|
40
|
+
assert !@file.eof?
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_eof_should_be_true_if_at_eof_and_no_data_in_buffer
|
44
|
+
@sftp.expects(:read!).times(2).returns("hello world", nil)
|
45
|
+
@file.read
|
46
|
+
assert @file.eof?
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_read_without_argument_should_read_and_return_remainder_of_file_and_set_pos
|
50
|
+
@sftp.expects(:read!).times(2).returns("hello world", nil)
|
51
|
+
assert_equal "hello world", @file.read
|
52
|
+
assert_equal 11, @file.pos
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_read_with_argument_should_read_and_return_n_bytes_and_set_pos
|
56
|
+
@sftp.expects(:read!).returns("hello world")
|
57
|
+
assert_equal "hello", @file.read(5)
|
58
|
+
assert_equal 5, @file.pos
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_read_after_pos_assignment_should_read_from_specified_position
|
62
|
+
@sftp.expects(:read!).with("handle", 5, 8192).returns("hello world")
|
63
|
+
@file.pos = 5
|
64
|
+
assert_equal "hello", @file.read(5)
|
65
|
+
assert_equal 10, @file.pos
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_gets_without_argument_should_read_until_first_dollar_fslash
|
69
|
+
@sftp.expects(:read!).returns("hello world\ngoodbye world\n\nfarewell!\n")
|
70
|
+
assert_equal "\n", $/
|
71
|
+
assert_equal "hello world\n", @file.gets
|
72
|
+
assert_equal 12, @file.pos
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_gets_with_empty_argument_should_read_until_double_dollar_fslash
|
76
|
+
@sftp.expects(:read!).returns("hello world\ngoodbye world\n\nfarewell!\n")
|
77
|
+
assert_equal "\n", $/
|
78
|
+
assert_equal "hello world\ngoodbye world\n\n", @file.gets("")
|
79
|
+
assert_equal 27, @file.pos
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_gets_with_argument_should_read_until_first_instance_of_argument
|
83
|
+
@sftp.expects(:read!).returns("hello world\ngoodbye world\n\nfarewell!\n")
|
84
|
+
assert_equal "hello w", @file.gets("w")
|
85
|
+
assert_equal 7, @file.pos
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_gets_when_no_such_delimiter_exists_in_stream_should_read_to_EOF
|
89
|
+
@sftp.expects(:read!).times(2).returns("hello world\ngoodbye world\n\nfarewell!\n", nil)
|
90
|
+
assert_equal "hello world\ngoodbye world\n\nfarewell!\n", @file.gets("X")
|
91
|
+
assert @file.eof?
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_gets_at_EOF_should_return_nil
|
95
|
+
@sftp.expects(:read!).returns(nil)
|
96
|
+
assert_nil @file.gets
|
97
|
+
assert @file.eof?
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_readline_should_raise_exception_on_EOF
|
101
|
+
@sftp.expects(:read!).returns(nil)
|
102
|
+
assert_raises(EOFError) { @file.readline }
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_write_should_write_data_and_increment_pos_and_return_data_length
|
106
|
+
@sftp.expects(:write!).with("handle", 0, "hello world")
|
107
|
+
assert_equal 11, @file.write("hello world")
|
108
|
+
assert_equal 11, @file.pos
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_write_after_pos_assignment_should_write_at_position
|
112
|
+
@sftp.expects(:write!).with("handle", 15, "hello world")
|
113
|
+
@file.pos = 15
|
114
|
+
assert_equal 11, @file.write("hello world")
|
115
|
+
assert_equal 26, @file.pos
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_print_with_no_arguments_should_write_nothing_if_dollar_bslash_is_nil
|
119
|
+
assert_nil $\
|
120
|
+
@sftp.expects(:write!).never
|
121
|
+
@file.print
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_print_with_no_arguments_should_write_dollar_bslash_if_dollar_bslash_is_not_nil
|
125
|
+
$\ = "-"
|
126
|
+
@sftp.expects(:write!).with("handle", 0, "-")
|
127
|
+
@file.print
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_print_with_arguments_should_write_all_arguments
|
131
|
+
@sftp.expects(:write!).with("handle", 0, "hello")
|
132
|
+
@sftp.expects(:write!).with("handle", 5, " ")
|
133
|
+
@sftp.expects(:write!).with("handle", 6, "world")
|
134
|
+
@file.print("hello", " ", "world")
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_puts_should_recursively_puts_array_arguments
|
138
|
+
10.times do |i|
|
139
|
+
@sftp.expects(:write!).with("handle", i*2, i.to_s)
|
140
|
+
@sftp.expects(:write!).with("handle", i*2+1, "\n")
|
141
|
+
end
|
142
|
+
@file.puts 0, [1, [2, 3], 4, [5, [6, 7, 8]]], 9
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_puts_should_not_append_newline_if_argument_ends_in_newline
|
146
|
+
@sftp.expects(:write!).with("handle", 0, "a")
|
147
|
+
@sftp.expects(:write!).with("handle", 1, "\n")
|
148
|
+
@sftp.expects(:write!).with("handle", 2, "b\n")
|
149
|
+
@sftp.expects(:write!).with("handle", 4, "c")
|
150
|
+
@sftp.expects(:write!).with("handle", 5, "\n")
|
151
|
+
@file.puts "a", "b\n", "c"
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_stat_should_return_attributes_object_for_handle
|
155
|
+
stat = stub("stat")
|
156
|
+
@sftp.expects(:fstat!).with("handle").returns(stat)
|
157
|
+
assert_equal stat, @file.stat
|
158
|
+
end
|
159
|
+
end
|