Class Net::SSH::Test::Channel

  1. lib/net/ssh/test/channel.rb
Parent: Object

A mock channel, used for scripting actions in tests. It wraps a Net::SSH::Test::Script instance, and delegates to it for the most part. This class has little real functionality on its own, but rather acts as a convenience for scripting channel-related activity for later comparison in a unit test.

story do |session|
  channel = session.opens_channel
  channel.sends_exec "ls"
  channel.gets_data "result of ls"
  channel.gets_close
  channel.sends_close
end

Attributes

local_id [W] Sets the local-id of this channel object (the id assigned by the client).
remote_id [W] Sets the remote-id of this channel object (the id assigned by the mock-server).
script [R] The Net::SSH::Test::Script instance employed by this mock channel.

Public class methods

new (script)

Creates a new Test::Channel instance on top of the given script (which must be a Net::SSH::Test::Script instance).

[show source]
    # File lib/net/ssh/test/channel.rb, line 28
28:     def initialize(script)
29:       @script = script
30:       @local_id = @remote_id = nil
31:     end

Public instance methods

gets_close ()

Scripts the reception of a “channel close” packet from the remote end.

channel.gets_close
[show source]
     # File lib/net/ssh/test/channel.rb, line 124
124:     def gets_close
125:       script.gets_channel_close(self)
126:     end
gets_data (data)

Scripts the reception of a channel data packet from the remote end.

channel.gets_data "bar"
[show source]
     # File lib/net/ssh/test/channel.rb, line 103
103:     def gets_data(data)
104:       script.gets_channel_data(self, data)
105:     end
gets_eof ()

Scripts the reception of an EOF packet from the remote end.

channel.gets_eof
[show source]
     # File lib/net/ssh/test/channel.rb, line 117
117:     def gets_eof
118:       script.gets_channel_eof(self)
119:     end
gets_exit_status (status=0)

Scripts the reception of an “exit-status” channel request packet.

channel.gets_exit_status(127)
[show source]
     # File lib/net/ssh/test/channel.rb, line 110
110:     def gets_exit_status(status=0)
111:       script.gets_channel_request(self, "exit-status", false, status)
112:     end
inject_remote_delay! ()

Because adjacent calls to gets_data will sometimes cause the data packets to be concatenated (causing expectations in tests to fail), you may need to separate those calls with calls to inject_remote_delay! (which essentially just mimics receiving an empty data packet):

channel.gets_data "abcdefg"
channel.inject_remote_delay!
channel.gets_data "hijklmn"
[show source]
    # File lib/net/ssh/test/channel.rb, line 55
55:     def inject_remote_delay!
56:       gets_data("")
57:     end
local_id ()

Returns the local (client-assigned) id for this channel, or a Proc object that will return the local-id later if the local id has not yet been set. (See Net::SSH::Test::Packet#instantiate!.)

[show source]
    # File lib/net/ssh/test/channel.rb, line 36
36:     def local_id
37:       @local_id || Proc.new { @local_id or raise "local-id has not been set yet!" }
38:     end
remote_id ()

Returns the remote (server-assigned) id for this channel, or a Proc object that will return the remote-id later if the remote id has not yet been set. (See Net::SSH::Test::Packet#instantiate!.)

[show source]
    # File lib/net/ssh/test/channel.rb, line 43
43:     def remote_id
44:       @remote_id || Proc.new { @remote_id or raise "remote-id has not been set yet!" }
45:     end
sends_close ()

Scripts the sending of a “channel close” packet across the channel.

channel.sends_close
[show source]
    # File lib/net/ssh/test/channel.rb, line 96
96:     def sends_close
97:       script.sends_channel_close(self)
98:     end
sends_data (data)

Scripts the sending of a data packet across the channel.

channel.sends_data "foo"
[show source]
    # File lib/net/ssh/test/channel.rb, line 82
82:     def sends_data(data)
83:       script.sends_channel_data(self, data)
84:     end
sends_eof ()

Scripts the sending of an EOF packet across the channel.

channel.sends_eof
[show source]
    # File lib/net/ssh/test/channel.rb, line 89
89:     def sends_eof
90:       script.sends_channel_eof(self)
91:     end
sends_exec (command, reply=true, success=true)

Scripts the sending of an “exec” channel request packet to the mock server. If reply is true, then the server is expected to reply to the request, otherwise no response to this request will be sent. If success is true, then the request will be successful, otherwise a failure will be scripted.

channel.sends_exec "ls -l"
[show source]
    # File lib/net/ssh/test/channel.rb, line 66
66:     def sends_exec(command, reply=true, success=true)
67:       script.sends_channel_request(self, "exec", reply, command, success)
68:     end
sends_subsystem (subsystem, reply=true, success=true)

Scripts the sending of a “subsystem” channel request packet to the mock server. See sends_exec for a discussion of the meaning of the reply and success arguments.

channel.sends_subsystem "sftp"
[show source]
    # File lib/net/ssh/test/channel.rb, line 75
75:     def sends_subsystem(subsystem, reply=true, success=true)
76:       script.sends_channel_request(self, "subsystem", reply, subsystem, success)
77:     end