all repos — telegram-bot-api @ e16094f76a5f0642fe110299d3f557911dd7af7c

Golang bindings for the Telegram Bot API

Tests improved
Gleb Sinyavsky zhulik.gleb@gmail.com
Fri, 20 Nov 2015 19:43:56 +0300
commit

e16094f76a5f0642fe110299d3f557911dd7af7c

parent

d0711736ecd8b8ba32ff177eacf09d4b862ffaee

2 files changed, 109 insertions(+), 2 deletions(-)

jump to
M .gitignore.gitignore

@@ -1,1 +1,2 @@

-.idea/+.idea/ +coverage.out
M bot_test.gobot_test.go

@@ -64,7 +64,7 @@ t.Fail()

} } -func TestSendWithPhoto(t *testing.T) { +func TestSendWithNewPhoto(t *testing.T) { bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) if err != nil {

@@ -74,6 +74,112 @@

msg := tgbotapi.NewPhotoUpload(76918703, "tests/image.jpg") _, err = bot.Send(msg) + if err != nil { + t.Fail() + } +} + + + +func TestSendWithExistingPhoto(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + msg := tgbotapi.NewPhotoShare(76918703, "AgADAgADxKcxG4cBswqt13DnHOgbmBxDhCoABC0h01_AL4SKe20BAAEC") + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + +func TestSendWithNewDocument(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + msg := tgbotapi.NewDocumentUpload(76918703, "tests/image.jpg") + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + +func TestSendWithExistingDocument(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + msg := tgbotapi.NewDocumentShare(76918703, "BQADAgADBwADhwGzCjWgiUU4T8VNAg") + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + +func TestGetFile(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + file := tgbotapi.FileConfig{"BQADAgADBwADhwGzCjWgiUU4T8VNAg"} + + _, err = bot.GetFile(file) + + if err != nil { + t.Fail() + } +} + +func TestSendChatConfig(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + err = bot.SendChatAction(tgbotapi.NewChatAction(76918703, tgbotapi.ChatTyping)) + + if err != nil { + t.Fail() + } +} + +func TestGetUserProfilePhotos(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + _, err = bot.GetUserProfilePhotos(tgbotapi.NewUserProfilePhotos(76918703)) + if err != nil { + t.Fail() + } +} + +func TestUpdatesChan(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + var ucfg tgbotapi.UpdateConfig = tgbotapi.NewUpdate(0) + ucfg.Timeout = 60 + err = bot.UpdatesChan(ucfg) + if err != nil { t.Fail() }