Sha256: dfba067d2077249ecb8bba31218bde4719087991bfa4f935888b5c59a2eda12a

Contents?: true

Size: 1.71 KB

Versions: 166

Compression:

Stored size: 1.71 KB

Contents

require 'net/ssh/packet'
require 'net/ssh/test/packet'

module Net; module SSH; module Test

  # This is a specialization of Net::SSH::Test::Packet for representing mock
  # packets that are sent from the local (client) host. These are created
  # automatically by Net::SSH::Test::Script and Net::SSH::Test::Channel by any
  # of the sends_* methods.
  class LocalPacket < Packet
    attr_reader :init

    # Extend the default Net::SSH::Test::Packet constructor to also accept an
    # optional block, which is used to finalize the initialization of the
    # packet when #process is first called.
    def initialize(type, *args, &block)
      super(type, *args)
      @init = block
    end

    # Returns +true+; this is a local packet.
    def local?
      true
    end

    # Called by Net::SSH::Test::Extensions::PacketStream#test_enqueue_packet
    # to mimic remote processing of a locally-sent packet. It compares the
    # packet it was given with the contents of this LocalPacket's data, to see
    # if what was sent matches what was scripted. If it differs in any way,
    # an exception is raised.
    def process(packet)
      @init.call(Net::SSH::Packet.new(packet.to_s)) if @init
      type = packet.read_byte
      raise "expected #{@type}, but got #{type}" if @type != type

      @data.zip(types).each do |expected, type|
        type ||= case expected
          when nil then break
          when Numeric then :long
          when String then :string
          when TrueClass, FalseClass then :bool
          end

        actual = packet.send("read_#{type}")
        next if expected.nil?
        raise "expected #{type} #{expected.inspect} but got #{actual.inspect}" unless expected == actual
      end
    end
  end

end; end; end

Version data entries

166 entries across 136 versions & 18 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/net-ssh-2.4.0/lib/net/ssh/test/local_packet.rb
tpkg-2.3.5 lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb
tpkg-2.3.4 lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.10 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.11 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.12 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.13 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.14 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.15 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.16 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.17 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.5 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.6 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.7 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
auser-poolparty-1.3.8 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
ddollar-net-ssh-2.0.1 lib/net/ssh/test/local_packet.rb
fairchild-poolparty-1.3.17 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
fairchild-poolparty-1.3.5 vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb
jayniz-net-ssh-2.0.15 lib/net/ssh/test/local_packet.rb
kjvarga-net-ssh-2.0.12 lib/net/ssh/test/local_packet.rb