net-sftp 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. data/CHANGELOG.rdoc +23 -0
  2. data/Manifest +55 -0
  3. data/README.rdoc +96 -0
  4. data/Rakefile +30 -0
  5. data/lib/net/sftp.rb +53 -38
  6. data/lib/net/sftp/constants.rb +187 -0
  7. data/lib/net/sftp/errors.rb +34 -20
  8. data/lib/net/sftp/operations/dir.rb +93 -0
  9. data/lib/net/sftp/operations/download.rb +364 -0
  10. data/lib/net/sftp/operations/file.rb +176 -0
  11. data/lib/net/sftp/operations/file_factory.rb +60 -0
  12. data/lib/net/sftp/operations/upload.rb +387 -0
  13. data/lib/net/sftp/packet.rb +21 -0
  14. data/lib/net/sftp/protocol.rb +32 -0
  15. data/lib/net/sftp/protocol/01/attributes.rb +265 -96
  16. data/lib/net/sftp/protocol/01/base.rb +268 -0
  17. data/lib/net/sftp/protocol/01/name.rb +43 -0
  18. data/lib/net/sftp/protocol/02/base.rb +31 -0
  19. data/lib/net/sftp/protocol/03/base.rb +35 -0
  20. data/lib/net/sftp/protocol/04/attributes.rb +120 -195
  21. data/lib/net/sftp/protocol/04/base.rb +94 -0
  22. data/lib/net/sftp/protocol/04/name.rb +67 -0
  23. data/lib/net/sftp/protocol/05/base.rb +66 -0
  24. data/lib/net/sftp/protocol/06/attributes.rb +107 -0
  25. data/lib/net/sftp/protocol/06/base.rb +63 -0
  26. data/lib/net/sftp/protocol/base.rb +50 -0
  27. data/lib/net/sftp/request.rb +91 -0
  28. data/lib/net/sftp/response.rb +76 -0
  29. data/lib/net/sftp/session.rb +914 -238
  30. data/lib/net/sftp/version.rb +14 -21
  31. data/net-sftp.gemspec +60 -0
  32. data/setup.rb +1331 -0
  33. data/test/common.rb +173 -0
  34. data/test/protocol/01/test_attributes.rb +97 -0
  35. data/test/protocol/01/test_base.rb +210 -0
  36. data/test/protocol/01/test_name.rb +27 -0
  37. data/test/protocol/02/test_base.rb +26 -0
  38. data/test/protocol/03/test_base.rb +27 -0
  39. data/test/protocol/04/test_attributes.rb +148 -0
  40. data/test/protocol/04/test_base.rb +74 -0
  41. data/test/protocol/04/test_name.rb +49 -0
  42. data/test/protocol/05/test_base.rb +62 -0
  43. data/test/protocol/06/test_attributes.rb +124 -0
  44. data/test/protocol/06/test_base.rb +51 -0
  45. data/test/protocol/test_base.rb +42 -0
  46. data/test/test_all.rb +3 -0
  47. data/test/test_dir.rb +47 -0
  48. data/test/test_download.rb +252 -0
  49. data/test/test_file.rb +159 -0
  50. data/test/test_file_factory.rb +48 -0
  51. data/test/test_packet.rb +9 -0
  52. data/test/test_protocol.rb +17 -0
  53. data/test/test_request.rb +71 -0
  54. data/test/test_response.rb +53 -0
  55. data/test/test_session.rb +741 -0
  56. data/test/test_upload.rb +219 -0
  57. metadata +59 -111
  58. data/doc/LICENSE-BSD +0 -27
  59. data/doc/LICENSE-GPL +0 -280
  60. data/doc/LICENSE-RUBY +0 -56
  61. data/doc/faq/faq.html +0 -298
  62. data/doc/faq/faq.rb +0 -154
  63. data/doc/faq/faq.yml +0 -183
  64. data/examples/asynchronous.rb +0 -57
  65. data/examples/get-put.rb +0 -45
  66. data/examples/sftp-open-uri.rb +0 -30
  67. data/examples/ssh-service.rb +0 -30
  68. data/examples/synchronous.rb +0 -131
  69. data/lib/net/sftp/operations/abstract.rb +0 -108
  70. data/lib/net/sftp/operations/close.rb +0 -31
  71. data/lib/net/sftp/operations/errors.rb +0 -76
  72. data/lib/net/sftp/operations/fsetstat.rb +0 -36
  73. data/lib/net/sftp/operations/fstat.rb +0 -32
  74. data/lib/net/sftp/operations/lstat.rb +0 -31
  75. data/lib/net/sftp/operations/mkdir.rb +0 -33
  76. data/lib/net/sftp/operations/open.rb +0 -32
  77. data/lib/net/sftp/operations/opendir.rb +0 -32
  78. data/lib/net/sftp/operations/read.rb +0 -88
  79. data/lib/net/sftp/operations/readdir.rb +0 -55
  80. data/lib/net/sftp/operations/realpath.rb +0 -37
  81. data/lib/net/sftp/operations/remove.rb +0 -31
  82. data/lib/net/sftp/operations/rename.rb +0 -32
  83. data/lib/net/sftp/operations/rmdir.rb +0 -31
  84. data/lib/net/sftp/operations/services.rb +0 -42
  85. data/lib/net/sftp/operations/setstat.rb +0 -33
  86. data/lib/net/sftp/operations/stat.rb +0 -31
  87. data/lib/net/sftp/operations/write.rb +0 -63
  88. data/lib/net/sftp/protocol/01/impl.rb +0 -251
  89. data/lib/net/sftp/protocol/01/packet-assistant.rb +0 -82
  90. data/lib/net/sftp/protocol/01/services.rb +0 -47
  91. data/lib/net/sftp/protocol/02/impl.rb +0 -39
  92. data/lib/net/sftp/protocol/02/packet-assistant.rb +0 -32
  93. data/lib/net/sftp/protocol/02/services.rb +0 -44
  94. data/lib/net/sftp/protocol/03/impl.rb +0 -42
  95. data/lib/net/sftp/protocol/03/packet-assistant.rb +0 -35
  96. data/lib/net/sftp/protocol/03/services.rb +0 -44
  97. data/lib/net/sftp/protocol/04/impl.rb +0 -86
  98. data/lib/net/sftp/protocol/04/packet-assistant.rb +0 -45
  99. data/lib/net/sftp/protocol/04/services.rb +0 -44
  100. data/lib/net/sftp/protocol/05/impl.rb +0 -90
  101. data/lib/net/sftp/protocol/05/packet-assistant.rb +0 -34
  102. data/lib/net/sftp/protocol/05/services.rb +0 -44
  103. data/lib/net/sftp/protocol/constants.rb +0 -60
  104. data/lib/net/sftp/protocol/driver.rb +0 -235
  105. data/lib/net/sftp/protocol/packet-assistant.rb +0 -84
  106. data/lib/net/sftp/protocol/services.rb +0 -55
  107. data/lib/uri/open-sftp.rb +0 -54
  108. data/lib/uri/sftp.rb +0 -42
  109. data/test/ALL-TESTS.rb +0 -23
  110. data/test/operations/tc_abstract.rb +0 -124
  111. data/test/operations/tc_close.rb +0 -40
  112. data/test/operations/tc_fsetstat.rb +0 -48
  113. data/test/operations/tc_fstat.rb +0 -40
  114. data/test/operations/tc_lstat.rb +0 -40
  115. data/test/operations/tc_mkdir.rb +0 -48
  116. data/test/operations/tc_open.rb +0 -42
  117. data/test/operations/tc_opendir.rb +0 -40
  118. data/test/operations/tc_read.rb +0 -103
  119. data/test/operations/tc_readdir.rb +0 -88
  120. data/test/operations/tc_realpath.rb +0 -54
  121. data/test/operations/tc_remove.rb +0 -40
  122. data/test/operations/tc_rmdir.rb +0 -40
  123. data/test/operations/tc_setstat.rb +0 -48
  124. data/test/operations/tc_stat.rb +0 -40
  125. data/test/operations/tc_write.rb +0 -91
  126. data/test/protocol/01/tc_attributes.rb +0 -138
  127. data/test/protocol/01/tc_impl.rb +0 -294
  128. data/test/protocol/01/tc_packet_assistant.rb +0 -81
  129. data/test/protocol/02/tc_impl.rb +0 -41
  130. data/test/protocol/02/tc_packet_assistant.rb +0 -31
  131. data/test/protocol/03/tc_impl.rb +0 -48
  132. data/test/protocol/03/tc_packet_assistant.rb +0 -34
  133. data/test/protocol/04/tc_attributes.rb +0 -174
  134. data/test/protocol/04/tc_impl.rb +0 -91
  135. data/test/protocol/04/tc_packet_assistant.rb +0 -38
  136. data/test/protocol/05/tc_impl.rb +0 -61
  137. data/test/protocol/05/tc_packet_assistant.rb +0 -32
  138. data/test/protocol/tc_driver.rb +0 -219
@@ -1,84 +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
- module Net ; module SFTP ; module Protocol
18
-
19
- # This is the abstract base class for all packet assistant classes used by
20
- # the supported SFTP protocol versions.
21
- class PacketAssistant
22
-
23
- # A helper method for defining a new packet type. The +name+ is the name
24
- # of the packet (and of the corresponding method that is created), and the
25
- # arguments are symbols representing the types of each element in the
26
- # packet. The supported types are:
27
- #
28
- # * :long
29
- # * :int64
30
- # * :short
31
- # * :byte
32
- # * :string
33
- # * :attrs
34
- # * :write
35
- #
36
- # The :attrs and :write types both simply convert the argument to a string.
37
- #
38
- # The method that is created always supports an +id+ parameter in the
39
- # first position, which if null will default to the next available request
40
- # id. The method returns a tuple consisting of the request id, and a string
41
- # consisting of the arguments formatted according to the packet's
42
- # description.
43
- def self.packet( name, *args )
44
- body = ""
45
- args.each do |arg|
46
- body << "b.write"
47
- case arg
48
- when :long, :int64, :short, :byte
49
- body << "_#{arg} args.shift.to_i"
50
- when :string
51
- body << "_#{arg} args.shift.to_s"
52
- when :attrs, :write
53
- body << " args.shift.to_s"
54
- end
55
- body << "\n"
56
- end
57
- class_eval <<-EOF, __FILE__, __LINE__+1
58
- def #{name}( id, *args )
59
- b = buffers.writer
60
- id ||= driver.next_request_id
61
- b.write_long id
62
- #{body}
63
- [ id, b.to_s ]
64
- end
65
- EOF
66
- end
67
-
68
- # The buffer factory in use by this packet assistant, used to build the
69
- # packets.
70
- attr_reader :buffers
71
-
72
- # The protocol driver that will be used to obtain request ids.
73
- attr_reader :driver
74
-
75
- # Create a new PacketAssistant, which will use the given buffer factory and
76
- # SFTP protocol driver.
77
- def initialize( buffers, driver )
78
- @buffers = buffers
79
- @driver = driver
80
- end
81
-
82
- end
83
-
84
- end ; end ; end
@@ -1,55 +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
- module Net ; module SFTP ; module Protocol
18
-
19
- def register_services( container )
20
- container.namespace_define :protocol do |ns|
21
-
22
- # The maximum version of the SFTP protocol supported by this
23
- # implementation. Clients may set this to a lower value to force the
24
- # usage of a specific SFTP version. It should _not_ be set higher than
25
- # the value that is given below.
26
- ns.version { 5 }
27
-
28
- # A proc object that, when invoked, returns a dispatcher object capable
29
- # of handling the requested protocol version.
30
- ns.dispatcher_factory do |c,|
31
- lambda do |version, extensions|
32
- version = "%02d" % version
33
- c.require "net/sftp/protocol/#{version}/services",
34
- "#{self}::V_#{version}"
35
- impl = c["v_#{version}".to_sym][:impl]
36
- impl.extensions = extensions
37
- impl
38
- end
39
- end
40
-
41
- # The driver service that manages the SFTP protocol-level communications
42
- ns.driver do |c,p|
43
- require 'net/sftp/protocol/driver'
44
- Driver.new( c[:connection][:driver],
45
- c[:transport][:buffers],
46
- c[:version],
47
- c[:dispatcher_factory],
48
- c[:log_for, p] )
49
- end
50
-
51
- end
52
- end
53
- module_function :register_services
54
-
55
- end ; end ; end
data/lib/uri/open-sftp.rb DELETED
@@ -1,54 +0,0 @@
1
- # =======================================================================
2
- # Net::SSH -- A Ruby module implementing the SSH2 client protocol
3
- # Copyright (C) 2004 Jamis Buck (jamis@37signals.com)
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
- # =======================================================================
19
-
20
- require 'open-uri'
21
- require 'uri/sftp'
22
- require 'net/sftp'
23
-
24
- OpenURI::Options[ :chunk_size ] = true
25
-
26
- module URI
27
-
28
- class SFTP
29
- def direct_open( buf, open_options )
30
- Net::SFTP.start( host, port, user, password, options ) do |sftp|
31
- if open_options[:content_length_proc]
32
- open_options[:content_length_proc].call( sftp.lstat( path ).size )
33
- end
34
-
35
- body = nil
36
- sftp.open_handle( path ) do |handle|
37
- body = sftp.read( handle,
38
- :chunk_size => open_options[:chunk_size],
39
- :progress_callback => open_options[:progress_proc] )
40
- end
41
-
42
- if body.nil?
43
- raise Net::SSH::SFTP::SFTPError, sftp.status[:message]
44
- end
45
-
46
- buf << body
47
- buf.io.rewind
48
- end
49
- end
50
-
51
- include OpenURI::OpenRead
52
- end
53
-
54
- end
data/lib/uri/sftp.rb DELETED
@@ -1,42 +0,0 @@
1
- require 'uri/generic'
2
-
3
- module URI
4
-
5
- class SFTP < Generic
6
- DEFAULT_PORT = 22
7
-
8
- COMPONENT = [
9
- :scheme,
10
- :userinfo,
11
- :host, :port, :path,
12
- :query
13
- ].freeze
14
-
15
- attr_reader :options
16
-
17
- def self.new2( user, password, host, port, path, query )
18
- new( 'sftp',
19
- [ user, password ],
20
- host, port,
21
- nil, path,
22
- nil, query )
23
- end
24
-
25
- def initialize( *args )
26
- super( *args )
27
-
28
- @options = Hash.new
29
- ( query || "" ).split( /&/ ).each do |pair|
30
- name, value = pair.split( /=/ )
31
- opt_name = name.intern
32
- values = value.split( /,/ ).map { |v| v.to_i.to_s == v ? v.to_i : v }
33
- values = values.first if values.length == 1
34
- options[ opt_name ] = values
35
- end
36
- end
37
-
38
- end
39
-
40
- @@schemes['SFTP'] = SFTP
41
-
42
- end
data/test/ALL-TESTS.rb DELETED
@@ -1,23 +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
- gem "flexmock", "< 0.1"
18
-
19
- $:.unshift "../lib"
20
-
21
- $run_integration_tests = ARGV.include?( "-i" )
22
-
23
- Dir["**/tc_*.rb"].each { |f| load f }
@@ -1,124 +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/abstract'
21
- require 'flexmock'
22
-
23
- class TC_Operations_Abstract < Test::Unit::TestCase
24
-
25
- class Subclass < Net::SFTP::Operations::Abstract
26
- attr_reader :args
27
-
28
- def perform( *args )
29
- @args = args
30
- 14
31
- end
32
- end
33
-
34
- def setup
35
- @log = FlexMock.new
36
- @log.mock_handle( :debug )
37
- @log.mock_handle( :debug? )
38
-
39
- @session = FlexMock.new
40
- @session.mock_handle( :status= )
41
- @session.mock_handle( :register )
42
- @session.mock_handle( :loop )
43
-
44
- @driver = FlexMock.new
45
-
46
- @operation = Subclass.new( @log, @session, @driver )
47
- end
48
-
49
- def test_execute_no_block
50
- reg_args = nil
51
- @session.mock_handle( :register ) { |*a| reg_args = a }
52
-
53
- @operation.execute( :foo, :bar )
54
-
55
- assert_equal 1, @session.mock_count( :register )
56
- assert_equal 1, @session.mock_count( :loop )
57
- assert_equal [ 14, @operation ], reg_args
58
- assert_equal [ :foo, :bar ], @operation.args
59
- end
60
-
61
- def test_execute_with_block
62
- reg_args = nil
63
- @session.mock_handle( :register ) { |*a| reg_args = a }
64
-
65
- @operation.execute( :foo, :bar ) { }
66
-
67
- assert_equal 1, @session.mock_count( :register )
68
- assert_equal 0, @session.mock_count( :loop )
69
- assert_equal [ 14, @operation ], reg_args
70
- assert_equal [ :foo, :bar ], @operation.args
71
- end
72
-
73
- def test_do_status_bad
74
- assert_raise( Net::SFTP::Operations::StatusException ) do
75
- @operation.do_status( 5, nil, nil )
76
- end
77
- end
78
-
79
- def test_status_ok
80
- status = nil
81
- @operation.execute( :foo, :bar ) { |s| status = s }
82
- assert_nothing_raised { @operation.do_status( 0, "hello", "world" ) }
83
- assert_equal 0, status.code
84
- assert_equal "hello", status.message
85
- assert_equal "world", status.language
86
- end
87
-
88
- def test_do_handle
89
- status = nil
90
- handle = nil
91
- @operation.execute( :foo, :bar ) { |s,h| status, handle = s, h }
92
- @operation.do_handle( "foo" )
93
- assert_equal 0, status.code
94
- assert_equal "foo", handle
95
- end
96
-
97
- def test_do_data
98
- status = nil
99
- data = nil
100
- @operation.execute( :foo, :bar ) { |s,d| status, data = s, d }
101
- @operation.do_data( "foo" )
102
- assert_equal 0, status.code
103
- assert_equal "foo", data
104
- end
105
-
106
- def test_do_name
107
- status = nil
108
- name = nil
109
- @operation.execute( :foo, :bar ) { |s,n| status, name = s, n }
110
- @operation.do_name( "foo" )
111
- assert_equal 0, status.code
112
- assert_equal "foo", name
113
- end
114
-
115
- def test_do_attrs
116
- status = nil
117
- attrs = nil
118
- @operation.execute( :foo, :bar ) { |s,a| status, attrs = s, a }
119
- @operation.do_attrs( "foo" )
120
- assert_equal 0, status.code
121
- assert_equal "foo", attrs
122
- end
123
-
124
- 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/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
@@ -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/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