Sha256: 92bcec352caf68025df2643d559e4fad39eb6cf42554315c651a9c4f868939f3

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

When(/^I parse a file named "(.*?\.raw)" with "(.*?)" class$/) do |path, klass|
  raw_data = IO.read(expand_path("%/#{path}"))
  parser_klass = Pio.const_get(klass)
  @result = parser_klass.read(raw_data)
end

When(/^I parse a file named "(.*?\.pcap)" with "(.*?)" class$/) do |path, klass|
  pcap = Pio::Pcap::Frame.read(IO.read(expand_path("%/#{path}")))
  parser_klass = Pio.const_get(klass)
  @result = pcap.records.each_with_object([]) do |each, result|
    result << parser_klass.read(each.data)
  end
end

When(/^I create an exact match from "(.*?)"$/) do |path|
  raw_data = case File.extname(path)
             when '.raw'
               IO.read(expand_path("%/#{path}"))
             when '.rb'
               Pio.module_eval(IO.read(expand_path("%/#{path}")))
             else
               raise
             end
  @result = Pio::ExactMatch.new(Pio::PacketIn.read(raw_data))
end

Then(/^the message should be a "([^"]*)"$/) do |expected_klass|
  expect(@result.class.to_s).to eq(expected_klass)
end

Then(/^the packet has the following fields and values:$/) do |table|
  table.hashes.each do |each|
    output = @result.instance_eval("self.#{each['field']}")
    if /^:/.match?(output.inspect)
      expect(output.inspect).to eq(each['value'])
    else
      expect(output.to_s).to eq(each['value'])
    end
  end
end

Then(/^the message has the following fields and values:$/) do |table|
  step 'the packet has the following fields and values:', table
end

Then(/^the action has the following fields and values:$/) do |table|
  step 'the packet has the following fields and values:', table
end

# rubocop:disable LineLength
Then(/^the message \#(\d+) have the following fields and values:$/) do |index, table|
  table.hashes.each do |each|
    output = each['field'].split('.').inject(@result[index.to_i - 1]) do |memo, method|
      memo.__send__(method)
    end
    expect(output.to_s).to eq(each['value'])
  end
end
# rubocop:enable LineLength

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pio-0.30.2 features/step_definitions/packet_data_steps.rb