-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathimage_test.go
52 lines (48 loc) · 1.14 KB
/
image_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
package wxworkbot
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
func TestUnmarshalImageMessage(t *testing.T) {
jsonString := `
{
"msgtype": "image",
"image": {
"base64": "DATA",
"md5": "MD5"
}
}
`
var imageMsg imageMessage
err := json.Unmarshal([]byte(jsonString), &imageMsg)
assert.Nil(t, err)
assert.Equal(t, imageMsg.MsgType, "image")
assert.Equal(t, imageMsg.Image.Base64, "DATA")
assert.Equal(t, imageMsg.Image.MD5, "MD5")
}
func TestMarshalImage(t *testing.T) {
image := Image{
Base64: "DATA",
MD5: "MD5",
}
msgBytes, err := marshalMessage(image)
assert.Nil(t, err)
expected := `{"msgtype":"image","image":{"base64":"DATA","md5":"MD5"}}`
msg := strings.TrimSuffix(string(msgBytes), "\n")
assert.Equal(t, expected, msg)
}
func TestMarshalImageMessage(t *testing.T) {
imageMsg := imageMessage{
Image: Image{
Base64: "DATA",
MD5: "MD5",
},
}
msgBytes, err := marshalMessage(imageMsg)
assert.Nil(t, err)
expected := `{"msgtype":"image","image":{"base64":"DATA","md5":"MD5"}}`
msg := strings.TrimSuffix(string(msgBytes), "\n")
assert.Equal(t, expected, msg)
}