all repos — telegram-bot-api @ a746f39d224dc1070eb527fac4fdb70fd0ac0964

Golang bindings for the Telegram Bot API

Move tests into tgbotapi package.
Syfaro syfaro@huefox.com
Mon, 08 Oct 2018 23:34:34 -0500
commit

a746f39d224dc1070eb527fac4fdb70fd0ac0964

parent

cdcb93df5fc27adebfa8f3bc7d86ff0a33b5c7fe

3 files changed, 163 insertions(+), 170 deletions(-)

jump to
M bot_test.gobot_test.go

@@ -1,14 +1,11 @@

-package tgbotapi_test +package tgbotapi import ( "io/ioutil" - "log" "net/http" "os" "testing" "time" - - "github.com/go-telegram-bot-api/telegram-bot-api" ) const (

@@ -25,8 +22,8 @@ ExistingVideoNoteFileID = "DQADAgADdQAD70cQSUK41dLsRMqfAg"

ExistingStickerFileID = "BQADAgADcwADjMcoCbdl-6eB--YPAg" ) -func getBot(t *testing.T) (*tgbotapi.BotAPI, error) { - bot, err := tgbotapi.NewBotAPI(TestToken) +func getBot(t *testing.T) (*BotAPI, error) { + bot, err := NewBotAPI(TestToken) bot.Debug = true if err != nil {

@@ -38,7 +35,7 @@ return bot, err

} func TestNewBotAPI_notoken(t *testing.T) { - _, err := tgbotapi.NewBotAPI("") + _, err := NewBotAPI("") if err == nil { t.Error(err)

@@ -49,7 +46,7 @@

func TestGetUpdates(t *testing.T) { bot, _ := getBot(t) - u := tgbotapi.NewUpdate(0) + u := NewUpdate(0) _, err := bot.GetUpdates(u)

@@ -62,7 +59,7 @@

func TestSendWithMessage(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewMessage(ChatID, "A test message from the test library in telegram-bot-api") + msg := NewMessage(ChatID, "A test message from the test library in telegram-bot-api") msg.ParseMode = "markdown" _, err := bot.Send(msg)

@@ -75,7 +72,7 @@

func TestSendWithMessageReply(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewMessage(ChatID, "A test message from the test library in telegram-bot-api") + msg := NewMessage(ChatID, "A test message from the test library in telegram-bot-api") msg.ReplyToMessageID = ReplyToMessageID _, err := bot.Send(msg)

@@ -88,7 +85,7 @@

func TestSendWithMessageForward(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewForward(ChatID, ChatID, ReplyToMessageID) + msg := NewForward(ChatID, ChatID, ReplyToMessageID) _, err := bot.Send(msg) if err != nil {

@@ -100,7 +97,7 @@

func TestSendWithNewPhoto(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewPhotoUpload(ChatID, "tests/image.jpg") + msg := NewPhotoUpload(ChatID, "tests/image.jpg") msg.Caption = "Test" _, err := bot.Send(msg)

@@ -114,9 +111,9 @@ func TestSendWithNewPhotoWithFileBytes(t *testing.T) {

bot, _ := getBot(t) data, _ := ioutil.ReadFile("tests/image.jpg") - b := tgbotapi.FileBytes{Name: "image.jpg", Bytes: data} + b := FileBytes{Name: "image.jpg", Bytes: data} - msg := tgbotapi.NewPhotoUpload(ChatID, b) + msg := NewPhotoUpload(ChatID, b) msg.Caption = "Test" _, err := bot.Send(msg)

@@ -130,9 +127,9 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {

bot, _ := getBot(t) f, _ := os.Open("tests/image.jpg") - reader := tgbotapi.FileReader{Name: "image.jpg", Reader: f, Size: -1} + reader := FileReader{Name: "image.jpg", Reader: f, Size: -1} - msg := tgbotapi.NewPhotoUpload(ChatID, reader) + msg := NewPhotoUpload(ChatID, reader) msg.Caption = "Test" _, err := bot.Send(msg)

@@ -145,7 +142,7 @@

func TestSendWithNewPhotoReply(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewPhotoUpload(ChatID, "tests/image.jpg") + msg := NewPhotoUpload(ChatID, "tests/image.jpg") msg.ReplyToMessageID = ReplyToMessageID _, err := bot.Send(msg)

@@ -159,7 +156,7 @@

func TestSendWithExistingPhoto(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewPhotoShare(ChatID, ExistingPhotoFileID) + msg := NewPhotoShare(ChatID, ExistingPhotoFileID) msg.Caption = "Test" _, err := bot.Send(msg)

@@ -172,7 +169,7 @@

func TestSendWithNewDocument(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewDocumentUpload(ChatID, "tests/image.jpg") + msg := NewDocumentUpload(ChatID, "tests/image.jpg") _, err := bot.Send(msg) if err != nil {

@@ -184,7 +181,7 @@

func TestSendWithExistingDocument(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewDocumentShare(ChatID, ExistingDocumentFileID) + msg := NewDocumentShare(ChatID, ExistingDocumentFileID) _, err := bot.Send(msg) if err != nil {

@@ -196,7 +193,7 @@

func TestSendWithNewAudio(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewAudioUpload(ChatID, "tests/audio.mp3") + msg := NewAudioUpload(ChatID, "tests/audio.mp3") msg.Title = "TEST" msg.Duration = 10 msg.Performer = "TEST"

@@ -213,7 +210,7 @@

func TestSendWithExistingAudio(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewAudioShare(ChatID, ExistingAudioFileID) + msg := NewAudioShare(ChatID, ExistingAudioFileID) msg.Title = "TEST" msg.Duration = 10 msg.Performer = "TEST"

@@ -229,7 +226,7 @@

func TestSendWithNewVoice(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewVoiceUpload(ChatID, "tests/voice.ogg") + msg := NewVoiceUpload(ChatID, "tests/voice.ogg") msg.Duration = 10 _, err := bot.Send(msg)

@@ -242,7 +239,7 @@

func TestSendWithExistingVoice(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewVoiceShare(ChatID, ExistingVoiceFileID) + msg := NewVoiceShare(ChatID, ExistingVoiceFileID) msg.Duration = 10 _, err := bot.Send(msg)

@@ -255,7 +252,7 @@

func TestSendWithContact(t *testing.T) { bot, _ := getBot(t) - contact := tgbotapi.NewContact(ChatID, "5551234567", "Test") + contact := NewContact(ChatID, "5551234567", "Test") if _, err := bot.Send(contact); err != nil { t.Error(err)

@@ -266,7 +263,7 @@

func TestSendWithLocation(t *testing.T) { bot, _ := getBot(t) - _, err := bot.Send(tgbotapi.NewLocation(ChatID, 40, 40)) + _, err := bot.Send(NewLocation(ChatID, 40, 40)) if err != nil { t.Error(err)

@@ -277,7 +274,7 @@

func TestSendWithVenue(t *testing.T) { bot, _ := getBot(t) - venue := tgbotapi.NewVenue(ChatID, "A Test Location", "123 Test Street", 40, 40) + venue := NewVenue(ChatID, "A Test Location", "123 Test Street", 40, 40) if _, err := bot.Send(venue); err != nil { t.Error(err)

@@ -288,7 +285,7 @@

func TestSendWithNewVideo(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewVideoUpload(ChatID, "tests/video.mp4") + msg := NewVideoUpload(ChatID, "tests/video.mp4") msg.Duration = 10 msg.Caption = "TEST"

@@ -303,7 +300,7 @@

func TestSendWithExistingVideo(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewVideoShare(ChatID, ExistingVideoFileID) + msg := NewVideoShare(ChatID, ExistingVideoFileID) msg.Duration = 10 msg.Caption = "TEST"

@@ -318,7 +315,7 @@

func TestSendWithNewVideoNote(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewVideoNoteUpload(ChatID, 240, "tests/videonote.mp4") + msg := NewVideoNoteUpload(ChatID, 240, "tests/videonote.mp4") msg.Duration = 10 _, err := bot.Send(msg)

@@ -332,7 +329,7 @@

func TestSendWithExistingVideoNote(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewVideoNoteShare(ChatID, 240, ExistingVideoNoteFileID) + msg := NewVideoNoteShare(ChatID, 240, ExistingVideoNoteFileID) msg.Duration = 10 _, err := bot.Send(msg)

@@ -346,7 +343,7 @@

func TestSendWithNewSticker(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewStickerUpload(ChatID, "tests/image.jpg") + msg := NewStickerUpload(ChatID, "tests/image.jpg") _, err := bot.Send(msg)

@@ -359,7 +356,7 @@

func TestSendWithExistingSticker(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewStickerShare(ChatID, ExistingStickerFileID) + msg := NewStickerShare(ChatID, ExistingStickerFileID) _, err := bot.Send(msg)

@@ -372,8 +369,8 @@

func TestSendWithNewStickerAndKeyboardHide(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewStickerUpload(ChatID, "tests/image.jpg") - msg.ReplyMarkup = tgbotapi.ReplyKeyboardRemove{ + msg := NewStickerUpload(ChatID, "tests/image.jpg") + msg.ReplyMarkup = ReplyKeyboardRemove{ RemoveKeyboard: true, Selective: false, }

@@ -388,8 +385,8 @@

func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewStickerShare(ChatID, ExistingStickerFileID) - msg.ReplyMarkup = tgbotapi.ReplyKeyboardRemove{ + msg := NewStickerShare(ChatID, ExistingStickerFileID) + msg.ReplyMarkup = ReplyKeyboardRemove{ RemoveKeyboard: true, Selective: false, }

@@ -405,7 +402,7 @@

func TestGetFile(t *testing.T) { bot, _ := getBot(t) - file := tgbotapi.FileConfig{ + file := FileConfig{ FileID: ExistingPhotoFileID, }

@@ -420,7 +417,7 @@

func TestSendChatConfig(t *testing.T) { bot, _ := getBot(t) - _, err := bot.Request(tgbotapi.NewChatAction(ChatID, tgbotapi.ChatTyping)) + _, err := bot.Request(NewChatAction(ChatID, ChatTyping)) if err != nil { t.Error(err)

@@ -431,14 +428,14 @@

func TestSendEditMessage(t *testing.T) { bot, _ := getBot(t) - msg, err := bot.Send(tgbotapi.NewMessage(ChatID, "Testing editing.")) + msg, err := bot.Send(NewMessage(ChatID, "Testing editing.")) if err != nil { t.Error(err) t.Fail() } - edit := tgbotapi.EditMessageTextConfig{ - BaseEdit: tgbotapi.BaseEdit{ + edit := EditMessageTextConfig{ + BaseEdit: BaseEdit{ ChatID: ChatID, MessageID: msg.MessageID, },

@@ -455,7 +452,7 @@

func TestGetUserProfilePhotos(t *testing.T) { bot, _ := getBot(t) - _, err := bot.GetUserProfilePhotos(tgbotapi.NewUserProfilePhotos(ChatID)) + _, err := bot.GetUserProfilePhotos(NewUserProfilePhotos(ChatID)) if err != nil { t.Error(err) t.Fail()

@@ -467,9 +464,9 @@ bot, _ := getBot(t)

time.Sleep(time.Second * 2) - bot.Request(tgbotapi.RemoveWebhookConfig{}) + bot.Request(RemoveWebhookConfig{}) - wh := tgbotapi.NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, "tests/cert.pem") + wh := NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, "tests/cert.pem") _, err := bot.Request(wh) if err != nil { t.Error(err)

@@ -482,7 +479,7 @@ if err != nil {

t.Error(err) } - bot.Request(tgbotapi.RemoveWebhookConfig{}) + bot.Request(RemoveWebhookConfig{}) } func TestSetWebhookWithoutCert(t *testing.T) {

@@ -490,9 +487,9 @@ bot, _ := getBot(t)

time.Sleep(time.Second * 2) - bot.Request(tgbotapi.RemoveWebhookConfig{}) + bot.Request(RemoveWebhookConfig{}) - wh := tgbotapi.NewWebhook("https://example.com/tgbotapi-test/" + bot.Token) + wh := NewWebhook("https://example.com/tgbotapi-test/" + bot.Token) _, err := bot.Request(wh) if err != nil { t.Error(err)

@@ -509,13 +506,13 @@ if info.LastErrorDate != 0 {

t.Errorf("failed to set webhook: %s", info.LastErrorMessage) } - bot.Request(tgbotapi.RemoveWebhookConfig{}) + bot.Request(RemoveWebhookConfig{}) } func TestUpdatesChan(t *testing.T) { bot, _ := getBot(t) - var ucfg tgbotapi.UpdateConfig = tgbotapi.NewUpdate(0) + var ucfg = NewUpdate(0) ucfg.Timeout = 60 _, err := bot.GetUpdatesChan(ucfg)

@@ -528,10 +525,10 @@

func TestSendWithMediaGroup(t *testing.T) { bot, _ := getBot(t) - cfg := tgbotapi.NewMediaGroup(ChatID, []interface{}{ - tgbotapi.NewInputMediaPhoto("https://i.imgur.com/unQLJIb.jpg"), - tgbotapi.NewInputMediaPhoto("https://i.imgur.com/J5qweNZ.jpg"), - tgbotapi.NewInputMediaVideo("https://i.imgur.com/F6RmI24.mp4"), + cfg := NewMediaGroup(ChatID, []interface{}{ + NewInputMediaPhoto("https://i.imgur.com/unQLJIb.jpg"), + NewInputMediaPhoto("https://i.imgur.com/J5qweNZ.jpg"), + NewInputMediaVideo("https://i.imgur.com/F6RmI24.mp4"), }) _, err := bot.Request(cfg) if err != nil {

@@ -540,16 +537,16 @@ }

} func ExampleNewBotAPI() { - bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken") + bot, err := NewBotAPI("MyAwesomeBotToken") if err != nil { - log.Panic(err) + panic(err) } bot.Debug = true log.Printf("Authorized on account %s", bot.Self.UserName) - u := tgbotapi.NewUpdate(0) + u := NewUpdate(0) u.Timeout = 60 updates, err := bot.GetUpdatesChan(u)

@@ -566,7 +563,7 @@ }

log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) - msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) + msg := NewMessage(update.Message.Chat.ID, update.Message.Text) msg.ReplyToMessageID = update.Message.MessageID bot.Send(msg)

@@ -574,24 +571,24 @@ }

} func ExampleNewWebhook() { - bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken") + bot, err := NewBotAPI("MyAwesomeBotToken") if err != nil { - log.Fatal(err) + panic(err) } bot.Debug = true log.Printf("Authorized on account %s", bot.Self.UserName) - _, err = bot.Request(tgbotapi.NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem")) + _, err = bot.Request(NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem")) if err != nil { - log.Fatal(err) + panic(err) } info, err := bot.GetWebhookInfo() if err != nil { - log.Fatal(err) + panic(err) } if info.LastErrorDate != 0 {

@@ -607,14 +604,14 @@ }

} func ExampleInlineConfig() { - bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken") // create new bot + bot, err := NewBotAPI("MyAwesomeBotToken") // create new bot if err != nil { - log.Panic(err) + panic(err) } log.Printf("Authorized on account %s", bot.Self.UserName) - u := tgbotapi.NewUpdate(0) + u := NewUpdate(0) u.Timeout = 60 updates, err := bot.GetUpdatesChan(u)

@@ -624,10 +621,10 @@ if update.InlineQuery == nil { // if no inline query, ignore it

continue } - article := tgbotapi.NewInlineQueryResultArticle(update.InlineQuery.ID, "Echo", update.InlineQuery.Query) + article := NewInlineQueryResultArticle(update.InlineQuery.ID, "Echo", update.InlineQuery.Query) article.Description = update.InlineQuery.Query - inlineConf := tgbotapi.InlineConfig{ + inlineConf := InlineConfig{ InlineQueryID: update.InlineQuery.ID, IsPersonal: true, CacheTime: 0,

@@ -643,11 +640,11 @@

func TestDeleteMessage(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewMessage(ChatID, "A test message from the test library in telegram-bot-api") + msg := NewMessage(ChatID, "A test message from the test library in telegram-bot-api") msg.ParseMode = "markdown" message, _ := bot.Send(msg) - deleteMessageConfig := tgbotapi.DeleteMessageConfig{ + deleteMessageConfig := DeleteMessageConfig{ ChatID: message.Chat.ID, MessageID: message.MessageID, }

@@ -662,11 +659,11 @@

func TestPinChatMessage(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewMessage(SupergroupChatID, "A test message from the test library in telegram-bot-api") + msg := NewMessage(SupergroupChatID, "A test message from the test library in telegram-bot-api") msg.ParseMode = "markdown" message, _ := bot.Send(msg) - pinChatMessageConfig := tgbotapi.PinChatMessageConfig{ + pinChatMessageConfig := PinChatMessageConfig{ ChatID: message.Chat.ID, MessageID: message.MessageID, DisableNotification: false,

@@ -682,12 +679,12 @@

func TestUnpinChatMessage(t *testing.T) { bot, _ := getBot(t) - msg := tgbotapi.NewMessage(SupergroupChatID, "A test message from the test library in telegram-bot-api") + msg := NewMessage(SupergroupChatID, "A test message from the test library in telegram-bot-api") msg.ParseMode = "markdown" message, _ := bot.Send(msg) // We need pin message to unpin something - pinChatMessageConfig := tgbotapi.PinChatMessageConfig{ + pinChatMessageConfig := PinChatMessageConfig{ ChatID: message.Chat.ID, MessageID: message.MessageID, DisableNotification: false,

@@ -698,7 +695,7 @@ t.Error(err)

t.Fail() } - unpinChatMessageConfig := tgbotapi.UnpinChatMessageConfig{ + unpinChatMessageConfig := UnpinChatMessageConfig{ ChatID: message.Chat.ID, }
M helpers_test.gohelpers_test.go

@@ -1,48 +1,46 @@

-package tgbotapi_test +package tgbotapi import ( "testing" - - "github.com/go-telegram-bot-api/telegram-bot-api" ) func TestNewInlineQueryResultArticle(t *testing.T) { - result := tgbotapi.NewInlineQueryResultArticle("id", "title", "message") + result := NewInlineQueryResultArticle("id", "title", "message") if result.Type != "article" || result.ID != "id" || result.Title != "title" || - result.InputMessageContent.(tgbotapi.InputTextMessageContent).Text != "message" { + result.InputMessageContent.(InputTextMessageContent).Text != "message" { t.Fail() } } func TestNewInlineQueryResultArticleMarkdown(t *testing.T) { - result := tgbotapi.NewInlineQueryResultArticleMarkdown("id", "title", "*message*") + result := NewInlineQueryResultArticleMarkdown("id", "title", "*message*") if result.Type != "article" || result.ID != "id" || result.Title != "title" || - result.InputMessageContent.(tgbotapi.InputTextMessageContent).Text != "*message*" || - result.InputMessageContent.(tgbotapi.InputTextMessageContent).ParseMode != "Markdown" { + result.InputMessageContent.(InputTextMessageContent).Text != "*message*" || + result.InputMessageContent.(InputTextMessageContent).ParseMode != "Markdown" { t.Fail() } } func TestNewInlineQueryResultArticleHTML(t *testing.T) { - result := tgbotapi.NewInlineQueryResultArticleHTML("id", "title", "<b>message</b>") + result := NewInlineQueryResultArticleHTML("id", "title", "<b>message</b>") if result.Type != "article" || result.ID != "id" || result.Title != "title" || - result.InputMessageContent.(tgbotapi.InputTextMessageContent).Text != "<b>message</b>" || - result.InputMessageContent.(tgbotapi.InputTextMessageContent).ParseMode != "HTML" { + result.InputMessageContent.(InputTextMessageContent).Text != "<b>message</b>" || + result.InputMessageContent.(InputTextMessageContent).ParseMode != "HTML" { t.Fail() } } func TestNewInlineQueryResultGIF(t *testing.T) { - result := tgbotapi.NewInlineQueryResultGIF("id", "google.com") + result := NewInlineQueryResultGIF("id", "google.com") if result.Type != "gif" || result.ID != "id" ||

@@ -52,7 +50,7 @@ }

} func TestNewInlineQueryResultMPEG4GIF(t *testing.T) { - result := tgbotapi.NewInlineQueryResultMPEG4GIF("id", "google.com") + result := NewInlineQueryResultMPEG4GIF("id", "google.com") if result.Type != "mpeg4_gif" || result.ID != "id" ||

@@ -62,7 +60,7 @@ }

} func TestNewInlineQueryResultPhoto(t *testing.T) { - result := tgbotapi.NewInlineQueryResultPhoto("id", "google.com") + result := NewInlineQueryResultPhoto("id", "google.com") if result.Type != "photo" || result.ID != "id" ||

@@ -72,7 +70,7 @@ }

} func TestNewInlineQueryResultPhotoWithThumb(t *testing.T) { - result := tgbotapi.NewInlineQueryResultPhotoWithThumb("id", "google.com", "thumb.com") + result := NewInlineQueryResultPhotoWithThumb("id", "google.com", "thumb.com") if result.Type != "photo" || result.ID != "id" ||

@@ -83,7 +81,7 @@ }

} func TestNewInlineQueryResultVideo(t *testing.T) { - result := tgbotapi.NewInlineQueryResultVideo("id", "google.com") + result := NewInlineQueryResultVideo("id", "google.com") if result.Type != "video" || result.ID != "id" ||

@@ -93,7 +91,7 @@ }

} func TestNewInlineQueryResultAudio(t *testing.T) { - result := tgbotapi.NewInlineQueryResultAudio("id", "google.com", "title") + result := NewInlineQueryResultAudio("id", "google.com", "title") if result.Type != "audio" || result.ID != "id" ||

@@ -104,7 +102,7 @@ }

} func TestNewInlineQueryResultVoice(t *testing.T) { - result := tgbotapi.NewInlineQueryResultVoice("id", "google.com", "title") + result := NewInlineQueryResultVoice("id", "google.com", "title") if result.Type != "voice" || result.ID != "id" ||

@@ -115,7 +113,7 @@ }

} func TestNewInlineQueryResultDocument(t *testing.T) { - result := tgbotapi.NewInlineQueryResultDocument("id", "google.com", "title", "mime/type") + result := NewInlineQueryResultDocument("id", "google.com", "title", "mime/type") if result.Type != "document" || result.ID != "id" ||

@@ -127,7 +125,7 @@ }

} func TestNewInlineQueryResultLocation(t *testing.T) { - result := tgbotapi.NewInlineQueryResultLocation("id", "name", 40, 50) + result := NewInlineQueryResultLocation("id", "name", 40, 50) if result.Type != "location" || result.ID != "id" ||

@@ -139,7 +137,7 @@ }

} func TestNewEditMessageText(t *testing.T) { - edit := tgbotapi.NewEditMessageText(ChatID, ReplyToMessageID, "new text") + edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text") if edit.Text != "new text" || edit.BaseEdit.ChatID != ChatID ||

@@ -149,7 +147,7 @@ }

} func TestNewEditMessageCaption(t *testing.T) { - edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption") + edit := NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption") if edit.Caption != "new caption" || edit.BaseEdit.ChatID != ChatID ||

@@ -159,15 +157,15 @@ }

} func TestNewEditMessageReplyMarkup(t *testing.T) { - markup := tgbotapi.InlineKeyboardMarkup{ - InlineKeyboard: [][]tgbotapi.InlineKeyboardButton{ - []tgbotapi.InlineKeyboardButton{ - tgbotapi.InlineKeyboardButton{Text: "test"}, + markup := InlineKeyboardMarkup{ + InlineKeyboard: [][]InlineKeyboardButton{ + []InlineKeyboardButton{ + InlineKeyboardButton{Text: "test"}, }, }, } - edit := tgbotapi.NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup) + edit := NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup) if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" || edit.BaseEdit.ChatID != ChatID ||
M types_test.gotypes_test.go

@@ -1,14 +1,12 @@

-package tgbotapi_test +package tgbotapi import ( "testing" "time" - - "github.com/go-telegram-bot-api/telegram-bot-api" ) func TestUserStringWith(t *testing.T) { - user := tgbotapi.User{ + user := User{ ID: 0, FirstName: "Test", LastName: "Test",

@@ -23,7 +21,7 @@ }

} func TestUserStringWithUserName(t *testing.T) { - user := tgbotapi.User{ + user := User{ ID: 0, FirstName: "Test", LastName: "Test",

@@ -37,7 +35,7 @@ }

} func TestMessageTime(t *testing.T) { - message := tgbotapi.Message{Date: 0} + message := Message{Date: 0} date := time.Unix(0, 0) if message.Time() != date {

@@ -46,8 +44,8 @@ }

} func TestMessageIsCommandWithCommand(t *testing.T) { - message := tgbotapi.Message{Text: "/command"} - message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}} + message := Message{Text: "/command"} + message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}} if !message.IsCommand() { t.Fail()

@@ -55,7 +53,7 @@ }

} func TestIsCommandWithText(t *testing.T) { - message := tgbotapi.Message{Text: "some text"} + message := Message{Text: "some text"} if message.IsCommand() { t.Fail()

@@ -63,7 +61,7 @@ }

} func TestIsCommandWithEmptyText(t *testing.T) { - message := tgbotapi.Message{Text: ""} + message := Message{Text: ""} if message.IsCommand() { t.Fail()

@@ -71,8 +69,8 @@ }

} func TestCommandWithCommand(t *testing.T) { - message := tgbotapi.Message{Text: "/command"} - message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}} + message := Message{Text: "/command"} + message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}} if message.Command() != "command" { t.Fail()

@@ -80,7 +78,7 @@ }

} func TestCommandWithEmptyText(t *testing.T) { - message := tgbotapi.Message{Text: ""} + message := Message{Text: ""} if message.Command() != "" { t.Fail()

@@ -88,7 +86,7 @@ }

} func TestCommandWithNonCommand(t *testing.T) { - message := tgbotapi.Message{Text: "test text"} + message := Message{Text: "test text"} if message.Command() != "" { t.Fail()

@@ -96,8 +94,8 @@ }

} func TestCommandWithBotName(t *testing.T) { - message := tgbotapi.Message{Text: "/command@testbot"} - message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}} + message := Message{Text: "/command@testbot"} + message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}} if message.Command() != "command" { t.Fail()

@@ -105,8 +103,8 @@ }

} func TestCommandWithAtWithBotName(t *testing.T) { - message := tgbotapi.Message{Text: "/command@testbot"} - message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}} + message := Message{Text: "/command@testbot"} + message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}} if message.CommandWithAt() != "command@testbot" { t.Fail()

@@ -114,37 +112,37 @@ }

} func TestMessageCommandArgumentsWithArguments(t *testing.T) { - message := tgbotapi.Message{Text: "/command with arguments"} - message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}} + message := Message{Text: "/command with arguments"} + message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}} if message.CommandArguments() != "with arguments" { t.Fail() } } func TestMessageCommandArgumentsWithMalformedArguments(t *testing.T) { - message := tgbotapi.Message{Text: "/command-without argument space"} - message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}} + message := Message{Text: "/command-without argument space"} + message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}} if message.CommandArguments() != "without argument space" { t.Fail() } } func TestMessageCommandArgumentsWithoutArguments(t *testing.T) { - message := tgbotapi.Message{Text: "/command"} + message := Message{Text: "/command"} if message.CommandArguments() != "" { t.Fail() } } func TestMessageCommandArgumentsForNonCommand(t *testing.T) { - message := tgbotapi.Message{Text: "test text"} + message := Message{Text: "test text"} if message.CommandArguments() != "" { t.Fail() } } func TestMessageEntityParseURLGood(t *testing.T) { - entity := tgbotapi.MessageEntity{URL: "https://www.google.com"} + entity := MessageEntity{URL: "https://www.google.com"} if _, err := entity.ParseURL(); err != nil { t.Fail()

@@ -152,7 +150,7 @@ }

} func TestMessageEntityParseURLBad(t *testing.T) { - entity := tgbotapi.MessageEntity{URL: ""} + entity := MessageEntity{URL: ""} if _, err := entity.ParseURL(); err == nil { t.Fail()

@@ -160,7 +158,7 @@ }

} func TestChatIsPrivate(t *testing.T) { - chat := tgbotapi.Chat{ID: 10, Type: "private"} + chat := Chat{ID: 10, Type: "private"} if !chat.IsPrivate() { t.Fail()

@@ -168,7 +166,7 @@ }

} func TestChatIsGroup(t *testing.T) { - chat := tgbotapi.Chat{ID: 10, Type: "group"} + chat := Chat{ID: 10, Type: "group"} if !chat.IsGroup() { t.Fail()

@@ -176,7 +174,7 @@ }

} func TestChatIsChannel(t *testing.T) { - chat := tgbotapi.Chat{ID: 10, Type: "channel"} + chat := Chat{ID: 10, Type: "channel"} if !chat.IsChannel() { t.Fail()

@@ -184,7 +182,7 @@ }

} func TestChatIsSuperGroup(t *testing.T) { - chat := tgbotapi.Chat{ID: 10, Type: "supergroup"} + chat := Chat{ID: 10, Type: "supergroup"} if !chat.IsSuperGroup() { t.Fail()

@@ -192,7 +190,7 @@ }

} func TestFileLink(t *testing.T) { - file := tgbotapi.File{FilePath: "test/test.txt"} + file := File{FilePath: "test/test.txt"} if file.Link("token") != "https://api.telegram.org/file/bottoken/test/test.txt" { t.Fail()

@@ -201,41 +199,41 @@ }

// Ensure all configs are sendable var ( - _ tgbotapi.Chattable = tgbotapi.AnimationConfig{} - _ tgbotapi.Chattable = tgbotapi.AudioConfig{} - _ tgbotapi.Chattable = tgbotapi.CallbackConfig{} - _ tgbotapi.Chattable = tgbotapi.ChatActionConfig{} - _ tgbotapi.Chattable = tgbotapi.ContactConfig{} - _ tgbotapi.Chattable = tgbotapi.DeleteChatPhotoConfig{} - _ tgbotapi.Chattable = tgbotapi.DeleteChatStickerSetConfig{} - _ tgbotapi.Chattable = tgbotapi.DeleteMessageConfig{} - _ tgbotapi.Chattable = tgbotapi.DocumentConfig{} - _ tgbotapi.Chattable = tgbotapi.EditMessageCaptionConfig{} - _ tgbotapi.Chattable = tgbotapi.EditMessageLiveLocationConfig{} - _ tgbotapi.Chattable = tgbotapi.EditMessageReplyMarkupConfig{} - _ tgbotapi.Chattable = tgbotapi.EditMessageTextConfig{} - _ tgbotapi.Chattable = tgbotapi.ForwardConfig{} - _ tgbotapi.Chattable = tgbotapi.GameConfig{} - _ tgbotapi.Chattable = tgbotapi.GetGameHighScoresConfig{} - _ tgbotapi.Chattable = tgbotapi.InlineConfig{} - _ tgbotapi.Chattable = tgbotapi.InvoiceConfig{} - _ tgbotapi.Chattable = tgbotapi.KickChatMemberConfig{} - _ tgbotapi.Chattable = tgbotapi.LocationConfig{} - _ tgbotapi.Chattable = tgbotapi.MediaGroupConfig{} - _ tgbotapi.Chattable = tgbotapi.MessageConfig{} - _ tgbotapi.Chattable = tgbotapi.PhotoConfig{} - _ tgbotapi.Chattable = tgbotapi.PinChatMessageConfig{} - _ tgbotapi.Chattable = tgbotapi.SetChatDescriptionConfig{} - _ tgbotapi.Chattable = tgbotapi.SetChatPhotoConfig{} - _ tgbotapi.Chattable = tgbotapi.SetChatTitleConfig{} - _ tgbotapi.Chattable = tgbotapi.SetGameScoreConfig{} - _ tgbotapi.Chattable = tgbotapi.StickerConfig{} - _ tgbotapi.Chattable = tgbotapi.UnpinChatMessageConfig{} - _ tgbotapi.Chattable = tgbotapi.UpdateConfig{} - _ tgbotapi.Chattable = tgbotapi.UserProfilePhotosConfig{} - _ tgbotapi.Chattable = tgbotapi.VenueConfig{} - _ tgbotapi.Chattable = tgbotapi.VideoConfig{} - _ tgbotapi.Chattable = tgbotapi.VideoNoteConfig{} - _ tgbotapi.Chattable = tgbotapi.VoiceConfig{} - _ tgbotapi.Chattable = tgbotapi.WebhookConfig{} + _ Chattable = AnimationConfig{} + _ Chattable = AudioConfig{} + _ Chattable = CallbackConfig{} + _ Chattable = ChatActionConfig{} + _ Chattable = ContactConfig{} + _ Chattable = DeleteChatPhotoConfig{} + _ Chattable = DeleteChatStickerSetConfig{} + _ Chattable = DeleteMessageConfig{} + _ Chattable = DocumentConfig{} + _ Chattable = EditMessageCaptionConfig{} + _ Chattable = EditMessageLiveLocationConfig{} + _ Chattable = EditMessageReplyMarkupConfig{} + _ Chattable = EditMessageTextConfig{} + _ Chattable = ForwardConfig{} + _ Chattable = GameConfig{} + _ Chattable = GetGameHighScoresConfig{} + _ Chattable = InlineConfig{} + _ Chattable = InvoiceConfig{} + _ Chattable = KickChatMemberConfig{} + _ Chattable = LocationConfig{} + _ Chattable = MediaGroupConfig{} + _ Chattable = MessageConfig{} + _ Chattable = PhotoConfig{} + _ Chattable = PinChatMessageConfig{} + _ Chattable = SetChatDescriptionConfig{} + _ Chattable = SetChatPhotoConfig{} + _ Chattable = SetChatTitleConfig{} + _ Chattable = SetGameScoreConfig{} + _ Chattable = StickerConfig{} + _ Chattable = UnpinChatMessageConfig{} + _ Chattable = UpdateConfig{} + _ Chattable = UserProfilePhotosConfig{} + _ Chattable = VenueConfig{} + _ Chattable = VideoConfig{} + _ Chattable = VideoNoteConfig{} + _ Chattable = VoiceConfig{} + _ Chattable = WebhookConfig{} )