Sha256: 79e3a76ba51bec3639c8eeb6d519de7b1d3b82e7b02e6bba41d444fff9424229

Contents?: true

Size: 1.9 KB

Versions: 4

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

require 'helper'
require 'fluent/test/driver/parser'
require 'fluent/plugin/in_heroku_syslog_http'

require 'net/http'

# Stolen from fluentd/test/helper.rb
class Hash
  def corresponding_proxies
    @corresponding_proxies ||= []
  end

  def to_masked_element
    self
  end
end

class HerokuSyslogHttpParseTest < Test::Unit::TestCase
  def setup
    Fluent::Test.setup
  end

  def create_driver(conf = {})
    d = Struct.new(:instance).new
    d.instance = Fluent::Plugin::HerokuSyslogHttpParser.new
    d.instance.configure(conf)
    d
  end

  def test_parsing_with_default_conf
    text = '<13>1 2014-01-29T06:25:52.589365+00:00 host app web.1 - foo'
    expected_time = Time.strptime('2014-01-29T07:25:52+01:00', '%Y-%m-%dT%H:%M:%S%z').to_i
    event = {
      'syslog.pri' => '13',
      'syslog.facility' => 'user',
      'syslog.severity' => 'notice',
      'syslog.hostname' => 'host',
      'syslog.appname' => 'app',
      'syslog.procid' => 'web.1',
      'syslog.timestamp' => '2014-01-29T06:25:52.589365+00:00',
      'message' => 'foo'
    }
    d = create_driver
    d.instance.parse(text) do |time, record|
      assert_equal expected_time, time
      assert_equal event, record
    end
  end

  def test_parsing_pri_conf
    d = create_driver

    d.instance.parse('<13>1 2014-01-29T06:25:52.589365+00:00 host app web.1 - foo') do |_, record|
      assert_equal 'notice', record['syslog.severity']
      assert_equal 'user', record['syslog.facility']
    end
    d.instance.parse('<42>1 2014-01-29T06:25:52.589365+00:00 host app web.1 - foo') do |_, record|
      assert_equal 'crit', record['syslog.severity']
      assert_equal 'syslog', record['syslog.facility']
    end
    d.instance.parse('<27>1 2014-01-29T06:25:52.589365+00:00 host app web.1 - foo') do |_, record|
      assert_equal 'err', record['syslog.severity']
      assert_equal 'daemon', record['syslog.facility']
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fluent-plugin-heroku-syslog-http-0.3 test/plugin/test_parser_heroku_syslog_http.rb
fluent-plugin-heroku-syslog-http-0.2.4 test/plugin/test_parser_heroku_syslog_http.rb
fluent-plugin-heroku-syslog-http-0.2.2 test/plugin/test_parser_heroku_syslog_http.rb
fluent-plugin-heroku-syslog-http-0.2.1 test/plugin/test_parser_heroku_syslog_http.rb