| Class | Net::SSH::Test::Script |
| In: |
lib/net/ssh/test/script.rb
lib/net/ssh/test/script.rb |
| Parent: | Object |
Represents a sequence of scripted events that identify the behavior that a test expects. Methods named "sends_*" create events for packets being sent from the local to the remote host, and methods named "gets_*" create events for packets being received by the local from the remote host.
A reference to a script. is generally obtained in a unit test via the Net::SSH::Test#story helper method:
story do |script|
channel = script.opens_channel
...
end
| events | [R] | The list of scripted events. These will be Net::SSH::Test::LocalPacket and Net::SSH::Test::RemotePacket instances. |
| events | [R] | The list of scripted events. These will be Net::SSH::Test::LocalPacket and Net::SSH::Test::RemotePacket instances. |
A convenience method for adding an arbitrary remote packet to the events list.
# File lib/net/ssh/test/script.rb, line 56
56: def gets(type, *args)
57: events << RemotePacket.new(type, *args)
58: end
A convenience method for adding an arbitrary remote packet to the events list.
# File lib/net/ssh/test/script.rb, line 56
56: def gets(type, *args)
57: events << RemotePacket.new(type, *args)
58: end
Scripts the reception of a channel close packet from the remote host by the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#gets_close.
# File lib/net/ssh/test/script.rb, line 131
131: def gets_channel_close(channel)
132: events << RemotePacket.new(:channel_close, channel.local_id)
133: end
Scripts the reception of a channel close packet from the remote host by the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#gets_close.
# File lib/net/ssh/test/script.rb, line 131
131: def gets_channel_close(channel)
132: events << RemotePacket.new(:channel_close, channel.local_id)
133: end
Scripts the reception of a channel data packet from the remote host by the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#gets_data.
# File lib/net/ssh/test/script.rb, line 110
110: def gets_channel_data(channel, data)
111: events << RemotePacket.new(:channel_data, channel.local_id, data)
112: end
Scripts the reception of a channel data packet from the remote host by the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#gets_data.
# File lib/net/ssh/test/script.rb, line 110
110: def gets_channel_data(channel, data)
111: events << RemotePacket.new(:channel_data, channel.local_id, data)
112: end
Scripts the reception of a channel EOF packet from the remote host by the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#gets_eof.
# File lib/net/ssh/test/script.rb, line 124
124: def gets_channel_eof(channel)
125: events << RemotePacket.new(:channel_eof, channel.local_id)
126: end
Scripts the reception of a channel EOF packet from the remote host by the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#gets_eof.
# File lib/net/ssh/test/script.rb, line 124
124: def gets_channel_eof(channel)
125: events << RemotePacket.new(:channel_eof, channel.local_id)
126: end
Scripts the reception of a channel request packet from the remote host by the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#gets_exit_status.
# File lib/net/ssh/test/script.rb, line 117
117: def gets_channel_request(channel, request, reply, data)
118: events << RemotePacket.new(:channel_request, channel.local_id, request, reply, data)
119: end
Scripts the reception of a channel request packet from the remote host by the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#gets_exit_status.
# File lib/net/ssh/test/script.rb, line 117
117: def gets_channel_request(channel, request, reply, data)
118: events << RemotePacket.new(:channel_request, channel.local_id, request, reply, data)
119: end
By default, removes the next event in the list and returns it. However, this can also be used to non-destructively peek at the next event in the list, by passing :first as the argument.
# remove the next event and return it event = script.next # peek at the next event event = script.next(:first)
# File lib/net/ssh/test/script.rb, line 144
144: def next(mode=:shift)
145: events.send(mode)
146: end
By default, removes the next event in the list and returns it. However, this can also be used to non-destructively peek at the next event in the list, by passing :first as the argument.
# remove the next event and return it event = script.next # peek at the next event event = script.next(:first)
# File lib/net/ssh/test/script.rb, line 144
144: def next(mode=:shift)
145: events.send(mode)
146: end
Scripts the opening of a channel by adding a local packet sending the channel open request, and if confirm is true (the default), also adding a remote packet confirming the new channel.
A new Net::SSH::Test::Channel instance is returned, which can be used to script additional channel operations.
# File lib/net/ssh/test/script.rb, line 35
35: def opens_channel(confirm=true)
36: channel = Channel.new(self)
37: channel.remote_id = 5555
38:
39: events << LocalPacket.new(:channel_open) { |p| channel.local_id = p[:remote_id] }
40:
41: if confirm
42: events << RemotePacket.new(:channel_open_confirmation, channel.local_id, channel.remote_id, 0x20000, 0x10000)
43: end
44:
45: channel
46: end
Scripts the opening of a channel by adding a local packet sending the channel open request, and if confirm is true (the default), also adding a remote packet confirming the new channel.
A new Net::SSH::Test::Channel instance is returned, which can be used to script additional channel operations.
# File lib/net/ssh/test/script.rb, line 35
35: def opens_channel(confirm=true)
36: channel = Channel.new(self)
37: channel.remote_id = 5555
38:
39: events << LocalPacket.new(:channel_open) { |p| channel.local_id = p[:remote_id] }
40:
41: if confirm
42: events << RemotePacket.new(:channel_open_confirmation, channel.local_id, channel.remote_id, 0x20000, 0x10000)
43: end
44:
45: channel
46: end
Compare the given packet against the next event in the list. If there is no next event, an exception will be raised. This is called by Net::SSH::Test::Extensions::PacketStream#test_enqueue_packet.
# File lib/net/ssh/test/script.rb, line 151
151: def process(packet)
152: event = events.shift or raise "end of script reached, but got a packet type #{packet.read_byte}"
153: event.process(packet)
154: end
Compare the given packet against the next event in the list. If there is no next event, an exception will be raised. This is called by Net::SSH::Test::Extensions::PacketStream#test_enqueue_packet.
# File lib/net/ssh/test/script.rb, line 151
151: def process(packet)
152: event = events.shift or raise "end of script reached, but got a packet type #{packet.read_byte}"
153: event.process(packet)
154: end
A convenience method for adding an arbitrary local packet to the events list.
# File lib/net/ssh/test/script.rb, line 50
50: def sends(type, *args, &block)
51: events << LocalPacket.new(type, *args, &block)
52: end
A convenience method for adding an arbitrary local packet to the events list.
# File lib/net/ssh/test/script.rb, line 50
50: def sends(type, *args, &block)
51: events << LocalPacket.new(type, *args, &block)
52: end
Scripts the sending of a channel close packet from the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#sends_close.
# File lib/net/ssh/test/script.rb, line 103
103: def sends_channel_close(channel)
104: events << LocalPacket.new(:channel_close, channel.remote_id)
105: end
Scripts the sending of a channel close packet from the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#sends_close.
# File lib/net/ssh/test/script.rb, line 103
103: def sends_channel_close(channel)
104: events << LocalPacket.new(:channel_close, channel.remote_id)
105: end
Scripts the sending of a channel data packet. channel must be a Net::SSH::Test::Channel object, and data is the (string) data to expect will be sent.
This will typically be called via Net::SSH::Test::Channel#sends_data.
# File lib/net/ssh/test/script.rb, line 89
89: def sends_channel_data(channel, data)
90: events << LocalPacket.new(:channel_data, channel.remote_id, data)
91: end
Scripts the sending of a channel data packet. channel must be a Net::SSH::Test::Channel object, and data is the (string) data to expect will be sent.
This will typically be called via Net::SSH::Test::Channel#sends_data.
# File lib/net/ssh/test/script.rb, line 89
89: def sends_channel_data(channel, data)
90: events << LocalPacket.new(:channel_data, channel.remote_id, data)
91: end
Scripts the sending of a channel EOF packet from the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#sends_eof.
# File lib/net/ssh/test/script.rb, line 96
96: def sends_channel_eof(channel)
97: events << LocalPacket.new(:channel_eof, channel.remote_id)
98: end
Scripts the sending of a channel EOF packet from the given Net::SSH::Test::Channel channel. This will typically be called via Net::SSH::Test::Channel#sends_eof.
# File lib/net/ssh/test/script.rb, line 96
96: def sends_channel_eof(channel)
97: events << LocalPacket.new(:channel_eof, channel.remote_id)
98: end
Scripts the sending of a new channel request packet to the remote host. channel should be an instance of Net::SSH::Test::Channel. request is a string naming the request type to send, reply is a boolean indicating whether a response to this packet is required , and data is any additional request-specific data that this packet should send. success indicates whether the response (if one is required) should be success or failure.
If a reply is desired, a remote packet will also be queued, :channel_success if success is true, or :channel_failure if success is false.
This will typically be called via Net::SSH::Test::Channel#sends_exec or Net::SSH::Test::Channel#sends_subsystem.
# File lib/net/ssh/test/script.rb, line 73
73: def sends_channel_request(channel, request, reply, data, success=true)
74: events << LocalPacket.new(:channel_request, channel.remote_id, request, reply, data)
75: if reply
76: if success
77: events << RemotePacket.new(:channel_success, channel.local_id)
78: else
79: events << RemotePacket.new(:channel_failure, channel.local_id)
80: end
81: end
82: end
Scripts the sending of a new channel request packet to the remote host. channel should be an instance of Net::SSH::Test::Channel. request is a string naming the request type to send, reply is a boolean indicating whether a response to this packet is required , and data is any additional request-specific data that this packet should send. success indicates whether the response (if one is required) should be success or failure.
If a reply is desired, a remote packet will also be queued, :channel_success if success is true, or :channel_failure if success is false.
This will typically be called via Net::SSH::Test::Channel#sends_exec or Net::SSH::Test::Channel#sends_subsystem.
# File lib/net/ssh/test/script.rb, line 73
73: def sends_channel_request(channel, request, reply, data, success=true)
74: events << LocalPacket.new(:channel_request, channel.remote_id, request, reply, data)
75: if reply
76: if success
77: events << RemotePacket.new(:channel_success, channel.local_id)
78: else
79: events << RemotePacket.new(:channel_failure, channel.local_id)
80: end
81: end
82: end