net-sftp 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +23 -0
- data/Manifest +55 -0
- data/README.rdoc +96 -0
- data/Rakefile +30 -0
- data/lib/net/sftp.rb +53 -38
- data/lib/net/sftp/constants.rb +187 -0
- data/lib/net/sftp/errors.rb +34 -20
- data/lib/net/sftp/operations/dir.rb +93 -0
- data/lib/net/sftp/operations/download.rb +364 -0
- data/lib/net/sftp/operations/file.rb +176 -0
- data/lib/net/sftp/operations/file_factory.rb +60 -0
- data/lib/net/sftp/operations/upload.rb +387 -0
- data/lib/net/sftp/packet.rb +21 -0
- data/lib/net/sftp/protocol.rb +32 -0
- data/lib/net/sftp/protocol/01/attributes.rb +265 -96
- data/lib/net/sftp/protocol/01/base.rb +268 -0
- data/lib/net/sftp/protocol/01/name.rb +43 -0
- data/lib/net/sftp/protocol/02/base.rb +31 -0
- data/lib/net/sftp/protocol/03/base.rb +35 -0
- data/lib/net/sftp/protocol/04/attributes.rb +120 -195
- data/lib/net/sftp/protocol/04/base.rb +94 -0
- data/lib/net/sftp/protocol/04/name.rb +67 -0
- data/lib/net/sftp/protocol/05/base.rb +66 -0
- data/lib/net/sftp/protocol/06/attributes.rb +107 -0
- data/lib/net/sftp/protocol/06/base.rb +63 -0
- data/lib/net/sftp/protocol/base.rb +50 -0
- data/lib/net/sftp/request.rb +91 -0
- data/lib/net/sftp/response.rb +76 -0
- data/lib/net/sftp/session.rb +914 -238
- data/lib/net/sftp/version.rb +14 -21
- data/net-sftp.gemspec +60 -0
- data/setup.rb +1331 -0
- data/test/common.rb +173 -0
- data/test/protocol/01/test_attributes.rb +97 -0
- data/test/protocol/01/test_base.rb +210 -0
- data/test/protocol/01/test_name.rb +27 -0
- data/test/protocol/02/test_base.rb +26 -0
- data/test/protocol/03/test_base.rb +27 -0
- data/test/protocol/04/test_attributes.rb +148 -0
- data/test/protocol/04/test_base.rb +74 -0
- data/test/protocol/04/test_name.rb +49 -0
- data/test/protocol/05/test_base.rb +62 -0
- data/test/protocol/06/test_attributes.rb +124 -0
- data/test/protocol/06/test_base.rb +51 -0
- data/test/protocol/test_base.rb +42 -0
- data/test/test_all.rb +3 -0
- data/test/test_dir.rb +47 -0
- data/test/test_download.rb +252 -0
- data/test/test_file.rb +159 -0
- data/test/test_file_factory.rb +48 -0
- data/test/test_packet.rb +9 -0
- data/test/test_protocol.rb +17 -0
- data/test/test_request.rb +71 -0
- data/test/test_response.rb +53 -0
- data/test/test_session.rb +741 -0
- data/test/test_upload.rb +219 -0
- metadata +59 -111
- data/doc/LICENSE-BSD +0 -27
- data/doc/LICENSE-GPL +0 -280
- data/doc/LICENSE-RUBY +0 -56
- data/doc/faq/faq.html +0 -298
- data/doc/faq/faq.rb +0 -154
- data/doc/faq/faq.yml +0 -183
- data/examples/asynchronous.rb +0 -57
- data/examples/get-put.rb +0 -45
- data/examples/sftp-open-uri.rb +0 -30
- data/examples/ssh-service.rb +0 -30
- data/examples/synchronous.rb +0 -131
- data/lib/net/sftp/operations/abstract.rb +0 -108
- data/lib/net/sftp/operations/close.rb +0 -31
- data/lib/net/sftp/operations/errors.rb +0 -76
- data/lib/net/sftp/operations/fsetstat.rb +0 -36
- data/lib/net/sftp/operations/fstat.rb +0 -32
- data/lib/net/sftp/operations/lstat.rb +0 -31
- data/lib/net/sftp/operations/mkdir.rb +0 -33
- data/lib/net/sftp/operations/open.rb +0 -32
- data/lib/net/sftp/operations/opendir.rb +0 -32
- data/lib/net/sftp/operations/read.rb +0 -88
- data/lib/net/sftp/operations/readdir.rb +0 -55
- data/lib/net/sftp/operations/realpath.rb +0 -37
- data/lib/net/sftp/operations/remove.rb +0 -31
- data/lib/net/sftp/operations/rename.rb +0 -32
- data/lib/net/sftp/operations/rmdir.rb +0 -31
- data/lib/net/sftp/operations/services.rb +0 -42
- data/lib/net/sftp/operations/setstat.rb +0 -33
- data/lib/net/sftp/operations/stat.rb +0 -31
- data/lib/net/sftp/operations/write.rb +0 -63
- data/lib/net/sftp/protocol/01/impl.rb +0 -251
- data/lib/net/sftp/protocol/01/packet-assistant.rb +0 -82
- data/lib/net/sftp/protocol/01/services.rb +0 -47
- data/lib/net/sftp/protocol/02/impl.rb +0 -39
- data/lib/net/sftp/protocol/02/packet-assistant.rb +0 -32
- data/lib/net/sftp/protocol/02/services.rb +0 -44
- data/lib/net/sftp/protocol/03/impl.rb +0 -42
- data/lib/net/sftp/protocol/03/packet-assistant.rb +0 -35
- data/lib/net/sftp/protocol/03/services.rb +0 -44
- data/lib/net/sftp/protocol/04/impl.rb +0 -86
- data/lib/net/sftp/protocol/04/packet-assistant.rb +0 -45
- data/lib/net/sftp/protocol/04/services.rb +0 -44
- data/lib/net/sftp/protocol/05/impl.rb +0 -90
- data/lib/net/sftp/protocol/05/packet-assistant.rb +0 -34
- data/lib/net/sftp/protocol/05/services.rb +0 -44
- data/lib/net/sftp/protocol/constants.rb +0 -60
- data/lib/net/sftp/protocol/driver.rb +0 -235
- data/lib/net/sftp/protocol/packet-assistant.rb +0 -84
- data/lib/net/sftp/protocol/services.rb +0 -55
- data/lib/uri/open-sftp.rb +0 -54
- data/lib/uri/sftp.rb +0 -42
- data/test/ALL-TESTS.rb +0 -23
- data/test/operations/tc_abstract.rb +0 -124
- data/test/operations/tc_close.rb +0 -40
- data/test/operations/tc_fsetstat.rb +0 -48
- data/test/operations/tc_fstat.rb +0 -40
- data/test/operations/tc_lstat.rb +0 -40
- data/test/operations/tc_mkdir.rb +0 -48
- data/test/operations/tc_open.rb +0 -42
- data/test/operations/tc_opendir.rb +0 -40
- data/test/operations/tc_read.rb +0 -103
- data/test/operations/tc_readdir.rb +0 -88
- data/test/operations/tc_realpath.rb +0 -54
- data/test/operations/tc_remove.rb +0 -40
- data/test/operations/tc_rmdir.rb +0 -40
- data/test/operations/tc_setstat.rb +0 -48
- data/test/operations/tc_stat.rb +0 -40
- data/test/operations/tc_write.rb +0 -91
- data/test/protocol/01/tc_attributes.rb +0 -138
- data/test/protocol/01/tc_impl.rb +0 -294
- data/test/protocol/01/tc_packet_assistant.rb +0 -81
- data/test/protocol/02/tc_impl.rb +0 -41
- data/test/protocol/02/tc_packet_assistant.rb +0 -31
- data/test/protocol/03/tc_impl.rb +0 -48
- data/test/protocol/03/tc_packet_assistant.rb +0 -34
- data/test/protocol/04/tc_attributes.rb +0 -174
- data/test/protocol/04/tc_impl.rb +0 -91
- data/test/protocol/04/tc_packet_assistant.rb +0 -38
- data/test/protocol/05/tc_impl.rb +0 -61
- data/test/protocol/05/tc_packet_assistant.rb +0 -32
- data/test/protocol/tc_driver.rb +0 -219
data/test/operations/tc_fstat.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../lib"
|
18
|
-
|
19
|
-
require 'test/unit'
|
20
|
-
require 'net/sftp/operations/fstat'
|
21
|
-
require 'flexmock'
|
22
|
-
|
23
|
-
class TC_Operations_Fstat < Test::Unit::TestCase
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@log = FlexMock.new
|
27
|
-
@session = FlexMock.new
|
28
|
-
@driver = FlexMock.new
|
29
|
-
@operation = Net::SFTP::Operations::Fstat.new( @log, @session, @driver )
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_perform
|
33
|
-
id = handle = nil
|
34
|
-
@driver.mock_handle( :fstat ) { |i,h| id, handle = i, h; 10 }
|
35
|
-
assert_equal 10, @operation.perform( "foo" )
|
36
|
-
assert_nil id
|
37
|
-
assert_equal "foo", handle
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
data/test/operations/tc_lstat.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../lib"
|
18
|
-
|
19
|
-
require 'test/unit'
|
20
|
-
require 'net/sftp/operations/lstat'
|
21
|
-
require 'flexmock'
|
22
|
-
|
23
|
-
class TC_Operations_Lstat < Test::Unit::TestCase
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@log = FlexMock.new
|
27
|
-
@session = FlexMock.new
|
28
|
-
@driver = FlexMock.new
|
29
|
-
@operation = Net::SFTP::Operations::Lstat.new( @log, @session, @driver )
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_perform
|
33
|
-
id = path = nil
|
34
|
-
@driver.mock_handle( :lstat ) { |i,p| id, path = i, p; 10 }
|
35
|
-
assert_equal 10, @operation.perform( "foo" )
|
36
|
-
assert_nil id
|
37
|
-
assert_equal "foo", path
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
data/test/operations/tc_mkdir.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../lib"
|
18
|
-
|
19
|
-
require 'test/unit'
|
20
|
-
require 'net/sftp/operations/mkdir'
|
21
|
-
require 'flexmock'
|
22
|
-
|
23
|
-
class TC_Operations_Mkdir < Test::Unit::TestCase
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@log = FlexMock.new
|
27
|
-
@session = FlexMock.new
|
28
|
-
@attr_factory = FlexMock.new
|
29
|
-
@driver = FlexMock.new
|
30
|
-
@driver.mock_handle( :attr_factory ) { @attr_factory }
|
31
|
-
@operation = Net::SFTP::Operations::Mkdir.new( @log, @session, @driver )
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_perform
|
35
|
-
hash = nil
|
36
|
-
@attr_factory.mock_handle( :from_hash ) { |h| hash = h; :foo }
|
37
|
-
|
38
|
-
id = handle = attrs = nil
|
39
|
-
@driver.mock_handle( :mkdir ) { |i,h,a| id, handle, attrs = i, h, a; 10 }
|
40
|
-
|
41
|
-
assert_equal 10, @operation.perform( "foo", "bar" )
|
42
|
-
assert_nil id
|
43
|
-
assert_equal "foo", handle
|
44
|
-
assert_equal "bar", hash
|
45
|
-
assert_equal :foo, attrs
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
data/test/operations/tc_open.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../lib"
|
18
|
-
|
19
|
-
require 'test/unit'
|
20
|
-
require 'net/sftp/operations/open'
|
21
|
-
require 'flexmock'
|
22
|
-
|
23
|
-
class TC_Operations_Open < Test::Unit::TestCase
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@log = FlexMock.new
|
27
|
-
@session = FlexMock.new
|
28
|
-
@driver = FlexMock.new
|
29
|
-
@operation = Net::SFTP::Operations::Open.new( @log, @session, @driver )
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_perform
|
33
|
-
id = handle = flags = mode = nil
|
34
|
-
@driver.mock_handle( :open ) { |i,h,f,m| id, handle, flags, mode = i, h, f, m; 10 }
|
35
|
-
assert_equal 10, @operation.perform( "foo" )
|
36
|
-
assert_nil id
|
37
|
-
assert_equal "foo", handle
|
38
|
-
assert_equal IO::RDONLY, flags
|
39
|
-
assert_equal 0660, mode
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../lib"
|
18
|
-
|
19
|
-
require 'test/unit'
|
20
|
-
require 'net/sftp/operations/opendir'
|
21
|
-
require 'flexmock'
|
22
|
-
|
23
|
-
class TC_Operations_Opendir < Test::Unit::TestCase
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@log = FlexMock.new
|
27
|
-
@session = FlexMock.new
|
28
|
-
@driver = FlexMock.new
|
29
|
-
@operation = Net::SFTP::Operations::Opendir.new( @log, @session, @driver )
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_perform
|
33
|
-
id = path = nil
|
34
|
-
@driver.mock_handle( :opendir ) { |i,p| id, path = i, p; 10 }
|
35
|
-
assert_equal 10, @operation.perform( "foo" )
|
36
|
-
assert_nil id
|
37
|
-
assert_equal "foo", path
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
data/test/operations/tc_read.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../lib"
|
18
|
-
|
19
|
-
require 'test/unit'
|
20
|
-
require 'net/sftp/operations/read'
|
21
|
-
require 'flexmock'
|
22
|
-
|
23
|
-
class TC_Operations_Read < Test::Unit::TestCase
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@log = FlexMock.new
|
27
|
-
@log.mock_handle( :debug? )
|
28
|
-
@log.mock_handle( :debug )
|
29
|
-
|
30
|
-
@session = FlexMock.new
|
31
|
-
@driver = FlexMock.new
|
32
|
-
@operation = Net::SFTP::Operations::Read.new( @log, @session, @driver )
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_perform_defaults
|
36
|
-
id = handle = offset = length = nil
|
37
|
-
@driver.mock_handle( :read ) { |i,h,o,l| id, handle, offset, length = i, h, o, l; 10 }
|
38
|
-
assert_equal 10, @operation.perform( "foo" )
|
39
|
-
assert_nil id
|
40
|
-
assert_equal "foo", handle
|
41
|
-
assert_equal 0, offset
|
42
|
-
assert_equal 64 * 1024, length
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_perform_explicit
|
46
|
-
id = handle = offset = length = nil
|
47
|
-
@driver.mock_handle( :read ) { |i,h,o,l| id, handle, offset, length = i, h, o, l; 10 }
|
48
|
-
assert_equal 10, @operation.perform( "foo", :offset=>15, :length=>72 )
|
49
|
-
assert_nil id
|
50
|
-
assert_equal "foo", handle
|
51
|
-
assert_equal 15, offset
|
52
|
-
assert_equal 72, length
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_do_data_full
|
56
|
-
id = handle = offset = length = nil
|
57
|
-
@driver.mock_handle( :read ) { |i,h,o,l| id, handle, offset, length = i, h, o, l; 10 }
|
58
|
-
@session.mock_handle( :register )
|
59
|
-
@operation.perform( "foo" )
|
60
|
-
@operation.do_data( "harbinger of doom" )
|
61
|
-
assert_equal 2, @driver.mock_count( :read )
|
62
|
-
assert_equal 1, @session.mock_count( :register )
|
63
|
-
assert_equal "foo", handle
|
64
|
-
assert_equal 17, offset
|
65
|
-
assert_equal 64 * 1024, length
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_do_data_partial
|
69
|
-
id = handle = offset = length = nil
|
70
|
-
@driver.mock_handle( :read ) { |i,h,o,l| id, handle, offset, length = i, h, o, l; 10 }
|
71
|
-
@session.mock_handle( :register )
|
72
|
-
@session.mock_handle( :loop )
|
73
|
-
@session.mock_handle( :status= )
|
74
|
-
called = false
|
75
|
-
@operation.execute( "foo", :offset=>15, :length=>20 ) { called = true }
|
76
|
-
@operation.do_data( "harbinger of doom" )
|
77
|
-
@operation.do_data( "abc" )
|
78
|
-
assert_equal 2, @driver.mock_count( :read )
|
79
|
-
assert_equal 2, @session.mock_count( :register )
|
80
|
-
assert_equal "foo", handle
|
81
|
-
assert_equal 32, offset
|
82
|
-
assert_equal 3, length
|
83
|
-
assert called
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_do_status_eof
|
87
|
-
@driver.mock_handle( :read )
|
88
|
-
@session.mock_handle( :register )
|
89
|
-
@session.mock_handle( :loop )
|
90
|
-
@session.mock_handle( :status= )
|
91
|
-
called = false
|
92
|
-
@operation.execute( "foo", :offset=>15, :length=>20 ) { called = true }
|
93
|
-
assert_nothing_raised { @operation.do_status( 1, nil, nil ) }
|
94
|
-
assert called
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_do_status_bad
|
98
|
-
assert_raise( Net::SFTP::Operations::StatusException ) do
|
99
|
-
@operation.do_status( 2, nil, nil )
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../lib"
|
18
|
-
|
19
|
-
require 'test/unit'
|
20
|
-
require 'net/sftp/operations/readdir'
|
21
|
-
require 'flexmock'
|
22
|
-
|
23
|
-
class TC_Operations_Readdir < Test::Unit::TestCase
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@log = FlexMock.new
|
27
|
-
@session = FlexMock.new
|
28
|
-
@driver = FlexMock.new
|
29
|
-
@operation = Net::SFTP::Operations::Readdir.new( @log, @session, @driver )
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_perform
|
33
|
-
id = handle = nil
|
34
|
-
@driver.mock_handle( :readdir ) { |i,h| id, handle = i, h; 10 }
|
35
|
-
assert_equal 10, @operation.perform( "foo" )
|
36
|
-
assert_nil id
|
37
|
-
assert_equal "foo", handle
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_do_name
|
41
|
-
id = handle = nil
|
42
|
-
@log.mock_handle( :debug? )
|
43
|
-
@log.mock_handle( :debug )
|
44
|
-
@driver.mock_handle( :readdir ) { |i,h| id, handle = i, h; 10 }
|
45
|
-
@session.mock_handle( :register )
|
46
|
-
@operation.perform( "foo" )
|
47
|
-
@operation.do_name( [ :a, :b ] )
|
48
|
-
assert_equal 1, @session.mock_count( :register )
|
49
|
-
assert_equal "foo", handle
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_do_status_ok
|
53
|
-
called = false
|
54
|
-
|
55
|
-
@log.mock_handle( :debug? )
|
56
|
-
@log.mock_handle( :debug )
|
57
|
-
@driver.mock_handle( :readdir )
|
58
|
-
@session.mock_handle( :register )
|
59
|
-
@session.mock_handle( :status= )
|
60
|
-
@session.mock_handle( :loop )
|
61
|
-
|
62
|
-
@operation.execute( "foo" ) { called = true }
|
63
|
-
assert_nothing_raised { @operation.do_status( 0, :a, :b ) }
|
64
|
-
assert called
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_do_status_eof
|
68
|
-
called = false
|
69
|
-
|
70
|
-
@log.mock_handle( :debug? )
|
71
|
-
@log.mock_handle( :debug )
|
72
|
-
@driver.mock_handle( :readdir )
|
73
|
-
@session.mock_handle( :register )
|
74
|
-
@session.mock_handle( :status= )
|
75
|
-
@session.mock_handle( :loop )
|
76
|
-
|
77
|
-
@operation.execute( "foo" ) { called = true }
|
78
|
-
assert_nothing_raised { @operation.do_status( 1, :a, :b ) }
|
79
|
-
assert called
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_do_status_bad
|
83
|
-
assert_raise( Net::SFTP::Operations::StatusException ) do
|
84
|
-
@operation.do_status( 2, :a, :b )
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../lib"
|
18
|
-
|
19
|
-
require 'test/unit'
|
20
|
-
require 'net/sftp/operations/realpath'
|
21
|
-
require 'flexmock'
|
22
|
-
|
23
|
-
class TC_Operations_Realpath < Test::Unit::TestCase
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@log = FlexMock.new
|
27
|
-
@session = FlexMock.new
|
28
|
-
@driver = FlexMock.new
|
29
|
-
@operation = Net::SFTP::Operations::Realpath.new( @log, @session, @driver )
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_perform
|
33
|
-
id = path = nil
|
34
|
-
@driver.mock_handle( :realpath ) { |i,p| id, path = i, p; 10 }
|
35
|
-
assert_equal 10, @operation.perform( "foo" )
|
36
|
-
assert_nil id
|
37
|
-
assert_equal "foo", path
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_do_name
|
41
|
-
@session.mock_handle( :loop )
|
42
|
-
@session.mock_handle( :status= )
|
43
|
-
@session.mock_handle( :register )
|
44
|
-
@driver.mock_handle( :realpath )
|
45
|
-
@log.mock_handle( :debug? )
|
46
|
-
@log.mock_handle( :debug )
|
47
|
-
|
48
|
-
called = false
|
49
|
-
@operation.execute( "foo" ) { |s,v| called = v }
|
50
|
-
@operation.do_name( [ :a, :b ] )
|
51
|
-
assert_equal :a, called
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|