From 207a1a08f29fa32366ce1daafd54921613ba484e Mon Sep 17 00:00:00 2001 From: Gleb Sinyavsky Date: Sat, 21 Nov 2015 14:36:43 +0300 Subject: [PATCH] Tests added --- bot_test.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/bot_test.go b/bot_test.go index 0d15e11..a86cd36 100644 --- a/bot_test.go +++ b/bot_test.go @@ -8,6 +8,7 @@ import ( "os" "strings" "testing" + "io/ioutil" ) func TestMain(m *testing.M) { @@ -116,6 +117,48 @@ func TestSendWithNewPhoto(t *testing.T) { } } + + +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 @@ func TestListenForWebhook(t *testing.T) { } } -func TestSetWebhook(t *testing.T) { +func TestSetWebhookWithCert(t *testing.T) { bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) if err != nil { @@ -448,6 +491,24 @@ func TestSetWebhook(t *testing.T) { 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() + } + + bot.RemoveWebhook() +} + func TestUpdatesChan(t *testing.T) { bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN"))