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
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 58 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
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 71 def test_available_for_read? return true if select_for_read? idle! false end
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 79 def test_enqueue_packet(payload) packet = Net::SSH::Buffer.new(payload.to_s) script.process(packet) end
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 86 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