Module Net::SSH::Test::Extensions::PacketStream

  1. lib/net/ssh/test/extensions.rb

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
56:       def idle!
57:         return false unless script.next(:first)
58: 
59:         if script.next(:first).remote?
60:           self.string << script.next.to_s
61:           self.pos = pos
62:         end
63: 
64:         return true
65:       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
69:       def test_available_for_read?
70:         return true if select_for_read?
71:         idle!
72:         false
73:       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
77:       def test_enqueue_packet(payload)
78:         packet = Net::SSH::Buffer.new(payload.to_s)
79:         script.process(packet)
80:       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
84:       def test_poll_next_packet
85:         return nil if available <= 0
86:         packet = Net::SSH::Buffer.new(read_available(4))
87:         length = packet.read_long
88:         Net::SSH::Packet.new(read_available(length))
89:       end