77 "net/http"
88 "os"
99 "testing"
10+ "time"
1011)
1112
1213const (
@@ -25,6 +26,7 @@ func getBot(t *testing.T) (*tgbotapi.BotAPI, error) {
2526 bot , err := tgbotapi .NewBotAPI (TestToken )
2627
2728 if err != nil {
29+ t .Error (err )
2830 t .Fail ()
2931 }
3032
@@ -35,6 +37,7 @@ func TestNewBotAPI_notoken(t *testing.T) {
3537 _ , err := tgbotapi .NewBotAPI ("" )
3638
3739 if err == nil {
40+ t .Error (err )
3841 t .Fail ()
3942 }
4043}
@@ -47,6 +50,7 @@ func TestGetUpdates(t *testing.T) {
4750 _ , err := bot .GetUpdates (u )
4851
4952 if err != nil {
53+ t .Error (err )
5054 t .Fail ()
5155 }
5256}
@@ -59,6 +63,7 @@ func TestSendWithMessage(t *testing.T) {
5963 _ , err := bot .Send (msg )
6064
6165 if err != nil {
66+ t .Error (err )
6267 t .Fail ()
6368 }
6469}
@@ -71,6 +76,7 @@ func TestSendWithMessageReply(t *testing.T) {
7176 _ , err := bot .Send (msg )
7277
7378 if err != nil {
79+ t .Error (err )
7480 t .Fail ()
7581 }
7682}
@@ -82,6 +88,7 @@ func TestSendWithMessageForward(t *testing.T) {
8288 _ , err := bot .Send (msg )
8389
8490 if err != nil {
91+ t .Error (err )
8592 t .Fail ()
8693 }
8794}
@@ -94,6 +101,7 @@ func TestSendWithNewPhoto(t *testing.T) {
94101 _ , err := bot .Send (msg )
95102
96103 if err != nil {
104+ t .Error (err )
97105 t .Fail ()
98106 }
99107}
@@ -109,6 +117,7 @@ func TestSendWithNewPhotoWithFileBytes(t *testing.T) {
109117 _ , err := bot .Send (msg )
110118
111119 if err != nil {
120+ t .Error (err )
112121 t .Fail ()
113122 }
114123}
@@ -124,6 +133,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
124133 _ , err := bot .Send (msg )
125134
126135 if err != nil {
136+ t .Error (err )
127137 t .Fail ()
128138 }
129139}
@@ -137,6 +147,7 @@ func TestSendWithNewPhotoReply(t *testing.T) {
137147 _ , err := bot .Send (msg )
138148
139149 if err != nil {
150+ t .Error (err )
140151 t .Fail ()
141152 }
142153}
@@ -149,6 +160,7 @@ func TestSendWithExistingPhoto(t *testing.T) {
149160 _ , err := bot .Send (msg )
150161
151162 if err != nil {
163+ t .Error (err )
152164 t .Fail ()
153165 }
154166}
@@ -160,6 +172,7 @@ func TestSendWithNewDocument(t *testing.T) {
160172 _ , err := bot .Send (msg )
161173
162174 if err != nil {
175+ t .Error (err )
163176 t .Fail ()
164177 }
165178}
@@ -171,6 +184,7 @@ func TestSendWithExistingDocument(t *testing.T) {
171184 _ , err := bot .Send (msg )
172185
173186 if err != nil {
187+ t .Error (err )
174188 t .Fail ()
175189 }
176190}
@@ -187,6 +201,7 @@ func TestSendWithNewAudio(t *testing.T) {
187201 _ , err := bot .Send (msg )
188202
189203 if err != nil {
204+ t .Error (err )
190205 t .Fail ()
191206 }
192207}
@@ -202,6 +217,7 @@ func TestSendWithExistingAudio(t *testing.T) {
202217 _ , err := bot .Send (msg )
203218
204219 if err != nil {
220+ t .Error (err )
205221 t .Fail ()
206222 }
207223}
@@ -214,6 +230,7 @@ func TestSendWithNewVoice(t *testing.T) {
214230 _ , err := bot .Send (msg )
215231
216232 if err != nil {
233+ t .Error (err )
217234 t .Fail ()
218235 }
219236}
@@ -226,6 +243,7 @@ func TestSendWithExistingVoice(t *testing.T) {
226243 _ , err := bot .Send (msg )
227244
228245 if err != nil {
246+ t .Error (err )
229247 t .Fail ()
230248 }
231249}
@@ -236,6 +254,7 @@ func TestSendWithContact(t *testing.T) {
236254 contact := tgbotapi .NewContact (ChatID , "5551234567" , "Test" )
237255
238256 if _ , err := bot .Send (contact ); err != nil {
257+ t .Error (err )
239258 t .Fail ()
240259 }
241260}
@@ -246,6 +265,7 @@ func TestSendWithLocation(t *testing.T) {
246265 _ , err := bot .Send (tgbotapi .NewLocation (ChatID , 40 , 40 ))
247266
248267 if err != nil {
268+ t .Error (err )
249269 t .Fail ()
250270 }
251271}
@@ -256,6 +276,7 @@ func TestSendWithVenue(t *testing.T) {
256276 venue := tgbotapi .NewVenue (ChatID , "A Test Location" , "123 Test Street" , 40 , 40 )
257277
258278 if _ , err := bot .Send (venue ); err != nil {
279+ t .Error (err )
259280 t .Fail ()
260281 }
261282}
@@ -270,6 +291,7 @@ func TestSendWithNewVideo(t *testing.T) {
270291 _ , err := bot .Send (msg )
271292
272293 if err != nil {
294+ t .Error (err )
273295 t .Fail ()
274296 }
275297}
@@ -284,6 +306,7 @@ func TestSendWithExistingVideo(t *testing.T) {
284306 _ , err := bot .Send (msg )
285307
286308 if err != nil {
309+ t .Error (err )
287310 t .Fail ()
288311 }
289312}
@@ -296,6 +319,7 @@ func TestSendWithNewSticker(t *testing.T) {
296319 _ , err := bot .Send (msg )
297320
298321 if err != nil {
322+ t .Error (err )
299323 t .Fail ()
300324 }
301325}
@@ -308,6 +332,7 @@ func TestSendWithExistingSticker(t *testing.T) {
308332 _ , err := bot .Send (msg )
309333
310334 if err != nil {
335+ t .Error (err )
311336 t .Fail ()
312337 }
313338}
@@ -316,10 +341,11 @@ func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
316341 bot , _ := getBot (t )
317342
318343 msg := tgbotapi .NewStickerUpload (ChatID , "tests/image.jpg" )
319- msg .ReplyMarkup = tgbotapi.ReplyKeyboardHide {true , false }
344+ msg .ReplyMarkup = tgbotapi.ReplyKeyboardRemove {true , false }
320345 _ , err := bot .Send (msg )
321346
322347 if err != nil {
348+ t .Error (err )
323349 t .Fail ()
324350 }
325351}
@@ -328,12 +354,12 @@ func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) {
328354 bot , _ := getBot (t )
329355
330356 msg := tgbotapi .NewStickerShare (ChatID , ExistingStickerFileID )
331- msg .ReplyMarkup = tgbotapi.ReplyKeyboardHide {true , false }
357+ msg .ReplyMarkup = tgbotapi.ReplyKeyboardRemove {true , false }
332358
333359 _ , err := bot .Send (msg )
334360
335361 if err != nil {
336-
362+ t . Error ( err )
337363 t .Fail ()
338364 }
339365}
@@ -346,6 +372,7 @@ func TestGetFile(t *testing.T) {
346372 _ , err := bot .GetFile (file )
347373
348374 if err != nil {
375+ t .Error (err )
349376 t .Fail ()
350377 }
351378}
@@ -356,6 +383,7 @@ func TestSendChatConfig(t *testing.T) {
356383 _ , err := bot .Send (tgbotapi .NewChatAction (ChatID , tgbotapi .ChatTyping ))
357384
358385 if err != nil {
386+ t .Error (err )
359387 t .Fail ()
360388 }
361389}
@@ -365,6 +393,7 @@ func TestSendEditMessage(t *testing.T) {
365393
366394 msg , err := bot .Send (tgbotapi .NewMessage (ChatID , "Testing editing." ))
367395 if err != nil {
396+ t .Error (err )
368397 t .Fail ()
369398 }
370399
@@ -378,6 +407,7 @@ func TestSendEditMessage(t *testing.T) {
378407
379408 _ , err = bot .Send (edit )
380409 if err != nil {
410+ t .Error (err )
381411 t .Fail ()
382412 }
383413}
@@ -387,18 +417,22 @@ func TestGetUserProfilePhotos(t *testing.T) {
387417
388418 _ , err := bot .GetUserProfilePhotos (tgbotapi .NewUserProfilePhotos (ChatID ))
389419 if err != nil {
420+ t .Error (err )
390421 t .Fail ()
391422 }
392423}
393424
394425func TestSetWebhookWithCert (t * testing.T ) {
395426 bot , _ := getBot (t )
396427
428+ time .Sleep (time .Second * 2 )
429+
397430 bot .RemoveWebhook ()
398431
399432 wh := tgbotapi .NewWebhookWithCert ("https://example.com/tgbotapi-test/" + bot .Token , "tests/cert.pem" )
400433 _ , err := bot .SetWebhook (wh )
401434 if err != nil {
435+ t .Error (err )
402436 t .Fail ()
403437 }
404438
@@ -408,11 +442,14 @@ func TestSetWebhookWithCert(t *testing.T) {
408442func TestSetWebhookWithoutCert (t * testing.T ) {
409443 bot , _ := getBot (t )
410444
445+ time .Sleep (time .Second * 2 )
446+
411447 bot .RemoveWebhook ()
412448
413449 wh := tgbotapi .NewWebhook ("https://example.com/tgbotapi-test/" + bot .Token )
414450 _ , err := bot .SetWebhook (wh )
415451 if err != nil {
452+ t .Error (err )
416453 t .Fail ()
417454 }
418455
@@ -427,6 +464,7 @@ func TestUpdatesChan(t *testing.T) {
427464 _ , err := bot .GetUpdatesChan (ucfg )
428465
429466 if err != nil {
467+ t .Error (err )
430468 t .Fail ()
431469 }
432470}
0 commit comments