Sha256: f1abdb505f87ad5dbb63f897e96cda86755822c1336860ed6419d2aa40aee33e

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

require 'helper'

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

  def create_driver(conf)
    Fluent::Test::InputTestDriver.new(Fluent::ExecCronInput).configure(conf)
  end

  def test_configure_full
    d = create_driver %q{
      type exec_cron
      tag exec_cron.example
      command echo '{"a":"a"}'
      format json
      cron * * * * *
      graceful_shutdown false
    }

    assert_equal 'exec_cron.example', d.instance.tag
  end

  def test_configure_error_when_config_is_empty
    assert_raise(Fluent::ConfigError) do
      create_driver ''
    end
  end

  def test_configure_error_cron_syntax
    assert_raise(Fluent::ConfigError) do
      create_driver %q{
        tag exec_cron.example
        command echo '{"a":"a"}'
        format json
        cron hogehoge
        graceful_shutdown false
      }
    end
  end

  def test_configure_placeholder
    d = create_driver %q{
      type exec_cron
      tag exec_cron.example
      command echo '{"a":"${(Date.new(2015, 1, 1) - 1).strftime('%Y/%m/%d')}"}'
      format json
      cron * * * * *
      graceful_shutdown false
    }
    assert_equal %Q{echo '{"a":"2014/12/31"}'}, d.instance.command.result(binding)
  end

  def test_emit
    d = create_driver %q{
      tag exec_cron.example
      command echo '{"a":"a", "time":"2011-01-02 13:14:15"}'
      format json
      time_key time
      time_format %Y-%m-%d %H:%M:%S
      cron * * * * *
      graceful_shutdown false
    }

    d.run do
      sleep 60
    end

    emits = d.emits
    assert_equal true, emits.length > 0
    assert_equal ["exec_cron.example", Time.parse("2011-01-02 13:14:15").to_i, {"a"=>"a"}], emits[0]
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fluent-plugin-exec_cron-0.0.3 test/plugin/test_in_exec_cron.rb
fluent-plugin-exec_cron-0.0.2 test/plugin/test_in_exec_cron.rb