-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_test.go
More file actions
78 lines (70 loc) · 1.5 KB
/
message_test.go
File metadata and controls
78 lines (70 loc) · 1.5 KB
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
74
75
76
77
78
package botclient
import (
"crypto/md5"
"encoding/base64"
"encoding/hex"
"fmt"
"os"
"testing"
)
func TestText(t *testing.T) {
msg := &TextMessage{
Content: "hello",
MentionedList: []string{All},
}
bot := New("98fcbeba-ce84-451b-8b6d-ae162d769fd6")
if err := bot.Send(msg); err != nil {
t.Error(err)
}
}
func TestUploadMedia(t *testing.T) {
bot := New("98fcbeba-ce84-451b-8b6d-ae162d769fd6")
mid, err := bot.UploadMedia("go.mod")
if err != nil {
t.Error(err)
}
fmt.Println(mid)
}
func TestImage(t *testing.T) {
body, err := os.ReadFile("1.png")
if err != nil {
panic(err)
}
hash := md5.New()
hash.Write(body)
md5Str := hex.EncodeToString(hash.Sum(nil))
base64Str := base64.StdEncoding.EncodeToString(body)
bot := New("98fcbeba-ce84-451b-8b6d-ae162d769fd6")
msg := &ImageMessage{
Base64: base64Str,
Md5: md5Str,
}
if err := bot.Send(msg); err != nil {
t.Error(err)
}
}
func TestNews(t *testing.T) {
bot := New("98fcbeba-ce84-451b-8b6d-ae162d769fd6")
msg := &NewsMessage{}
msg.AddArticle(NewsMessageArticle{
Title: "test",
URL: "https://github.com/duke-git/lancet/blob/main/README_zh-CN.md",
PicURL: "https://picb9.photophoto.cn/39/872/39872639_1.jpg",
})
if err := bot.Send(msg); err != nil {
t.Error(err)
}
}
func TestFile(t *testing.T) {
bot := New("98fcbeba-ce84-451b-8b6d-ae162d769fd6")
mid, err := bot.UploadMedia("go.mod")
if err != nil {
panic(err)
}
msg := &FileMessage{
MediaId: mid,
}
if err := bot.Send(msg); err != nil {
t.Error(err)
}
}