Sha256: 0a9698a7b178e9fa5442ef7de36c2429ee82d81405dd40937e5273dabdecda2b

Contents?: true

Size: 863 Bytes

Versions: 16

Compression:

Stored size: 863 Bytes

Contents

require 'grok'
require 'test/unit'

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

  def test_hosts
    hosts = ["www.google.com", "foo-234.14.AAc5-2.foobar.net",
            "192-455.a.b.c.d."]
    hosts.each do |host|
      match = @grok.match(host)
      assert_not_equal(false, match, "Expected this to match: #{host}")
      assert_equal(host, match.captures["HOSTNAME"][0])
    end
  end

  def test_hosts_in_string
    @grok.compile("%{HOSTNAME =~ /\\./}")
    host = "www.google.com"
    line = "1 2 3 4 #{host} test"
    match = @grok.match(line)
    assert_not_equal(false, match, "Expected this to match: #{line}")
    assert_equal(host, match.captures["HOSTNAME"][0])
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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