module Net::SSH::Test::Extensions::PacketStream

An extension to Net::SSH::Transport::PacketStream (assumes that the underlying IO is actually a StringIO). Facilitates unit testing.

Public Instance Methods

idle!() click to toggle source

Called when another packet should be inspected from the current script. If the next packet is a remote packet, it pops it off the script and shoves it onto this IO object, making it available to be read.

# File lib/net/ssh/test/extensions.rb, line 56
def idle!
  return false unless script.next(:first)

  if script.next(:first).remote?
    self.string << script.next.to_s
    self.pos = pos
  end

  return true
end
test_available_for_read?() click to toggle source

The testing version of Net::SSH::Transport::PacketStream#available_for_read?. Returns true if there is data pending to be read. Otherwise calls idle!.

# File lib/net/ssh/test/extensions.rb, line 69
def test_available_for_read?
  return true if select_for_read?
  idle!
  false
end
test_enqueue_packet(payload) click to toggle source

The testing version of Net::SSH::Transport::PacketStream#enqueued_packet. Simply calls Net::SSH::Test::Script#process on the packet.

# File lib/net/ssh/test/extensions.rb, line 77
def test_enqueue_packet(payload)
  packet = Net::SSH::Buffer.new(payload.to_s)
  script.process(packet)
end
test_poll_next_packet() click to toggle source

The testing version of Net::SSH::Transport::PacketStream#poll_next_packet. Reads the next available packet from the IO object and returns it.

# File lib/net/ssh/test/extensions.rb, line 84
def test_poll_next_packet
  return nil if available <= 0
  packet = Net::SSH::Buffer.new(read_available(4))
  length = packet.read_long
  Net::SSH::Packet.new(read_available(length))
end