Sha256: fc29d2cb838f51d38a4b95d4a95b610e165e7179f920e46b71410d9bce0cfe45

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

# coding: utf-8

require 'helper'

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

  CONFIG = %[
    type typetalk
    client_id 123456
    client_secret secret
    topic_id 1
    template <%= record.to_json %>
  ]

  def create_driver(conf = CONFIG, tag = 'test')
    Fluent::Test::BufferedOutputTestDriver.new(Fluent::TypetalkOutput, tag).configure(conf)
  end

  def test_configure
    d = create_driver()
    assert_equal d.instance.typetalk.instance_variable_get(:@client_id), '123456'
    assert_equal d.instance.typetalk.instance_variable_get(:@client_secret), 'secret'
  end

  def test_write
    d = create_driver()
    stub(d.instance.typetalk).post(1, '{"message":"test1"}')
    d.emit({'message' => 'test1'})
    d.run()
  end

  def test_template
    d = create_driver(CONFIG, 'warn')
    d.instance.template = "<%= tag %> at <%= Time.at(time).localtime %>\n<%= record.to_json %>"
    stub(d.instance.typetalk).post(1, "warn at 2014-05-13 01:05:38 +0900\n{\"message\":\"test1\"}")

    ENV["TZ"]="Asia/Tokyo"
    t = Time.strptime('2014-05-13 01:05:38', '%Y-%m-%d %T')
    d.emit({'message' => 'test1'}, t)
    d.run()
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-typetalk-0.0.1 test/plugin/test_out_typetalk.rb