all repos — telegram-bot-api @ 207a1a08f29fa32366ce1daafd54921613ba484e

Golang bindings for the Telegram Bot API

Tests added
Gleb Sinyavsky zhulik.gleb@gmail.com
Sat, 21 Nov 2015 14:36:43 +0300
commit

207a1a08f29fa32366ce1daafd54921613ba484e

parent

9644984dae4c18c2109b47ac0da9eab69dae66b2

1 files changed, 62 insertions(+), 1 deletions(-)

jump to
M bot_test.gobot_test.go

@@ -8,6 +8,7 @@ "net/http/httptest"

"os" "strings" "testing" + "io/ioutil" ) func TestMain(m *testing.M) {

@@ -115,6 +116,48 @@ if err != nil {

t.Fail() } } + + + +func TestSendWithNewPhotoWithFileBytes(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + data, _ := ioutil.ReadFile("tests/image.jpg") + b := tgbotapi.FileBytes{Name: "image.jpg", Bytes: data} + + msg := tgbotapi.NewPhotoUpload(76918703, b) + msg.Caption = "Test" + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + + +func TestSendWithNewPhotoWithFileReader(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + f, _ := os.Open("tests/image.jpg") + reader := tgbotapi.FileReader{Name: "image.jpg", Reader: f, Size: -1} + + msg := tgbotapi.NewPhotoUpload(76918703, reader) + msg.Caption = "Test" + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + func TestSendWithNewPhotoReply(t *testing.T) { bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN"))

@@ -430,7 +473,7 @@ t.Errorf("Home page didn't return %v", http.StatusOK)

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

@@ -440,6 +483,24 @@

bot.RemoveWebhook() wh := tgbotapi.NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, "tests/cert.pem") + _, err = bot.SetWebhook(wh) + if err != nil { + t.Fail() + } + + bot.RemoveWebhook() +} + +func TestSetWebhookWithoutCert(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + bot.RemoveWebhook() + + wh := tgbotapi.NewWebhook("https://example.com/tgbotapi-test/" + bot.Token) _, err = bot.SetWebhook(wh) if err != nil { t.Fail()