forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
attachements_test.go
73 lines (66 loc) · 1.62 KB
/
attachements_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package slack
import (
"encoding/json"
"strings"
"testing"
"github.com/go-test/deep"
)
func TestAttachment_UnmarshalMarshalJSON_WithBlocks(t *testing.T) {
originalAttachmentJson := `{
"id": 1,
"blocks": [
{
"type": "section",
"block_id": "xxxx",
"text": {
"type": "mrkdwn",
"text": "Pick something:",
"verbatim": true
},
"accessory": {
"type": "static_select",
"action_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"placeholder": {
"type": "plain_text",
"text": "Select one item",
"emoji": true
},
"options": [
{
"text": {
"type": "plain_text",
"text": "ghi",
"emoji": true
},
"value": "ghi"
}
]
}
}
],
"color": "#13A554",
"fallback": "[no preview available]"
}`
attachment := new(Attachment)
err := json.Unmarshal([]byte(originalAttachmentJson), attachment)
if err != nil {
t.Fatalf("expected no error unmarshaling attachment with blocks, got: %v", err)
}
actualAttachmentJson, err := json.Marshal(attachment)
if err != nil {
t.Fatal(err)
}
var (
actual interface{}
expected interface{}
)
if err = json.Unmarshal([]byte(originalAttachmentJson), &expected); err != nil {
t.Fatal(err)
}
if err = json.Unmarshal(actualAttachmentJson, &actual); err != nil {
t.Fatal(err)
}
if diff := deep.Equal(actual, expected); diff != nil {
t.Fatal("actual does not match expected\n", strings.Join(diff, "\n"))
}
}