Sha256: 8a9f59b5e167b7bdbf0059ab2d3ee96020324af10a334bc78e3c8baf1b52f911

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

require 'test_helper'
require 'time'

class BufferedSlackOutputTest < Test::Unit::TestCase

  def setup
    super
    Fluent::Test.setup
  end

  CONFIG1 = %[
    type buffered_slack
    api_key testtoken
    team    sowasowa
    channel  %23test
    username testuser
    color    good
    icon_emoji :ghost:
    timezone Asia/Tokyo
    compress gz
    buffer_path ./test/tmp
    utc
  ]

  def create_driver(conf = CONFIG1)
    Fluent::Test::BufferedOutputTestDriver.new(Fluent::BufferedSlackOutput).configure(conf)
  end

  def test_format
    d = create_driver
    time = Time.parse("2014-01-01 22:00:00 UTC").to_i
    d.tag = 'test'
    stub(d.instance.slack).ping(
      nil,
      channel:    '%23test',
      username:   'testuser',
      icon_emoji: ':ghost:',
      attachments: [{
        fallback: d.tag,
        color:    'good',
        fields:   [
          {
            title: d.tag,
            value: "[#{Time.at(time).in_time_zone('Tokyo')}] sowawa\n"
          }]}])
    d.emit({message: 'sowawa'}, time)
    d.expect_format %[#{['test', time, {message: 'sowawa'}].to_msgpack}]
    d.run
  end

  def test_write
    d = create_driver
    time = Time.parse("2014-01-01 22:00:00 UTC").to_i
    d.tag  = 'test'
    stub(d.instance.slack).ping(
      nil,
      channel:    '%23test',
      username:   'testuser',
      icon_emoji: ':ghost:',
      attachments: [{
        fallback: d.tag,
        color:    'good',
        fields:   [
          {
            title: d.tag,
            value: "[#{Time.at(time).in_time_zone('Tokyo')}] sowawa1\n" +
                     "[#{Time.at(time).in_time_zone('Tokyo')}] sowawa2\n"
          }]}])
    d.emit({message: 'sowawa1'}, time)
    d.emit({message: 'sowawa2'}, time)
    d.run
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-slack-0.4.0 test/plugin/test_out_buffered_slack.rb