From 5d62b3661bcf4b912e7809ca05082e364e2b34b1 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Wed, 8 Mar 2017 04:15:33 -0500 Subject: Added additional validation for slack attachment format on server (#5680) --- model/incoming_webhook_test.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'model/incoming_webhook_test.go') diff --git a/model/incoming_webhook_test.go b/model/incoming_webhook_test.go index 8246b6c0a..46e5b6743 100644 --- a/model/incoming_webhook_test.go +++ b/model/incoming_webhook_test.go @@ -142,21 +142,20 @@ func TestIncomingWebhookRequestFromJson_Announcements(t *testing.T) { t.Fatal("IncomingWebhookRequest should not be nil") } - attachments := iwr.Attachments.([]interface{}) - attachment := attachments[0].(map[string]interface{}) - if attachment["pretext"] != expected { - t.Fatalf("Sample attachment pretext should be: %s, got: %s", expected, attachment["pretext"]) + attachment := iwr.Attachments[0] + if attachment.Pretext != expected { + t.Fatalf("Sample attachment pretext should be:%s, got: %s", expected, attachment.Pretext) } - if attachment["text"] != expected { - t.Fatalf("Sample attachment text should be: %s, got: %s", expected, attachment["text"]) + if attachment.Text != expected { + t.Fatalf("Sample attachment text should be: %s, got: %s", expected, attachment.Text) } - if attachment["title"] != expected { - t.Fatalf("Sample attachment title should be: %s, got: %s", expected, attachment["title"]) + if attachment.Title != expected { + t.Fatalf("Sample attachment title should be: %s, got: %s", expected, attachment.Title) } - fields := attachment["fields"].([]interface{}) - field := fields[0].(map[string]interface{}) - if field["value"] != expected { - t.Fatalf("Sample attachment field value should be: %s, got: %s", expected, field["value"]) + + field := attachment.Fields[0] + if field.Value != expected { + t.Fatalf("Sample attachment field value should be: %s, got: %s", expected, field.Value) } } @@ -224,10 +223,10 @@ func TestIncomingWebhookRequestFromJson(t *testing.T) { if iwr.Text != expected { t.Fatalf("Sample %d text should be: %s, got: %s", i, expected, iwr.Text) } - attachments := iwr.Attachments.([]interface{}) - attachment := attachments[0].(map[string]interface{}) - if attachment["text"] != expected { - t.Fatalf("Sample %d attachment text should be: %s, got: %s", i, expected, attachment["text"]) + + attachment := iwr.Attachments[0] + if attachment.Text != expected { + t.Fatalf("Sample %d attachment text should be: %s, got: %s", i, expected, attachment.Text) } } } -- cgit v1.2.3-1-g7c22