|
|
@ -7,6 +7,7 @@ import ( |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
|
|
|
|
"time" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
@ -25,6 +26,7 @@ func getBot(t *testing.T) (*tgbotapi.BotAPI, error) { |
|
|
|
bot, err := tgbotapi.NewBotAPI(TestToken) |
|
|
|
bot, err := tgbotapi.NewBotAPI(TestToken) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -35,6 +37,7 @@ func TestNewBotAPI_notoken(t *testing.T) { |
|
|
|
_, err := tgbotapi.NewBotAPI("") |
|
|
|
_, err := tgbotapi.NewBotAPI("") |
|
|
|
|
|
|
|
|
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -47,6 +50,7 @@ func TestGetUpdates(t *testing.T) { |
|
|
|
_, err := bot.GetUpdates(u) |
|
|
|
_, err := bot.GetUpdates(u) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -59,6 +63,7 @@ func TestSendWithMessage(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -71,6 +76,7 @@ func TestSendWithMessageReply(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -82,6 +88,7 @@ func TestSendWithMessageForward(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -94,6 +101,7 @@ func TestSendWithNewPhoto(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -109,6 +117,7 @@ func TestSendWithNewPhotoWithFileBytes(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -124,6 +133,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -137,6 +147,7 @@ func TestSendWithNewPhotoReply(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -149,6 +160,7 @@ func TestSendWithExistingPhoto(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -160,6 +172,7 @@ func TestSendWithNewDocument(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -171,6 +184,7 @@ func TestSendWithExistingDocument(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -187,6 +201,7 @@ func TestSendWithNewAudio(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -202,6 +217,7 @@ func TestSendWithExistingAudio(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -214,6 +230,7 @@ func TestSendWithNewVoice(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -226,6 +243,7 @@ func TestSendWithExistingVoice(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -236,6 +254,7 @@ func TestSendWithContact(t *testing.T) { |
|
|
|
contact := tgbotapi.NewContact(ChatID, "5551234567", "Test") |
|
|
|
contact := tgbotapi.NewContact(ChatID, "5551234567", "Test") |
|
|
|
|
|
|
|
|
|
|
|
if _, err := bot.Send(contact); err != nil { |
|
|
|
if _, err := bot.Send(contact); err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -246,6 +265,7 @@ func TestSendWithLocation(t *testing.T) { |
|
|
|
_, err := bot.Send(tgbotapi.NewLocation(ChatID, 40, 40)) |
|
|
|
_, err := bot.Send(tgbotapi.NewLocation(ChatID, 40, 40)) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -256,6 +276,7 @@ func TestSendWithVenue(t *testing.T) { |
|
|
|
venue := tgbotapi.NewVenue(ChatID, "A Test Location", "123 Test Street", 40, 40) |
|
|
|
venue := tgbotapi.NewVenue(ChatID, "A Test Location", "123 Test Street", 40, 40) |
|
|
|
|
|
|
|
|
|
|
|
if _, err := bot.Send(venue); err != nil { |
|
|
|
if _, err := bot.Send(venue); err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -270,6 +291,7 @@ func TestSendWithNewVideo(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -284,6 +306,7 @@ func TestSendWithExistingVideo(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -296,6 +319,7 @@ func TestSendWithNewSticker(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -308,6 +332,7 @@ func TestSendWithExistingSticker(t *testing.T) { |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -316,10 +341,11 @@ func TestSendWithNewStickerAndKeyboardHide(t *testing.T) { |
|
|
|
bot, _ := getBot(t) |
|
|
|
bot, _ := getBot(t) |
|
|
|
|
|
|
|
|
|
|
|
msg := tgbotapi.NewStickerUpload(ChatID, "tests/image.jpg") |
|
|
|
msg := tgbotapi.NewStickerUpload(ChatID, "tests/image.jpg") |
|
|
|
msg.ReplyMarkup = tgbotapi.ReplyKeyboardHide{true, false} |
|
|
|
msg.ReplyMarkup = tgbotapi.ReplyKeyboardRemove{true, false} |
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -328,12 +354,12 @@ func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) { |
|
|
|
bot, _ := getBot(t) |
|
|
|
bot, _ := getBot(t) |
|
|
|
|
|
|
|
|
|
|
|
msg := tgbotapi.NewStickerShare(ChatID, ExistingStickerFileID) |
|
|
|
msg := tgbotapi.NewStickerShare(ChatID, ExistingStickerFileID) |
|
|
|
msg.ReplyMarkup = tgbotapi.ReplyKeyboardHide{true, false} |
|
|
|
msg.ReplyMarkup = tgbotapi.ReplyKeyboardRemove{true, false} |
|
|
|
|
|
|
|
|
|
|
|
_, err := bot.Send(msg) |
|
|
|
_, err := bot.Send(msg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -346,6 +372,7 @@ func TestGetFile(t *testing.T) { |
|
|
|
_, err := bot.GetFile(file) |
|
|
|
_, err := bot.GetFile(file) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -356,6 +383,7 @@ func TestSendChatConfig(t *testing.T) { |
|
|
|
_, err := bot.Send(tgbotapi.NewChatAction(ChatID, tgbotapi.ChatTyping)) |
|
|
|
_, err := bot.Send(tgbotapi.NewChatAction(ChatID, tgbotapi.ChatTyping)) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -365,6 +393,7 @@ func TestSendEditMessage(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
msg, err := bot.Send(tgbotapi.NewMessage(ChatID, "Testing editing.")) |
|
|
|
msg, err := bot.Send(tgbotapi.NewMessage(ChatID, "Testing editing.")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -378,6 +407,7 @@ func TestSendEditMessage(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
_, err = bot.Send(edit) |
|
|
|
_, err = bot.Send(edit) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -387,6 +417,7 @@ func TestGetUserProfilePhotos(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
_, err := bot.GetUserProfilePhotos(tgbotapi.NewUserProfilePhotos(ChatID)) |
|
|
|
_, err := bot.GetUserProfilePhotos(tgbotapi.NewUserProfilePhotos(ChatID)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -394,11 +425,14 @@ func TestGetUserProfilePhotos(t *testing.T) { |
|
|
|
func TestSetWebhookWithCert(t *testing.T) { |
|
|
|
func TestSetWebhookWithCert(t *testing.T) { |
|
|
|
bot, _ := getBot(t) |
|
|
|
bot, _ := getBot(t) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time.Sleep(time.Second * 2) |
|
|
|
|
|
|
|
|
|
|
|
bot.RemoveWebhook() |
|
|
|
bot.RemoveWebhook() |
|
|
|
|
|
|
|
|
|
|
|
wh := tgbotapi.NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, "tests/cert.pem") |
|
|
|
wh := tgbotapi.NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, "tests/cert.pem") |
|
|
|
_, err := bot.SetWebhook(wh) |
|
|
|
_, err := bot.SetWebhook(wh) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -408,11 +442,14 @@ func TestSetWebhookWithCert(t *testing.T) { |
|
|
|
func TestSetWebhookWithoutCert(t *testing.T) { |
|
|
|
func TestSetWebhookWithoutCert(t *testing.T) { |
|
|
|
bot, _ := getBot(t) |
|
|
|
bot, _ := getBot(t) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time.Sleep(time.Second * 2) |
|
|
|
|
|
|
|
|
|
|
|
bot.RemoveWebhook() |
|
|
|
bot.RemoveWebhook() |
|
|
|
|
|
|
|
|
|
|
|
wh := tgbotapi.NewWebhook("https://example.com/tgbotapi-test/" + bot.Token) |
|
|
|
wh := tgbotapi.NewWebhook("https://example.com/tgbotapi-test/" + bot.Token) |
|
|
|
_, err := bot.SetWebhook(wh) |
|
|
|
_, err := bot.SetWebhook(wh) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -427,6 +464,7 @@ func TestUpdatesChan(t *testing.T) { |
|
|
|
_, err := bot.GetUpdatesChan(ucfg) |
|
|
|
_, err := bot.GetUpdatesChan(ucfg) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Fail() |
|
|
|
t.Fail() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|