spec/outputs/slack_spec.rb in logstash-output-slack-0.1.0 vs spec/outputs/slack_spec.rb in logstash-output-slack-0.1.1
- old
+ new
@@ -16,23 +16,46 @@
}
}
CONFIG
end
- let(:long_config) do <<-CONFIG
+ let(:long_formatted_config) do <<-CONFIG
input {
generator {
message => "This message should show in slack"
- add_field => {"extra" => 3}
+ add_field => {"x" => "3"
+ "channelname" => "mychannel"
+ "username" => "slackbot"}
count => 1
}
}
output {
slack {
url => "http://requestb.in/r9lkbzr9"
- format => "%{message} %{extra}"
+ format => "%{message} %{x}"
+ channel => "%{channelname}"
+ username => "%{username}"
+ icon_emoji => ":chart_with_upwards_trend:"
+ icon_url => "http://lorempixel.com/48/48"
+ }
+ }
+ CONFIG
+ end
+
+ let(:long_unformatted_config) do <<-CONFIG
+ input {
+ generator {
+ message => "This message should not show in slack"
+ count => 1
+ }
+ }
+
+ output {
+ slack {
+ url => "http://requestb.in/r9lkbzr9"
+ format => "Unformatted message"
channel => "mychannel"
username => "slackbot"
icon_emoji => ":chart_with_upwards_trend:"
icon_url => "http://lorempixel.com/48/48"
}
@@ -69,11 +92,11 @@
'User-Agent' => 'logstash-output-slack'
})).
to have_been_made.once
end
- it "uses all provided values" do
+ it "uses and formats all provided values" do
stub_request(:post, "requestb.in").
to_return(:body => "", :status => 200,
:headers => { 'Content-Length' => 0 })
expected_json = {
@@ -82,11 +105,11 @@
:username => "slackbot",
:icon_emoji => ":chart_with_upwards_trend:",
:icon_url => "http://lorempixel.com/48/48"
}
- LogStash::Pipeline.new(long_config).run
+ LogStash::Pipeline.new(long_formatted_config).run
expect(a_request(:post, "http://requestb.in/r9lkbzr9").
with(:body => "payload=#{CGI.escape(JSON.dump(expected_json))}",
:headers => {
'Content-Type' => 'application/x-www-form-urlencoded',
@@ -94,7 +117,31 @@
'User-Agent' => 'logstash-output-slack'
})).
to have_been_made.once
end
+ it "uses and formats all provided values" do
+ stub_request(:post, "requestb.in").
+ to_return(:body => "", :status => 200,
+ :headers => { 'Content-Length' => 0 })
+
+ expected_json = {
+ :text => "Unformatted message",
+ :channel => "mychannel",
+ :username => "slackbot",
+ :icon_emoji => ":chart_with_upwards_trend:",
+ :icon_url => "http://lorempixel.com/48/48"
+ }
+
+ LogStash::Pipeline.new(long_unformatted_config).run
+
+ expect(a_request(:post, "http://requestb.in/r9lkbzr9").
+ with(:body => "payload=#{CGI.escape(JSON.dump(expected_json))}",
+ :headers => {
+ 'Content-Type' => 'application/x-www-form-urlencoded',
+ 'Accept'=> 'application/json',
+ 'User-Agent' => 'logstash-output-slack'
+ })).
+ to have_been_made.once
+ end
end
end