Class: Net::SSH::Test::Channel

### Home Classes Methods

### In Files

- lib/net/ssh/test/channel.rb

### Parent

Object

### Methods

- ::new
- #gets_close
- #gets_data
- #gets_eof
- #gets_exit_status
- #gets_extended_data
- #inject_remote_delay!
- #local_id
- #remote_id
- #sends_close
- #sends_data
- #sends_eof
- #sends_exec
- #sends_subsystem

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Net
- Net::SSH
- Net::SSH::Authentication
- Net::SSH::Authentication::Agent
- Net::SSH::Authentication::Agent::Comment
- Net::SSH::Authentication::AgentError
- Net::SSH::Authentication::AgentNotAvailable
- Net::SSH::Authentication::Constants
- Net::SSH::Authentication::DisallowedMethod
- Net::SSH::Authentication::KeyManager
- Net::SSH::Authentication::KeyManagerError
- Net::SSH::Authentication::Methods
- Net::SSH::Authentication::Methods::Abstract
- Net::SSH::Authentication::Methods::Hostbased
- Net::SSH::Authentication::Methods::KeyboardInteractive
- Net::SSH::Authentication::Methods::None
- Net::SSH::Authentication::Methods::Password
- Net::SSH::Authentication::Methods::Publickey
- Net::SSH::Authentication::Session
- Net::SSH::AuthenticationFailed
- Net::SSH::Buffer
- Net::SSH::ChannelOpenFailed
- Net::SSH::ChannelRequestFailed
- Net::SSH::Compat
- Net::SSH::Config
- Net::SSH::Connection
- Net::SSH::Connection::Channel
- Net::SSH::Connection::Constants
- Net::SSH::Connection::Keepalive
- Net::SSH::Connection::Session
- Net::SSH::Connection::Session::NilChannel
- Net::SSH::Connection::Term
- Net::SSH::ConnectionTimeout
- Net::SSH::Disconnect
- Net::SSH::Exception
- Net::SSH::HostKeyError
- Net::SSH::HostKeyMismatch
- Net::SSH::HostKeyUnknown
- Net::SSH::KeyFactory
- Net::SSH::KnownHosts
- Net::SSH::Loggable
- Net::SSH::Packet
- Net::SSH::PromptMethods
- Net::SSH::PromptMethods::Clear
- Net::SSH::PromptMethods::Highline
- Net::SSH::PromptMethods::Termios
- Net::SSH::Proxy
- Net::SSH::Proxy::Command
- Net::SSH::Proxy::ConnectError
- Net::SSH::Proxy::Error
- Net::SSH::Proxy::HTTP
- Net::SSH::Proxy::SOCKS4
- Net::SSH::Proxy::SOCKS5
- Net::SSH::Proxy::UnauthorizedError
- Net::SSH::Test
- Net::SSH::Test::Channel
- Net::SSH::Test::Extensions
- Net::SSH::Test::Extensions::BufferedIo
- Net::SSH::Test::Extensions::Channel
- Net::SSH::Test::Extensions::IO
- Net::SSH::Test::Extensions::IO::ClassMethods
- Net::SSH::Test::Extensions::PacketStream
- Net::SSH::Test::Kex
- Net::SSH::Test::LocalPacket
- Net::SSH::Test::Packet
- Net::SSH::Test::RemotePacket
- Net::SSH::Test::Script
- Net::SSH::Test::Socket
- Net::SSH::Timeout
- Net::SSH::Transport
- Net::SSH::Transport::Algorithms
- Net::SSH::Transport::CTR
- Net::SSH::Transport::CipherFactory
- Net::SSH::Transport::Constants
- Net::SSH::Transport::HMAC
- Net::SSH::Transport::HMAC::Abstract
- Net::SSH::Transport::HMAC::MD5
- Net::SSH::Transport::HMAC::MD5_96
- Net::SSH::Transport::HMAC::None
- Net::SSH::Transport::HMAC::RIPEMD160
- Net::SSH::Transport::HMAC::SHA1
- Net::SSH::Transport::HMAC::SHA1_96
- Net::SSH::Transport::HMAC::SHA2_256
- Net::SSH::Transport::HMAC::SHA2_256_96
- Net::SSH::Transport::HMAC::SHA2_512
- Net::SSH::Transport::HMAC::SHA2_512_96
- Net::SSH::Transport::IdentityCipher
- Net::SSH::Transport::Kex
- Net::SSH::Transport::Kex::DiffieHellmanGroup14SHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA256
- Net::SSH::Transport::Kex::EcdhSHA2NistP256
- Net::SSH::Transport::Kex::EcdhSHA2NistP384
- Net::SSH::Transport::Kex::EcdhSHA2NistP521
- Net::SSH::Transport::KeyExpander
- Net::SSH::Transport::PacketStream
- Net::SSH::Transport::ServerVersion
- Net::SSH::Transport::Session
- Net::SSH::Transport::State
- Net::SSH::Verifiers
- Net::SSH::Verifiers::Lenient
- Net::SSH::Verifiers::Null
- Net::SSH::Verifiers::Secure
- Net::SSH::Verifiers::Strict
- Net::SSH::Version
- OpenSSL
- OpenSSL::BN
- OpenSSL::PKey
- OpenSSL::PKey::DH
- OpenSSL::PKey::DSA
- OpenSSL::PKey::EC
- OpenSSL::PKey::OpenSSL
- OpenSSL::PKey::OpenSSL::PKey
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL::PKey
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL::PKey::ECError
- OpenSSL::PKey::PKey
- OpenSSL::PKey::RSA
- String

No matching classes.

# Net::SSH::Test::Channel

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_extended_data "some error coming from 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) click to toggle source

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

    # File lib/net/ssh/test/channel.rb, line 29
    def initialize(script)
      @script = script
      @local_id = @remote_id = nil
    end

### Public Instance Methods

gets_close() click to toggle source

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

    channel.gets_close

    # File lib/net/ssh/test/channel.rb, line 133
    def gets_close
      script.gets_channel_close(self)
    end

gets_data(data) click to toggle source

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

    channel.gets_data "bar"

    # File lib/net/ssh/test/channel.rb, line 104
    def gets_data(data)
      script.gets_channel_data(self, data)
    end

gets_eof() click to toggle source

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

    channel.gets_eof

    # File lib/net/ssh/test/channel.rb, line 126
    def gets_eof
      script.gets_channel_eof(self)
    end

gets_exit_status(status=0) click to toggle source

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

    channel.gets_exit_status(127)

    # File lib/net/ssh/test/channel.rb, line 119
    def gets_exit_status(status=0)
      script.gets_channel_request(self, "exit-status", false, status)
    end

gets_extended_data(data) click to toggle source

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

    channel.gets_extended_data "whoops"

    # File lib/net/ssh/test/channel.rb, line 112
    def gets_extended_data(data)
      script.gets_channel_extended_data(self, data)
    end

inject_remote_delay!() click to toggle source

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"

    # File lib/net/ssh/test/channel.rb, line 56
    def inject_remote_delay!
      gets_data("")
    end

local_id() click to toggle source

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!.)

    # File lib/net/ssh/test/channel.rb, line 37
    def local_id
      @local_id || Proc.new { @local_id or raise "local-id has not been set yet!" }
    end

remote_id() click to toggle source

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!.)

    # File lib/net/ssh/test/channel.rb, line 44
    def remote_id
      @remote_id || Proc.new { @remote_id or raise "remote-id has not been set yet!" }
    end

sends_close() click to toggle source

Scripts the sending of a "channel close" packet across the channel.

    channel.sends_close

    # File lib/net/ssh/test/channel.rb, line 97
    def sends_close
      script.sends_channel_close(self)
    end

sends_data(data) click to toggle source

Scripts the sending of a data packet across the channel.

    channel.sends_data "foo"

    # File lib/net/ssh/test/channel.rb, line 83
    def sends_data(data)
      script.sends_channel_data(self, data)
    end

sends_eof() click to toggle source

Scripts the sending of an EOF packet across the channel.

    channel.sends_eof

    # File lib/net/ssh/test/channel.rb, line 90
    def sends_eof
      script.sends_channel_eof(self)
    end

sends_exec(command, reply=true, success=true) click to toggle source

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"

    # File lib/net/ssh/test/channel.rb, line 67
    def sends_exec(command, reply=true, success=true)
      script.sends_channel_request(self, "exec", reply, command, success)
    end

sends_subsystem(subsystem, reply=true, success=true) click to toggle source

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"

    # File lib/net/ssh/test/channel.rb, line 76
    def sends_subsystem(subsystem, reply=true, success=true)
      script.sends_channel_request(self, "subsystem", reply, subsystem, success)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.