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

  1. lib/net/ssh/test/extensions.rb
Parent: Extensions

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

Included modules

  1. BufferedIo

Public Instance methods

idle! ()

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.

[show source]
# 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? ()

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

[show source]
# 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)

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

[show source]
# 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 ()

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

[show source]
# 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