Sha256: 1f1ba49ae7beba621962d44c02f2748beb62c62992f1488592125ebb01ecf040

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require "helper"
require "fluent/plugin/formatter_jq.rb"

class JqFormatterTest < Test::Unit::TestCase
  setup do
    Fluent::Test.setup
  end

  test "it should require jq_program" do
    assert_raise(Fluent::ConfigError) { create_driver '' }
  end

  test "it should raise error on invalid jq program" do
    e = assert_raise(Fluent::ConfigError) { create_driver 'jq_program blah' }
    assert_match /compile error/, e.message
  end

  test "it should work" do
    d = create_driver 'jq_program .log'
    record = {"log" => "this is a log", "source" => "stdout"}
    text = d.instance.format("some.tag", event_time, record)
    assert_equal record["log"], text
  end

  test "it should ignore error by default" do
    d = create_driver 'jq_program .[1]'
    record = {"log" => "some message"}
    text = d.instance.format "some.tag", event_time, record
    assert_equal record.to_json, text
  end

  test "it can skip on error" do
    d = create_driver "jq_program .[1]\non_error skip"
    record = {"log" => "some message"}
    text = d.instance.format "some.tag", event_time, record
    assert_equal '', text
  end

  test "it can raise error on error" do
    d = create_driver "jq_program .[1]\non_error raise_error"
    record = {"log" => "some message"}
    assert_raise(RuntimeError) {
      d.instance.format "some.tag", event_time, record
    }
  end

  private

  def create_driver(conf)
    Fluent::Test::Driver::Formatter.new(Fluent::Plugin::JqFormatter).configure(conf)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-jq-0.1.0 test/plugin/test_formatter_jq.rb