From 9ee7f661c76d7ef07ac03772a7cf0394217203f3 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 12 Jul 2017 06:43:07 -0700 Subject: PLT-7077: ignore null array items in slack attachments (#6904) * ignore null array items in incoming webhooks / command responses * consolidate code, process announcements in command response as well * make a bit more idiomatic, add tests * add missing file --- model/slack_attachment_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 model/slack_attachment_test.go (limited to 'model/slack_attachment_test.go') diff --git a/model/slack_attachment_test.go b/model/slack_attachment_test.go new file mode 100644 index 000000000..ff4df888f --- /dev/null +++ b/model/slack_attachment_test.go @@ -0,0 +1,38 @@ +package model + +import ( + "testing" +) + +func TestExpandAnnouncement(t *testing.T) { + if ExpandAnnouncement(" foo ") != "@channel foo @channel" { + t.Fail() + } +} + +func TestSlackAnnouncementProcess(t *testing.T) { + attachments := SlackAttachments{ + { + Pretext: " pretext", + Text: " text", + Title: " title", + Fields: []*SlackAttachmentField{ + { + Title: "foo", + Value: " bar", + Short: true, + }, nil, + }, + }, nil, + } + attachments.Process() + if len(attachments) != 1 || len(attachments[0].Fields) != 1 { + t.Fail() + } + if attachments[0].Pretext != "@channel pretext" || + attachments[0].Text != "@channel text" || + attachments[0].Title != "@channel title" || + attachments[0].Fields[0].Value != "@channel bar" { + t.Fail() + } +} -- cgit v1.2.3-1-g7c22