Sha256: e089679261243f8544413f82751e39eebeba81f31678b7e1c90681876b685d76

Contents?: true

Size: 1.87 KB

Versions: 1

Compression:

Stored size: 1.87 KB

Contents

require_relative '../test_helper'
require 'fluent/plugin/slack_client'
require 'time'
require 'dotenv'

# HOW TO RUN
#
# Create .env file with contents as:
#
#     WEBHOOK_URL=https://hooks.slack.com/services/XXXX/YYYY/ZZZZ
#     TOKEN=XXXXX
#
Dotenv.load
if ENV['WEBHOOK_URL'] and ENV['TOKEN']
  class SlackClientTest < Test::Unit::TestCase
    def setup
      super
      @incoming_webhook = Fluent::SlackClient::IncomingWebhook.new(ENV['WEBHOOK_URL'])
      @api = Fluent::SlackClient::WebApi.new
    end

    def token(client)
      client == @api ? {token: ENV['TOKEN']} : {}
    end

    def test_text
      [@incoming_webhook, @api].each do |slack|
        assert_nothing_raised do
          slack.post_message(
            {
              channel:     '#general',
              username:    'fluentd',
              icon_emoji:  ':question:',
              attachments: [{
                color:    'good',
                fallback: "sowawa1\nsowawa2\n",
                text:     "sowawa1\nsowawa2\n",
              }]
            }.merge(token(slack))
          )
        end
      end
    end

    def test_fields
      [@incoming_webhook, @api].each do |slack|
        assert_nothing_raised do
          slack.post_message(
            {
              channel:     '#general',
              username:    'fluentd',
              icon_emoji:  ':question:',
              attachments: [{
                color:    'good',
                fallback: 'test1 test2',
                fields:   [
                  {
                    title: 'test1',
                    value: "[07:00:00] sowawa1\n[07:00:00] sowawa2\n",
                  },
                  {
                    title: 'test2',
                    value: "[07:00:00] sowawa1\n[07:00:00] sowawa2\n",
                  },
                ],
              }]
            }.merge(token(slack))
          )
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-slack-0.5.0 test/plugin/test_slack_client.rb