-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest_test.go
70 lines (61 loc) · 1.54 KB
/
request_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
package telegram
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
)
type mockUploader struct{}
func (m mockUploader) Name() string {
panic("implement me")
}
func (m mockUploader) Reader() (io.Reader, error) {
panic("implement me")
}
func (m mockUploader) Size() int64 {
panic("implement me")
}
func TestIsFileUpload(t *testing.T) {
check := func(req interface{}, expected fileUpload) {
actual, ok := isFileUpload(req)
assert.Equal(t, expected.fieldname != "", ok)
assert.Equal(t, expected, actual)
}
check(&SendMessageRequest{}, fileUpload{})
check(&SendAnimationRequest{}, fileUpload{})
check(&SendPhotoRequest{}, fileUpload{})
check(&SendPhotoRequest{
ChatID: "12345",
Photo: mockUploader{},
Caption: "caption here",
ParseMode: "html",
DisableNotification: true,
ReplyToMessageID: 101,
ReplyMarkup: InlineKeyboardMarkup{
InlineKeyboard: [][]InlineKeyboardButton{{{
Text: "hello",
}}},
},
}, fileUpload{
params: map[string]string{
"chat_id": "12345",
"caption": "caption here",
"parse_mode": "html",
"disable_notification": "true",
"reply_to_message_id": "101",
"reply_markup": `{"inline_keyboard":[[{"text":"hello"}]]}`,
},
fieldname: "photo",
file: mockUploader{},
err: nil,
})
check(&SendPhotoRequest{
Photo: mockUploader{},
}, fileUpload{
params: map[string]string{
"chat_id": "",
},
fieldname: "photo",
file: mockUploader{},
err: nil,
})
}