net-sftp 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/LICENSE-BSD +27 -0
- data/doc/LICENSE-GPL +280 -0
- data/doc/LICENSE-RUBY +56 -0
- data/examples/asynchronous.rb +57 -0
- data/examples/ssh-service.rb +31 -0
- data/examples/synchronous.rb +120 -0
- data/lib/net/sftp.rb +39 -0
- data/lib/net/sftp/errors.rb +25 -0
- data/lib/net/sftp/operations/abstract.rb +103 -0
- data/lib/net/sftp/operations/close.rb +31 -0
- data/lib/net/sftp/operations/errors.rb +76 -0
- data/lib/net/sftp/operations/fsetstat.rb +36 -0
- data/lib/net/sftp/operations/fstat.rb +32 -0
- data/lib/net/sftp/operations/lstat.rb +31 -0
- data/lib/net/sftp/operations/mkdir.rb +33 -0
- data/lib/net/sftp/operations/open.rb +32 -0
- data/lib/net/sftp/operations/opendir.rb +32 -0
- data/lib/net/sftp/operations/read.rb +84 -0
- data/lib/net/sftp/operations/readdir.rb +55 -0
- data/lib/net/sftp/operations/realpath.rb +37 -0
- data/lib/net/sftp/operations/remove.rb +31 -0
- data/lib/net/sftp/operations/rename.rb +32 -0
- data/lib/net/sftp/operations/rmdir.rb +31 -0
- data/lib/net/sftp/operations/services.rb +42 -0
- data/lib/net/sftp/operations/setstat.rb +33 -0
- data/lib/net/sftp/operations/stat.rb +31 -0
- data/lib/net/sftp/operations/write.rb +63 -0
- data/lib/net/sftp/protocol/01/attributes.rb +146 -0
- data/lib/net/sftp/protocol/01/impl.rb +251 -0
- data/lib/net/sftp/protocol/01/packet-assistant.rb +82 -0
- data/lib/net/sftp/protocol/01/services.rb +47 -0
- data/lib/net/sftp/protocol/02/impl.rb +39 -0
- data/lib/net/sftp/protocol/02/packet-assistant.rb +32 -0
- data/lib/net/sftp/protocol/02/services.rb +44 -0
- data/lib/net/sftp/protocol/03/impl.rb +42 -0
- data/lib/net/sftp/protocol/03/packet-assistant.rb +35 -0
- data/lib/net/sftp/protocol/03/services.rb +44 -0
- data/lib/net/sftp/protocol/04/attributes.rb +227 -0
- data/lib/net/sftp/protocol/04/impl.rb +134 -0
- data/lib/net/sftp/protocol/04/packet-assistant.rb +51 -0
- data/lib/net/sftp/protocol/04/services.rb +44 -0
- data/lib/net/sftp/protocol/05/services.rb +44 -0
- data/lib/net/sftp/protocol/constants.rb +60 -0
- data/lib/net/sftp/protocol/driver.rb +232 -0
- data/lib/net/sftp/protocol/packet-assistant.rb +84 -0
- data/lib/net/sftp/protocol/services.rb +55 -0
- data/lib/net/sftp/session.rb +215 -0
- data/lib/net/sftp/version.rb +25 -0
- data/test/ALL-TESTS.rb +21 -0
- data/test/operations/tc_abstract.rb +124 -0
- data/test/operations/tc_close.rb +40 -0
- data/test/operations/tc_fsetstat.rb +48 -0
- data/test/operations/tc_fstat.rb +40 -0
- data/test/operations/tc_lstat.rb +40 -0
- data/test/operations/tc_mkdir.rb +48 -0
- data/test/operations/tc_open.rb +42 -0
- data/test/operations/tc_opendir.rb +40 -0
- data/test/operations/tc_read.rb +103 -0
- data/test/operations/tc_readdir.rb +88 -0
- data/test/operations/tc_realpath.rb +54 -0
- data/test/operations/tc_remove.rb +40 -0
- data/test/operations/tc_rmdir.rb +40 -0
- data/test/operations/tc_setstat.rb +48 -0
- data/test/operations/tc_stat.rb +40 -0
- data/test/operations/tc_write.rb +91 -0
- data/test/protocol/01/tc_attributes.rb +138 -0
- data/test/protocol/01/tc_impl.rb +294 -0
- data/test/protocol/01/tc_packet_assistant.rb +81 -0
- data/test/protocol/02/tc_impl.rb +41 -0
- data/test/protocol/02/tc_packet_assistant.rb +31 -0
- data/test/protocol/03/tc_impl.rb +48 -0
- data/test/protocol/03/tc_packet_assistant.rb +34 -0
- data/test/protocol/04/tc_attributes.rb +174 -0
- data/test/protocol/04/tc_impl.rb +102 -0
- data/test/protocol/04/tc_packet_assistant.rb +41 -0
- data/test/protocol/tc_driver.rb +219 -0
- metadata +137 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
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/close'
|
21
|
+
require 'flexmock'
|
22
|
+
|
23
|
+
class TC_Operations_Close < Test::Unit::TestCase
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@log = FlexMock.new
|
27
|
+
@session = FlexMock.new
|
28
|
+
@driver = FlexMock.new
|
29
|
+
@operation = Net::SFTP::Operations::Close.new( @log, @session, @driver )
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_perform
|
33
|
+
id = handle = nil
|
34
|
+
@driver.mock_handle( :close_handle ) { |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
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
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/fsetstat'
|
21
|
+
require 'flexmock'
|
22
|
+
|
23
|
+
class TC_Operations_Fsetstat < 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::Fsetstat.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( :fsetstat ) { |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
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
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
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
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
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
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
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
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
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
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
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
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", 15, 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", 15, 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", 15, 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
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
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
|