Sha256: 223e0ce8fc5becaf68135bcc10761d3120ba8d06517626b8fc9966b621931844

Contents?: true

Size: 778 Bytes

Versions: 19

Compression:

Stored size: 778 Bytes

Contents

require 'grok'
require 'test/unit'

class IPPatternsTest < Test::Unit::TestCase
  def setup
    @grok = Grok.new
    path = "#{File.dirname(__FILE__)}/../../../patterns/base"
    @grok.add_patterns_from_file(path)
  end

  def test_ips
    @grok.compile("%{IP}")
    File.open("#{File.dirname(__FILE__)}/ip.input").each do |line|
      line.chomp!
      match = @grok.match(line)
      assert_not_equal(false, match)
      assert_equal(line, match.captures["IP"][0])
    end
  end

  def test_non_ips
    @grok.compile("%{IP}")
    nonips = %w{255.255.255.256 0.1.a.33 300.1.2.3 300 400.4.3.a 1.2.3.b
                1..3.4.5 hello world}
    nonips << "hello world"
    nonips.each do |input|
      match = @grok.match(input)
      assert_equal(false, match)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
jls-grok-0.4.7 test/patterns/ip.rb
jls-grok-0.4.6 test/patterns/ip.rb
jls-grok-0.4.5 test/patterns/ip.rb
jls-grok-0.4.4 test/patterns/ip.rb
jls-grok-0.4.3 test/patterns/ip.rb
jls-grok-0.4.2 test/patterns/ip.rb
jls-grok-0.4.1 test/patterns/ip.rb
jls-grok-0.3.3209 test/patterns/ip.rb
jls-grok-0.2.3104 test/patterns/ip.rb
jls-grok-0.2.3102 test/patterns/ip.rb
jls-grok-0.2.3092 test/patterns/ip.rb
jls-grok-0.2.3091 test/patterns/ip.rb
jls-grok-0.2.3089 test/patterns/ip.rb
jls-grok-0.2.3071 test/patterns/ip.rb
jls-grok-0.1.3068 test/patterns/ip.rb
jls-grok-0.1.2840 test/patterns/ip.rb
jls-grok-0.1.2824 test/patterns/ip.rb
jls-grok-0.1.2823 test/patterns/ip.rb
jls-grok-0.1.2821 test/patterns/ip.rb