Sha256: 4ffb142f301ad778ade7d3087bf3e793663c867ab575d7ce4a65133e3747e3cf

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

Given(/^a packet data file "(.*?)"$/) do |name|
  path = File.expand_path(File.join(File.dirname(__FILE__),
                                    '..', 'packet_data', name))
  case File.extname(name)
  when '.raw'
    @raw = path
  when '.pcap'
    @pcap = path
  else
    fail "Unsupported file extension: #{name}"
  end
end

When(/^I try to parse the file with "(.*?)" class$/) do |parser|
  parser_klass = Pio.const_get(parser)
  if @raw
    @result = parser_klass.read(IO.read(@raw))
  elsif @pcap
    File.open(@pcap) do |file|
      pcap = Pio::Pcap::Frame.read(file)
      pcap.records.each { |each| parser_klass.read each.data }
    end
  else
    fail 'Packet data file is not specified.'
  end
end

When(/^I try to create an exact match from the packet$/) do
  @result = Pio::ExactMatch.new(Pio::PacketIn.read(IO.read(@raw)))
end

Then(/^it should finish successfully$/) do
  # Noop.
end

Then(/^the parsed data have the following field and value:$/) do |table|
  table.hashes.each do |each|
    output = each['field'].split('.').inject(@result) do |memo, method|
      memo.__send__(method)
    end
    expect(output.to_s).to eq(each['value'])
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pio-0.15.2 features/step_definitions/packet_data_steps.rb
pio-0.15.1 features/step_definitions/packet_data_steps.rb
pio-0.15.0 features/step_definitions/packet_data_steps.rb
pio-0.14.0 features/step_definitions/packet_data_steps.rb
pio-0.13.0 features/step_definitions/packet_data_steps.rb
pio-0.12.0 features/step_definitions/packet_data_steps.rb