Tests added

bot-api-6.1
Gleb Sinyavsky 2015-11-21 14:36:43 +03:00
parent 9644984dae
commit 207a1a08f2
1 changed files with 62 additions and 1 deletions

View File

@ -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"))