7
7
"net/http"
8
8
"os"
9
9
"testing"
10
+ "time"
10
11
)
11
12
12
13
const (
@@ -25,6 +26,7 @@ func getBot(t *testing.T) (*tgbotapi.BotAPI, error) {
25
26
bot , err := tgbotapi .NewBotAPI (TestToken )
26
27
27
28
if err != nil {
29
+ t .Error (err )
28
30
t .Fail ()
29
31
}
30
32
@@ -35,6 +37,7 @@ func TestNewBotAPI_notoken(t *testing.T) {
35
37
_ , err := tgbotapi .NewBotAPI ("" )
36
38
37
39
if err == nil {
40
+ t .Error (err )
38
41
t .Fail ()
39
42
}
40
43
}
@@ -47,6 +50,7 @@ func TestGetUpdates(t *testing.T) {
47
50
_ , err := bot .GetUpdates (u )
48
51
49
52
if err != nil {
53
+ t .Error (err )
50
54
t .Fail ()
51
55
}
52
56
}
@@ -59,6 +63,7 @@ func TestSendWithMessage(t *testing.T) {
59
63
_ , err := bot .Send (msg )
60
64
61
65
if err != nil {
66
+ t .Error (err )
62
67
t .Fail ()
63
68
}
64
69
}
@@ -71,6 +76,7 @@ func TestSendWithMessageReply(t *testing.T) {
71
76
_ , err := bot .Send (msg )
72
77
73
78
if err != nil {
79
+ t .Error (err )
74
80
t .Fail ()
75
81
}
76
82
}
@@ -82,6 +88,7 @@ func TestSendWithMessageForward(t *testing.T) {
82
88
_ , err := bot .Send (msg )
83
89
84
90
if err != nil {
91
+ t .Error (err )
85
92
t .Fail ()
86
93
}
87
94
}
@@ -94,6 +101,7 @@ func TestSendWithNewPhoto(t *testing.T) {
94
101
_ , err := bot .Send (msg )
95
102
96
103
if err != nil {
104
+ t .Error (err )
97
105
t .Fail ()
98
106
}
99
107
}
@@ -109,6 +117,7 @@ func TestSendWithNewPhotoWithFileBytes(t *testing.T) {
109
117
_ , err := bot .Send (msg )
110
118
111
119
if err != nil {
120
+ t .Error (err )
112
121
t .Fail ()
113
122
}
114
123
}
@@ -124,6 +133,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
124
133
_ , err := bot .Send (msg )
125
134
126
135
if err != nil {
136
+ t .Error (err )
127
137
t .Fail ()
128
138
}
129
139
}
@@ -137,6 +147,7 @@ func TestSendWithNewPhotoReply(t *testing.T) {
137
147
_ , err := bot .Send (msg )
138
148
139
149
if err != nil {
150
+ t .Error (err )
140
151
t .Fail ()
141
152
}
142
153
}
@@ -149,6 +160,7 @@ func TestSendWithExistingPhoto(t *testing.T) {
149
160
_ , err := bot .Send (msg )
150
161
151
162
if err != nil {
163
+ t .Error (err )
152
164
t .Fail ()
153
165
}
154
166
}
@@ -160,6 +172,7 @@ func TestSendWithNewDocument(t *testing.T) {
160
172
_ , err := bot .Send (msg )
161
173
162
174
if err != nil {
175
+ t .Error (err )
163
176
t .Fail ()
164
177
}
165
178
}
@@ -171,6 +184,7 @@ func TestSendWithExistingDocument(t *testing.T) {
171
184
_ , err := bot .Send (msg )
172
185
173
186
if err != nil {
187
+ t .Error (err )
174
188
t .Fail ()
175
189
}
176
190
}
@@ -187,6 +201,7 @@ func TestSendWithNewAudio(t *testing.T) {
187
201
_ , err := bot .Send (msg )
188
202
189
203
if err != nil {
204
+ t .Error (err )
190
205
t .Fail ()
191
206
}
192
207
}
@@ -202,6 +217,7 @@ func TestSendWithExistingAudio(t *testing.T) {
202
217
_ , err := bot .Send (msg )
203
218
204
219
if err != nil {
220
+ t .Error (err )
205
221
t .Fail ()
206
222
}
207
223
}
@@ -214,6 +230,7 @@ func TestSendWithNewVoice(t *testing.T) {
214
230
_ , err := bot .Send (msg )
215
231
216
232
if err != nil {
233
+ t .Error (err )
217
234
t .Fail ()
218
235
}
219
236
}
@@ -226,6 +243,7 @@ func TestSendWithExistingVoice(t *testing.T) {
226
243
_ , err := bot .Send (msg )
227
244
228
245
if err != nil {
246
+ t .Error (err )
229
247
t .Fail ()
230
248
}
231
249
}
@@ -236,6 +254,7 @@ func TestSendWithContact(t *testing.T) {
236
254
contact := tgbotapi .NewContact (ChatID , "5551234567" , "Test" )
237
255
238
256
if _ , err := bot .Send (contact ); err != nil {
257
+ t .Error (err )
239
258
t .Fail ()
240
259
}
241
260
}
@@ -246,6 +265,7 @@ func TestSendWithLocation(t *testing.T) {
246
265
_ , err := bot .Send (tgbotapi .NewLocation (ChatID , 40 , 40 ))
247
266
248
267
if err != nil {
268
+ t .Error (err )
249
269
t .Fail ()
250
270
}
251
271
}
@@ -256,6 +276,7 @@ func TestSendWithVenue(t *testing.T) {
256
276
venue := tgbotapi .NewVenue (ChatID , "A Test Location" , "123 Test Street" , 40 , 40 )
257
277
258
278
if _ , err := bot .Send (venue ); err != nil {
279
+ t .Error (err )
259
280
t .Fail ()
260
281
}
261
282
}
@@ -270,6 +291,7 @@ func TestSendWithNewVideo(t *testing.T) {
270
291
_ , err := bot .Send (msg )
271
292
272
293
if err != nil {
294
+ t .Error (err )
273
295
t .Fail ()
274
296
}
275
297
}
@@ -284,6 +306,7 @@ func TestSendWithExistingVideo(t *testing.T) {
284
306
_ , err := bot .Send (msg )
285
307
286
308
if err != nil {
309
+ t .Error (err )
287
310
t .Fail ()
288
311
}
289
312
}
@@ -296,6 +319,7 @@ func TestSendWithNewSticker(t *testing.T) {
296
319
_ , err := bot .Send (msg )
297
320
298
321
if err != nil {
322
+ t .Error (err )
299
323
t .Fail ()
300
324
}
301
325
}
@@ -308,6 +332,7 @@ func TestSendWithExistingSticker(t *testing.T) {
308
332
_ , err := bot .Send (msg )
309
333
310
334
if err != nil {
335
+ t .Error (err )
311
336
t .Fail ()
312
337
}
313
338
}
@@ -316,10 +341,11 @@ func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
316
341
bot , _ := getBot (t )
317
342
318
343
msg := tgbotapi .NewStickerUpload (ChatID , "tests/image.jpg" )
319
- msg .ReplyMarkup = tgbotapi.ReplyKeyboardHide {true , false }
344
+ msg .ReplyMarkup = tgbotapi.ReplyKeyboardRemove {true , false }
320
345
_ , err := bot .Send (msg )
321
346
322
347
if err != nil {
348
+ t .Error (err )
323
349
t .Fail ()
324
350
}
325
351
}
@@ -328,12 +354,12 @@ func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) {
328
354
bot , _ := getBot (t )
329
355
330
356
msg := tgbotapi .NewStickerShare (ChatID , ExistingStickerFileID )
331
- msg .ReplyMarkup = tgbotapi.ReplyKeyboardHide {true , false }
357
+ msg .ReplyMarkup = tgbotapi.ReplyKeyboardRemove {true , false }
332
358
333
359
_ , err := bot .Send (msg )
334
360
335
361
if err != nil {
336
-
362
+ t . Error ( err )
337
363
t .Fail ()
338
364
}
339
365
}
@@ -346,6 +372,7 @@ func TestGetFile(t *testing.T) {
346
372
_ , err := bot .GetFile (file )
347
373
348
374
if err != nil {
375
+ t .Error (err )
349
376
t .Fail ()
350
377
}
351
378
}
@@ -356,6 +383,7 @@ func TestSendChatConfig(t *testing.T) {
356
383
_ , err := bot .Send (tgbotapi .NewChatAction (ChatID , tgbotapi .ChatTyping ))
357
384
358
385
if err != nil {
386
+ t .Error (err )
359
387
t .Fail ()
360
388
}
361
389
}
@@ -365,6 +393,7 @@ func TestSendEditMessage(t *testing.T) {
365
393
366
394
msg , err := bot .Send (tgbotapi .NewMessage (ChatID , "Testing editing." ))
367
395
if err != nil {
396
+ t .Error (err )
368
397
t .Fail ()
369
398
}
370
399
@@ -378,6 +407,7 @@ func TestSendEditMessage(t *testing.T) {
378
407
379
408
_ , err = bot .Send (edit )
380
409
if err != nil {
410
+ t .Error (err )
381
411
t .Fail ()
382
412
}
383
413
}
@@ -387,18 +417,22 @@ func TestGetUserProfilePhotos(t *testing.T) {
387
417
388
418
_ , err := bot .GetUserProfilePhotos (tgbotapi .NewUserProfilePhotos (ChatID ))
389
419
if err != nil {
420
+ t .Error (err )
390
421
t .Fail ()
391
422
}
392
423
}
393
424
394
425
func TestSetWebhookWithCert (t * testing.T ) {
395
426
bot , _ := getBot (t )
396
427
428
+ time .Sleep (time .Second * 2 )
429
+
397
430
bot .RemoveWebhook ()
398
431
399
432
wh := tgbotapi .NewWebhookWithCert ("https://example.com/tgbotapi-test/" + bot .Token , "tests/cert.pem" )
400
433
_ , err := bot .SetWebhook (wh )
401
434
if err != nil {
435
+ t .Error (err )
402
436
t .Fail ()
403
437
}
404
438
@@ -408,11 +442,14 @@ func TestSetWebhookWithCert(t *testing.T) {
408
442
func TestSetWebhookWithoutCert (t * testing.T ) {
409
443
bot , _ := getBot (t )
410
444
445
+ time .Sleep (time .Second * 2 )
446
+
411
447
bot .RemoveWebhook ()
412
448
413
449
wh := tgbotapi .NewWebhook ("https://example.com/tgbotapi-test/" + bot .Token )
414
450
_ , err := bot .SetWebhook (wh )
415
451
if err != nil {
452
+ t .Error (err )
416
453
t .Fail ()
417
454
}
418
455
@@ -427,6 +464,7 @@ func TestUpdatesChan(t *testing.T) {
427
464
_ , err := bot .GetUpdatesChan (ucfg )
428
465
429
466
if err != nil {
467
+ t .Error (err )
430
468
t .Fail ()
431
469
}
432
470
}
0 commit comments