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
Этот коммит содержится в:
Chris
2017-07-12 06:43:07 -07:00
коммит произвёл Harrison Healey
родитель 83d53ea98c
Коммит 9ee7f661c7
6 изменённых файлов: 135 добавлений и 58 удалений

Просмотреть файл

@@ -230,3 +230,17 @@ func TestIncomingWebhookRequestFromJson(t *testing.T) {
}
}
}
func TestIncomingWebhookNullArrayItems(t *testing.T) {
payload := `{"attachments":[{"fields":[{"title":"foo","value":"bar","short":true}, null]}, null]}`
iwr := IncomingWebhookRequestFromJson(strings.NewReader(payload))
if iwr == nil {
t.Fatal("IncomingWebhookRequest should not be nil")
}
if len(iwr.Attachments) != 1 {
t.Fatalf("expected one attachment")
}
if len(iwr.Attachments[0].Fields) != 1 {
t.Fatalf("expected one field")
}
}