class Net::SSH::Test::Script

end

channel = script.opens_channel
story do |script|
Net::SSH::Test#story helper method:
A reference to a script. is generally obtained in a unit test via the
events for packets being received by the local from the remote host.
sent from the local to the remote host, and methods named “gets_*” create
a test expects. Methods named “sends_*” create events for packets being
Represents a sequence of scripted events that identify the behavior that

def gets(type, *args)

list.
A convenience method for adding an arbitrary remote packet to the events
def gets(type, *args)
  events << RemotePacket.new(type, *args)
end

def gets_channel_close(channel)

called via Net::SSH::Test::Channel#gets_close.
the given Net::SSH::Test::Channel +channel+. This will typically be
Scripts the reception of a channel close packet from the remote host by
def gets_channel_close(channel)
  events << RemotePacket.new(:channel_close, channel.local_id)
end

def gets_channel_data(channel, data)

called via Net::SSH::Test::Channel#gets_data.
the given Net::SSH::Test::Channel +channel+. This will typically be
Scripts the reception of a channel data packet from the remote host by
def gets_channel_data(channel, data)
  events << RemotePacket.new(:channel_data, channel.local_id, data)
end

def gets_channel_eof(channel)

called via Net::SSH::Test::Channel#gets_eof.
the given Net::SSH::Test::Channel +channel+. This will typically be
Scripts the reception of a channel EOF packet from the remote host by
def gets_channel_eof(channel)
  events << RemotePacket.new(:channel_eof, channel.local_id)
end

def gets_channel_extended_data(channel, data)

Currently the only extended data type is stderr == 1.

be called via Net::SSH::Test::Channel#gets_extended_data.
host by the given Net::SSH::Test::Channel +channel+. This will typically
Scripts the reception of a channel extended data packet from the remote
def gets_channel_extended_data(channel, data)
  events << RemotePacket.new(:channel_extended_data, channel.local_id, 1, data)
end

def gets_channel_request(channel, request, reply, data)

called via Net::SSH::Test::Channel#gets_exit_status.
the given Net::SSH::Test::Channel +channel+. This will typically be
Scripts the reception of a channel request packet from the remote host by
def gets_channel_request(channel, request, reply, data)
  events << RemotePacket.new(:channel_request, channel.local_id, request, reply, data)
end

def initialize

Create a new, empty script.
def initialize
  @events = []
end

def next(mode = :shift)

event = script.next(:first)
# peek at the next event

event = script.next
# remove the next event and return it

list, by passing :first as the argument.
this can also be used to non-destructively peek at the next event in the
By default, removes the next event in the list and returns it. However,
def next(mode = :shift)
  events.send(mode)
end

def opens_channel(confirm = true)

to script additional channel operations.
A new Net::SSH::Test::Channel instance is returned, which can be used

adding a remote packet confirming the new channel.
channel open request, and if +confirm+ is true (the default), also
Scripts the opening of a channel by adding a local packet sending the
def opens_channel(confirm = true)
  channel = Channel.new(self)
  channel.remote_id = 5555
  events << LocalPacket.new(:channel_open) { |p| channel.local_id = p[:remote_id] }
  events << RemotePacket.new(:channel_open_confirmation, channel.local_id, channel.remote_id, 0x20000, 0x10000) if confirm
  channel
end

def process(packet)

Net::SSH::Test::Extensions::PacketStream#test_enqueue_packet.
no next event, an exception will be raised. This is called by
Compare the given packet against the next event in the list. If there is
def process(packet)
  event = events.shift or raise "end of script reached, but got a packet type #{packet.read_byte}"
  event.process(packet)
end

def sends(type, *args, &block)

list.
A convenience method for adding an arbitrary local packet to the events
def sends(type, *args, &block)
  events << LocalPacket.new(type, *args, &block)
end

def sends_channel_close(channel)

Net::SSH::Test::Channel#sends_close.
Net::SSH::Test::Channel +channel+. This will typically be called via
Scripts the sending of a channel close packet from the given
def sends_channel_close(channel)
  events << LocalPacket.new(:channel_close, channel.remote_id)
end

def sends_channel_data(channel, data)

This will typically be called via Net::SSH::Test::Channel#sends_data.

expect will be sent.
Net::SSH::Test::Channel object, and +data+ is the (string) data to
Scripts the sending of a channel data packet. +channel+ must be a
def sends_channel_data(channel, data)
  events << LocalPacket.new(:channel_data, channel.remote_id, data)
end

def sends_channel_eof(channel)

Net::SSH::Test::Channel#sends_eof.
Net::SSH::Test::Channel +channel+. This will typically be called via
Scripts the sending of a channel EOF packet from the given
def sends_channel_eof(channel)
  events << LocalPacket.new(:channel_eof, channel.remote_id)
end

def sends_channel_request(channel, request, reply, data, success = true)

Net::SSH::Test::Channel#sends_subsystem.
This will typically be called via Net::SSH::Test::Channel#sends_exec or

if +success+ is true, or :channel_failure if +success+ is false.
If a reply is desired, a remote packet will also be queued, :channel_success

data.
success or failure. If +data+ is an array it will be treated as multiple
+success+ indicates whether the response (if one is required) should be
is any additional request-specific data that this packet should send.
indicating whether a response to this packet is required , and +data+
is a string naming the request type to send, +reply+ is a boolean
+channel+ should be an instance of Net::SSH::Test::Channel. +request+
Scripts the sending of a new channel request packet to the remote host.
def sends_channel_request(channel, request, reply, data, success = true)
  if data.is_a? Array
    events << LocalPacket.new(:channel_request, channel.remote_id, request, reply, *data)
  else
    events << LocalPacket.new(:channel_request, channel.remote_id, request, reply, data)
  end
  if reply
    if success
      events << RemotePacket.new(:channel_success, channel.local_id)
    else
      events << RemotePacket.new(:channel_failure, channel.local_id)
    end
  end
end

def sends_channel_request_pty(channel)

Net::SSH::Test::Channel#sends_request_pty.
Net::SSH::Test::Channel +channel+. This will typically be called via
Scripts the sending of a channel request pty packets from the given
def sends_channel_request_pty(channel)
  data = ['pty-req', false]
  data += Net::SSH::Connection::Channel::VALID_PTY_OPTIONS.merge(modes: "\0").values
  events << LocalPacket.new(:channel_request, channel.remote_id, *data)
end