Sha256: a0be5e6bc56a1bf87e0a55104ae7a3ba34c0f224303b9d652c0c7be6ee9889a8

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

require File.dirname(__FILE__) + '/helper'

class TestSlack < Minitest::Test
  def setup
    @slack = God::Contacts::Slack.new

    # new slack webhook url contains three random 'tokens' with length of 9, 9 and 24 characters
    @slack.url = "https://hooks.slack.com/services/ABCABCABC/DEFDEFDEF/ABCDEFABCDEFABCDEFABCDEF"

    @sample_data = {
      :message => "a sample message",
      :time => "2038-01-01 00:00:00",
      :priority => "High",
      :category => "Test",
      :host => "example.com"
    }
  end

  def test_api_url
    assert_equal @slack.url, @slack.api_url.to_s
  end

  def test_notify
    Net::HTTP.any_instance.expects(:request).returns(Net::HTTPSuccess.new('a', 'b', 'c'))

    @slack.channel = "#ops"

    @slack.notify('msg', Time.now, 'prio', 'cat', 'host')
    assert_equal "successfully notified slack on channel #ops", @slack.info
  end

  def test_default_channel
    Net::HTTP.any_instance.expects(:request).returns(Net::HTTPSuccess.new('a', 'b', 'c'))

    @slack.notify('msg', Time.now, 'prio', 'cat', 'host')
    assert_equal "successfully notified slack on channel #general", @slack.info
  end

  def test_default_formatting
    text = @slack.text(@sample_data)
    assert_equal "High alert on example.com: a sample message (Test, 2038-01-01 00:00:00)", text
  end

  def test_custom_formatting
    @slack.format = "%{host}: %{message}"
    text = @slack.text(@sample_data)
    assert_equal "example.com: a sample message", text
  end

  def test_notify_channel
    @slack.notify_channel = true
    @slack.format = ""
    text = @slack.text(@sample_data)
    assert_equal "<!channel> ", text
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
resurrected_god-0.14.0 test/test_slack.rb
mcproc-2016.2.20 test/test_slack.rb
god-0.13.7 test/test_slack.rb