Sha256: a23873a9dc0855ab6871d61f511fcdbbd5ae4380ed93f26e6a6bfef998dfff98

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

require "helper"
require "fluent/test/driver/formatter"
require "fluent/plugin/formatter_jq"

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

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

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

  test "it should work" do
    d = create_driver 'jq .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 .[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 .[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 .[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

3 entries across 3 versions & 1 rubygems

Version Path
fluent-plugin-jq-0.4.0 test/plugin/test_formatter_jq.rb
fluent-plugin-jq-0.3.0 test/plugin/test_formatter_jq.rb
fluent-plugin-jq-0.2.0 test/plugin/test_formatter_jq.rb