-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmarkdown_test.go
48 lines (44 loc) · 1.28 KB
/
markdown_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
package wxworkbot
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
func TestUnmarshalMarkdownMessage(t *testing.T) {
jsonString := `
{
"msgtype": "markdown",
"markdown": {
"content": "<font color=\"warning\">233</font>"
}
}`
var markdownMsg markdownMessage
err := json.Unmarshal([]byte(jsonString), &markdownMsg)
assert.Nil(t, err)
assert.Equal(t, markdownMsg.MsgType, "markdown")
assert.Equal(t, markdownMsg.Markdown.Content,
"<font color=\"warning\">233</font>")
}
func TestMarshalMarkdown(t *testing.T) {
markdown := Markdown{
Content: "<font color=\"warning\">233</font>",
}
msgBytes, err := marshalMessage(markdown)
assert.Nil(t, err)
expected := `{"msgtype":"markdown","markdown":{"content":"<font color=\"warning\">233</font>"}}`
msg := strings.TrimSuffix(string(msgBytes), "\n")
assert.Equal(t, expected, msg)
}
func TestMarshalMarkdownMessage(t *testing.T) {
markdownMsg := markdownMessage{
Markdown: Markdown{
Content: "<font color=\"warning\">233</font>",
},
}
msgBytes, err := marshalMessage(markdownMsg)
assert.Nil(t, err)
expected := `{"msgtype":"markdown","markdown":{"content":"<font color=\"warning\">233</font>"}}`
msg := strings.TrimSuffix(string(msgBytes), "\n")
assert.Equal(t, expected, msg)
}