Move tests into tgbotapi package.
parent
cdcb93df5f
commit
a746f39d22
147
bot_test.go
147
bot_test.go
|
@ -1,14 +1,11 @@
|
||||||
package tgbotapi_test
|
package tgbotapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -25,8 +22,8 @@ const (
|
||||||
ExistingStickerFileID = "BQADAgADcwADjMcoCbdl-6eB--YPAg"
|
ExistingStickerFileID = "BQADAgADcwADjMcoCbdl-6eB--YPAg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getBot(t *testing.T) (*tgbotapi.BotAPI, error) {
|
func getBot(t *testing.T) (*BotAPI, error) {
|
||||||
bot, err := tgbotapi.NewBotAPI(TestToken)
|
bot, err := NewBotAPI(TestToken)
|
||||||
bot.Debug = true
|
bot.Debug = true
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -38,7 +35,7 @@ func getBot(t *testing.T) (*tgbotapi.BotAPI, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewBotAPI_notoken(t *testing.T) {
|
func TestNewBotAPI_notoken(t *testing.T) {
|
||||||
_, err := tgbotapi.NewBotAPI("")
|
_, err := NewBotAPI("")
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -49,7 +46,7 @@ func TestNewBotAPI_notoken(t *testing.T) {
|
||||||
func TestGetUpdates(t *testing.T) {
|
func TestGetUpdates(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
u := tgbotapi.NewUpdate(0)
|
u := NewUpdate(0)
|
||||||
|
|
||||||
_, err := bot.GetUpdates(u)
|
_, err := bot.GetUpdates(u)
|
||||||
|
|
||||||
|
@ -62,7 +59,7 @@ func TestGetUpdates(t *testing.T) {
|
||||||
func TestSendWithMessage(t *testing.T) {
|
func TestSendWithMessage(t *testing.T) {
|
||||||
bot, _ := getBot(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"
|
msg.ParseMode = "markdown"
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
|
@ -75,7 +72,7 @@ func TestSendWithMessage(t *testing.T) {
|
||||||
func TestSendWithMessageReply(t *testing.T) {
|
func TestSendWithMessageReply(t *testing.T) {
|
||||||
bot, _ := getBot(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
|
msg.ReplyToMessageID = ReplyToMessageID
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
|
@ -88,7 +85,7 @@ func TestSendWithMessageReply(t *testing.T) {
|
||||||
func TestSendWithMessageForward(t *testing.T) {
|
func TestSendWithMessageForward(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewForward(ChatID, ChatID, ReplyToMessageID)
|
msg := NewForward(ChatID, ChatID, ReplyToMessageID)
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -100,7 +97,7 @@ func TestSendWithMessageForward(t *testing.T) {
|
||||||
func TestSendWithNewPhoto(t *testing.T) {
|
func TestSendWithNewPhoto(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewPhotoUpload(ChatID, "tests/image.jpg")
|
msg := NewPhotoUpload(ChatID, "tests/image.jpg")
|
||||||
msg.Caption = "Test"
|
msg.Caption = "Test"
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
|
@ -114,9 +111,9 @@ func TestSendWithNewPhotoWithFileBytes(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
data, _ := ioutil.ReadFile("tests/image.jpg")
|
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"
|
msg.Caption = "Test"
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
|
@ -130,9 +127,9 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
f, _ := os.Open("tests/image.jpg")
|
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"
|
msg.Caption = "Test"
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
|
@ -145,7 +142,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
|
||||||
func TestSendWithNewPhotoReply(t *testing.T) {
|
func TestSendWithNewPhotoReply(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewPhotoUpload(ChatID, "tests/image.jpg")
|
msg := NewPhotoUpload(ChatID, "tests/image.jpg")
|
||||||
msg.ReplyToMessageID = ReplyToMessageID
|
msg.ReplyToMessageID = ReplyToMessageID
|
||||||
|
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
@ -159,7 +156,7 @@ func TestSendWithNewPhotoReply(t *testing.T) {
|
||||||
func TestSendWithExistingPhoto(t *testing.T) {
|
func TestSendWithExistingPhoto(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewPhotoShare(ChatID, ExistingPhotoFileID)
|
msg := NewPhotoShare(ChatID, ExistingPhotoFileID)
|
||||||
msg.Caption = "Test"
|
msg.Caption = "Test"
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
|
@ -172,7 +169,7 @@ func TestSendWithExistingPhoto(t *testing.T) {
|
||||||
func TestSendWithNewDocument(t *testing.T) {
|
func TestSendWithNewDocument(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewDocumentUpload(ChatID, "tests/image.jpg")
|
msg := NewDocumentUpload(ChatID, "tests/image.jpg")
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -184,7 +181,7 @@ func TestSendWithNewDocument(t *testing.T) {
|
||||||
func TestSendWithExistingDocument(t *testing.T) {
|
func TestSendWithExistingDocument(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewDocumentShare(ChatID, ExistingDocumentFileID)
|
msg := NewDocumentShare(ChatID, ExistingDocumentFileID)
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -196,7 +193,7 @@ func TestSendWithExistingDocument(t *testing.T) {
|
||||||
func TestSendWithNewAudio(t *testing.T) {
|
func TestSendWithNewAudio(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewAudioUpload(ChatID, "tests/audio.mp3")
|
msg := NewAudioUpload(ChatID, "tests/audio.mp3")
|
||||||
msg.Title = "TEST"
|
msg.Title = "TEST"
|
||||||
msg.Duration = 10
|
msg.Duration = 10
|
||||||
msg.Performer = "TEST"
|
msg.Performer = "TEST"
|
||||||
|
@ -213,7 +210,7 @@ func TestSendWithNewAudio(t *testing.T) {
|
||||||
func TestSendWithExistingAudio(t *testing.T) {
|
func TestSendWithExistingAudio(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewAudioShare(ChatID, ExistingAudioFileID)
|
msg := NewAudioShare(ChatID, ExistingAudioFileID)
|
||||||
msg.Title = "TEST"
|
msg.Title = "TEST"
|
||||||
msg.Duration = 10
|
msg.Duration = 10
|
||||||
msg.Performer = "TEST"
|
msg.Performer = "TEST"
|
||||||
|
@ -229,7 +226,7 @@ func TestSendWithExistingAudio(t *testing.T) {
|
||||||
func TestSendWithNewVoice(t *testing.T) {
|
func TestSendWithNewVoice(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewVoiceUpload(ChatID, "tests/voice.ogg")
|
msg := NewVoiceUpload(ChatID, "tests/voice.ogg")
|
||||||
msg.Duration = 10
|
msg.Duration = 10
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
|
@ -242,7 +239,7 @@ func TestSendWithNewVoice(t *testing.T) {
|
||||||
func TestSendWithExistingVoice(t *testing.T) {
|
func TestSendWithExistingVoice(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewVoiceShare(ChatID, ExistingVoiceFileID)
|
msg := NewVoiceShare(ChatID, ExistingVoiceFileID)
|
||||||
msg.Duration = 10
|
msg.Duration = 10
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
|
@ -255,7 +252,7 @@ func TestSendWithExistingVoice(t *testing.T) {
|
||||||
func TestSendWithContact(t *testing.T) {
|
func TestSendWithContact(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
contact := tgbotapi.NewContact(ChatID, "5551234567", "Test")
|
contact := NewContact(ChatID, "5551234567", "Test")
|
||||||
|
|
||||||
if _, err := bot.Send(contact); err != nil {
|
if _, err := bot.Send(contact); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -266,7 +263,7 @@ func TestSendWithContact(t *testing.T) {
|
||||||
func TestSendWithLocation(t *testing.T) {
|
func TestSendWithLocation(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
_, err := bot.Send(tgbotapi.NewLocation(ChatID, 40, 40))
|
_, err := bot.Send(NewLocation(ChatID, 40, 40))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -277,7 +274,7 @@ func TestSendWithLocation(t *testing.T) {
|
||||||
func TestSendWithVenue(t *testing.T) {
|
func TestSendWithVenue(t *testing.T) {
|
||||||
bot, _ := getBot(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 {
|
if _, err := bot.Send(venue); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -288,7 +285,7 @@ func TestSendWithVenue(t *testing.T) {
|
||||||
func TestSendWithNewVideo(t *testing.T) {
|
func TestSendWithNewVideo(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewVideoUpload(ChatID, "tests/video.mp4")
|
msg := NewVideoUpload(ChatID, "tests/video.mp4")
|
||||||
msg.Duration = 10
|
msg.Duration = 10
|
||||||
msg.Caption = "TEST"
|
msg.Caption = "TEST"
|
||||||
|
|
||||||
|
@ -303,7 +300,7 @@ func TestSendWithNewVideo(t *testing.T) {
|
||||||
func TestSendWithExistingVideo(t *testing.T) {
|
func TestSendWithExistingVideo(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewVideoShare(ChatID, ExistingVideoFileID)
|
msg := NewVideoShare(ChatID, ExistingVideoFileID)
|
||||||
msg.Duration = 10
|
msg.Duration = 10
|
||||||
msg.Caption = "TEST"
|
msg.Caption = "TEST"
|
||||||
|
|
||||||
|
@ -318,7 +315,7 @@ func TestSendWithExistingVideo(t *testing.T) {
|
||||||
func TestSendWithNewVideoNote(t *testing.T) {
|
func TestSendWithNewVideoNote(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewVideoNoteUpload(ChatID, 240, "tests/videonote.mp4")
|
msg := NewVideoNoteUpload(ChatID, 240, "tests/videonote.mp4")
|
||||||
msg.Duration = 10
|
msg.Duration = 10
|
||||||
|
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
@ -332,7 +329,7 @@ func TestSendWithNewVideoNote(t *testing.T) {
|
||||||
func TestSendWithExistingVideoNote(t *testing.T) {
|
func TestSendWithExistingVideoNote(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewVideoNoteShare(ChatID, 240, ExistingVideoNoteFileID)
|
msg := NewVideoNoteShare(ChatID, 240, ExistingVideoNoteFileID)
|
||||||
msg.Duration = 10
|
msg.Duration = 10
|
||||||
|
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
@ -346,7 +343,7 @@ func TestSendWithExistingVideoNote(t *testing.T) {
|
||||||
func TestSendWithNewSticker(t *testing.T) {
|
func TestSendWithNewSticker(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewStickerUpload(ChatID, "tests/image.jpg")
|
msg := NewStickerUpload(ChatID, "tests/image.jpg")
|
||||||
|
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
|
@ -359,7 +356,7 @@ func TestSendWithNewSticker(t *testing.T) {
|
||||||
func TestSendWithExistingSticker(t *testing.T) {
|
func TestSendWithExistingSticker(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewStickerShare(ChatID, ExistingStickerFileID)
|
msg := NewStickerShare(ChatID, ExistingStickerFileID)
|
||||||
|
|
||||||
_, err := bot.Send(msg)
|
_, err := bot.Send(msg)
|
||||||
|
|
||||||
|
@ -372,8 +369,8 @@ func TestSendWithExistingSticker(t *testing.T) {
|
||||||
func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
|
func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewStickerUpload(ChatID, "tests/image.jpg")
|
msg := NewStickerUpload(ChatID, "tests/image.jpg")
|
||||||
msg.ReplyMarkup = tgbotapi.ReplyKeyboardRemove{
|
msg.ReplyMarkup = ReplyKeyboardRemove{
|
||||||
RemoveKeyboard: true,
|
RemoveKeyboard: true,
|
||||||
Selective: false,
|
Selective: false,
|
||||||
}
|
}
|
||||||
|
@ -388,8 +385,8 @@ func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
|
||||||
func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) {
|
func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg := tgbotapi.NewStickerShare(ChatID, ExistingStickerFileID)
|
msg := NewStickerShare(ChatID, ExistingStickerFileID)
|
||||||
msg.ReplyMarkup = tgbotapi.ReplyKeyboardRemove{
|
msg.ReplyMarkup = ReplyKeyboardRemove{
|
||||||
RemoveKeyboard: true,
|
RemoveKeyboard: true,
|
||||||
Selective: false,
|
Selective: false,
|
||||||
}
|
}
|
||||||
|
@ -405,7 +402,7 @@ func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) {
|
||||||
func TestGetFile(t *testing.T) {
|
func TestGetFile(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
file := tgbotapi.FileConfig{
|
file := FileConfig{
|
||||||
FileID: ExistingPhotoFileID,
|
FileID: ExistingPhotoFileID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,7 +417,7 @@ func TestGetFile(t *testing.T) {
|
||||||
func TestSendChatConfig(t *testing.T) {
|
func TestSendChatConfig(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
_, err := bot.Request(tgbotapi.NewChatAction(ChatID, tgbotapi.ChatTyping))
|
_, err := bot.Request(NewChatAction(ChatID, ChatTyping))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -431,14 +428,14 @@ func TestSendChatConfig(t *testing.T) {
|
||||||
func TestSendEditMessage(t *testing.T) {
|
func TestSendEditMessage(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
msg, err := bot.Send(tgbotapi.NewMessage(ChatID, "Testing editing."))
|
msg, err := bot.Send(NewMessage(ChatID, "Testing editing."))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
edit := tgbotapi.EditMessageTextConfig{
|
edit := EditMessageTextConfig{
|
||||||
BaseEdit: tgbotapi.BaseEdit{
|
BaseEdit: BaseEdit{
|
||||||
ChatID: ChatID,
|
ChatID: ChatID,
|
||||||
MessageID: msg.MessageID,
|
MessageID: msg.MessageID,
|
||||||
},
|
},
|
||||||
|
@ -455,7 +452,7 @@ func TestSendEditMessage(t *testing.T) {
|
||||||
func TestGetUserProfilePhotos(t *testing.T) {
|
func TestGetUserProfilePhotos(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
_, err := bot.GetUserProfilePhotos(tgbotapi.NewUserProfilePhotos(ChatID))
|
_, err := bot.GetUserProfilePhotos(NewUserProfilePhotos(ChatID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -467,9 +464,9 @@ func TestSetWebhookWithCert(t *testing.T) {
|
||||||
|
|
||||||
time.Sleep(time.Second * 2)
|
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)
|
_, err := bot.Request(wh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -482,7 +479,7 @@ func TestSetWebhookWithCert(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.Request(tgbotapi.RemoveWebhookConfig{})
|
bot.Request(RemoveWebhookConfig{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetWebhookWithoutCert(t *testing.T) {
|
func TestSetWebhookWithoutCert(t *testing.T) {
|
||||||
|
@ -490,9 +487,9 @@ func TestSetWebhookWithoutCert(t *testing.T) {
|
||||||
|
|
||||||
time.Sleep(time.Second * 2)
|
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)
|
_, err := bot.Request(wh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -509,13 +506,13 @@ func TestSetWebhookWithoutCert(t *testing.T) {
|
||||||
t.Errorf("failed to set webhook: %s", info.LastErrorMessage)
|
t.Errorf("failed to set webhook: %s", info.LastErrorMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.Request(tgbotapi.RemoveWebhookConfig{})
|
bot.Request(RemoveWebhookConfig{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdatesChan(t *testing.T) {
|
func TestUpdatesChan(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
var ucfg tgbotapi.UpdateConfig = tgbotapi.NewUpdate(0)
|
var ucfg = NewUpdate(0)
|
||||||
ucfg.Timeout = 60
|
ucfg.Timeout = 60
|
||||||
_, err := bot.GetUpdatesChan(ucfg)
|
_, err := bot.GetUpdatesChan(ucfg)
|
||||||
|
|
||||||
|
@ -528,10 +525,10 @@ func TestUpdatesChan(t *testing.T) {
|
||||||
func TestSendWithMediaGroup(t *testing.T) {
|
func TestSendWithMediaGroup(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
cfg := tgbotapi.NewMediaGroup(ChatID, []interface{}{
|
cfg := NewMediaGroup(ChatID, []interface{}{
|
||||||
tgbotapi.NewInputMediaPhoto("https://i.imgur.com/unQLJIb.jpg"),
|
NewInputMediaPhoto("https://i.imgur.com/unQLJIb.jpg"),
|
||||||
tgbotapi.NewInputMediaPhoto("https://i.imgur.com/J5qweNZ.jpg"),
|
NewInputMediaPhoto("https://i.imgur.com/J5qweNZ.jpg"),
|
||||||
tgbotapi.NewInputMediaVideo("https://i.imgur.com/F6RmI24.mp4"),
|
NewInputMediaVideo("https://i.imgur.com/F6RmI24.mp4"),
|
||||||
})
|
})
|
||||||
_, err := bot.Request(cfg)
|
_, err := bot.Request(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -540,16 +537,16 @@ func TestSendWithMediaGroup(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleNewBotAPI() {
|
func ExampleNewBotAPI() {
|
||||||
bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
|
bot, err := NewBotAPI("MyAwesomeBotToken")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.Debug = true
|
bot.Debug = true
|
||||||
|
|
||||||
log.Printf("Authorized on account %s", bot.Self.UserName)
|
log.Printf("Authorized on account %s", bot.Self.UserName)
|
||||||
|
|
||||||
u := tgbotapi.NewUpdate(0)
|
u := NewUpdate(0)
|
||||||
u.Timeout = 60
|
u.Timeout = 60
|
||||||
|
|
||||||
updates, err := bot.GetUpdatesChan(u)
|
updates, err := bot.GetUpdatesChan(u)
|
||||||
|
@ -566,7 +563,7 @@ func ExampleNewBotAPI() {
|
||||||
|
|
||||||
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
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
|
msg.ReplyToMessageID = update.Message.MessageID
|
||||||
|
|
||||||
bot.Send(msg)
|
bot.Send(msg)
|
||||||
|
@ -574,24 +571,24 @@ func ExampleNewBotAPI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleNewWebhook() {
|
func ExampleNewWebhook() {
|
||||||
bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
|
bot, err := NewBotAPI("MyAwesomeBotToken")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.Debug = true
|
bot.Debug = true
|
||||||
|
|
||||||
log.Printf("Authorized on account %s", bot.Self.UserName)
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := bot.GetWebhookInfo()
|
info, err := bot.GetWebhookInfo()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.LastErrorDate != 0 {
|
if info.LastErrorDate != 0 {
|
||||||
|
@ -607,14 +604,14 @@ func ExampleNewWebhook() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleInlineConfig() {
|
func ExampleInlineConfig() {
|
||||||
bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken") // create new bot
|
bot, err := NewBotAPI("MyAwesomeBotToken") // create new bot
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Authorized on account %s", bot.Self.UserName)
|
log.Printf("Authorized on account %s", bot.Self.UserName)
|
||||||
|
|
||||||
u := tgbotapi.NewUpdate(0)
|
u := NewUpdate(0)
|
||||||
u.Timeout = 60
|
u.Timeout = 60
|
||||||
|
|
||||||
updates, err := bot.GetUpdatesChan(u)
|
updates, err := bot.GetUpdatesChan(u)
|
||||||
|
@ -624,10 +621,10 @@ func ExampleInlineConfig() {
|
||||||
continue
|
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
|
article.Description = update.InlineQuery.Query
|
||||||
|
|
||||||
inlineConf := tgbotapi.InlineConfig{
|
inlineConf := InlineConfig{
|
||||||
InlineQueryID: update.InlineQuery.ID,
|
InlineQueryID: update.InlineQuery.ID,
|
||||||
IsPersonal: true,
|
IsPersonal: true,
|
||||||
CacheTime: 0,
|
CacheTime: 0,
|
||||||
|
@ -643,11 +640,11 @@ func ExampleInlineConfig() {
|
||||||
func TestDeleteMessage(t *testing.T) {
|
func TestDeleteMessage(t *testing.T) {
|
||||||
bot, _ := getBot(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"
|
msg.ParseMode = "markdown"
|
||||||
message, _ := bot.Send(msg)
|
message, _ := bot.Send(msg)
|
||||||
|
|
||||||
deleteMessageConfig := tgbotapi.DeleteMessageConfig{
|
deleteMessageConfig := DeleteMessageConfig{
|
||||||
ChatID: message.Chat.ID,
|
ChatID: message.Chat.ID,
|
||||||
MessageID: message.MessageID,
|
MessageID: message.MessageID,
|
||||||
}
|
}
|
||||||
|
@ -662,11 +659,11 @@ func TestDeleteMessage(t *testing.T) {
|
||||||
func TestPinChatMessage(t *testing.T) {
|
func TestPinChatMessage(t *testing.T) {
|
||||||
bot, _ := getBot(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"
|
msg.ParseMode = "markdown"
|
||||||
message, _ := bot.Send(msg)
|
message, _ := bot.Send(msg)
|
||||||
|
|
||||||
pinChatMessageConfig := tgbotapi.PinChatMessageConfig{
|
pinChatMessageConfig := PinChatMessageConfig{
|
||||||
ChatID: message.Chat.ID,
|
ChatID: message.Chat.ID,
|
||||||
MessageID: message.MessageID,
|
MessageID: message.MessageID,
|
||||||
DisableNotification: false,
|
DisableNotification: false,
|
||||||
|
@ -682,12 +679,12 @@ func TestPinChatMessage(t *testing.T) {
|
||||||
func TestUnpinChatMessage(t *testing.T) {
|
func TestUnpinChatMessage(t *testing.T) {
|
||||||
bot, _ := getBot(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"
|
msg.ParseMode = "markdown"
|
||||||
message, _ := bot.Send(msg)
|
message, _ := bot.Send(msg)
|
||||||
|
|
||||||
// We need pin message to unpin something
|
// We need pin message to unpin something
|
||||||
pinChatMessageConfig := tgbotapi.PinChatMessageConfig{
|
pinChatMessageConfig := PinChatMessageConfig{
|
||||||
ChatID: message.Chat.ID,
|
ChatID: message.Chat.ID,
|
||||||
MessageID: message.MessageID,
|
MessageID: message.MessageID,
|
||||||
DisableNotification: false,
|
DisableNotification: false,
|
||||||
|
@ -698,7 +695,7 @@ func TestUnpinChatMessage(t *testing.T) {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
unpinChatMessageConfig := tgbotapi.UnpinChatMessageConfig{
|
unpinChatMessageConfig := UnpinChatMessageConfig{
|
||||||
ChatID: message.Chat.ID,
|
ChatID: message.Chat.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,48 +1,46 @@
|
||||||
package tgbotapi_test
|
package tgbotapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewInlineQueryResultArticle(t *testing.T) {
|
func TestNewInlineQueryResultArticle(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultArticle("id", "title", "message")
|
result := NewInlineQueryResultArticle("id", "title", "message")
|
||||||
|
|
||||||
if result.Type != "article" ||
|
if result.Type != "article" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
result.Title != "title" ||
|
result.Title != "title" ||
|
||||||
result.InputMessageContent.(tgbotapi.InputTextMessageContent).Text != "message" {
|
result.InputMessageContent.(InputTextMessageContent).Text != "message" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultArticleMarkdown(t *testing.T) {
|
func TestNewInlineQueryResultArticleMarkdown(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultArticleMarkdown("id", "title", "*message*")
|
result := NewInlineQueryResultArticleMarkdown("id", "title", "*message*")
|
||||||
|
|
||||||
if result.Type != "article" ||
|
if result.Type != "article" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
result.Title != "title" ||
|
result.Title != "title" ||
|
||||||
result.InputMessageContent.(tgbotapi.InputTextMessageContent).Text != "*message*" ||
|
result.InputMessageContent.(InputTextMessageContent).Text != "*message*" ||
|
||||||
result.InputMessageContent.(tgbotapi.InputTextMessageContent).ParseMode != "Markdown" {
|
result.InputMessageContent.(InputTextMessageContent).ParseMode != "Markdown" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultArticleHTML(t *testing.T) {
|
func TestNewInlineQueryResultArticleHTML(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultArticleHTML("id", "title", "<b>message</b>")
|
result := NewInlineQueryResultArticleHTML("id", "title", "<b>message</b>")
|
||||||
|
|
||||||
if result.Type != "article" ||
|
if result.Type != "article" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
result.Title != "title" ||
|
result.Title != "title" ||
|
||||||
result.InputMessageContent.(tgbotapi.InputTextMessageContent).Text != "<b>message</b>" ||
|
result.InputMessageContent.(InputTextMessageContent).Text != "<b>message</b>" ||
|
||||||
result.InputMessageContent.(tgbotapi.InputTextMessageContent).ParseMode != "HTML" {
|
result.InputMessageContent.(InputTextMessageContent).ParseMode != "HTML" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultGIF(t *testing.T) {
|
func TestNewInlineQueryResultGIF(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultGIF("id", "google.com")
|
result := NewInlineQueryResultGIF("id", "google.com")
|
||||||
|
|
||||||
if result.Type != "gif" ||
|
if result.Type != "gif" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
|
@ -52,7 +50,7 @@ func TestNewInlineQueryResultGIF(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultMPEG4GIF(t *testing.T) {
|
func TestNewInlineQueryResultMPEG4GIF(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultMPEG4GIF("id", "google.com")
|
result := NewInlineQueryResultMPEG4GIF("id", "google.com")
|
||||||
|
|
||||||
if result.Type != "mpeg4_gif" ||
|
if result.Type != "mpeg4_gif" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
|
@ -62,7 +60,7 @@ func TestNewInlineQueryResultMPEG4GIF(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultPhoto(t *testing.T) {
|
func TestNewInlineQueryResultPhoto(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultPhoto("id", "google.com")
|
result := NewInlineQueryResultPhoto("id", "google.com")
|
||||||
|
|
||||||
if result.Type != "photo" ||
|
if result.Type != "photo" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
|
@ -72,7 +70,7 @@ func TestNewInlineQueryResultPhoto(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultPhotoWithThumb(t *testing.T) {
|
func TestNewInlineQueryResultPhotoWithThumb(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultPhotoWithThumb("id", "google.com", "thumb.com")
|
result := NewInlineQueryResultPhotoWithThumb("id", "google.com", "thumb.com")
|
||||||
|
|
||||||
if result.Type != "photo" ||
|
if result.Type != "photo" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
|
@ -83,7 +81,7 @@ func TestNewInlineQueryResultPhotoWithThumb(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultVideo(t *testing.T) {
|
func TestNewInlineQueryResultVideo(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultVideo("id", "google.com")
|
result := NewInlineQueryResultVideo("id", "google.com")
|
||||||
|
|
||||||
if result.Type != "video" ||
|
if result.Type != "video" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
|
@ -93,7 +91,7 @@ func TestNewInlineQueryResultVideo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultAudio(t *testing.T) {
|
func TestNewInlineQueryResultAudio(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultAudio("id", "google.com", "title")
|
result := NewInlineQueryResultAudio("id", "google.com", "title")
|
||||||
|
|
||||||
if result.Type != "audio" ||
|
if result.Type != "audio" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
|
@ -104,7 +102,7 @@ func TestNewInlineQueryResultAudio(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultVoice(t *testing.T) {
|
func TestNewInlineQueryResultVoice(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultVoice("id", "google.com", "title")
|
result := NewInlineQueryResultVoice("id", "google.com", "title")
|
||||||
|
|
||||||
if result.Type != "voice" ||
|
if result.Type != "voice" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
|
@ -115,7 +113,7 @@ func TestNewInlineQueryResultVoice(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultDocument(t *testing.T) {
|
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" ||
|
if result.Type != "document" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
|
@ -127,7 +125,7 @@ func TestNewInlineQueryResultDocument(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewInlineQueryResultLocation(t *testing.T) {
|
func TestNewInlineQueryResultLocation(t *testing.T) {
|
||||||
result := tgbotapi.NewInlineQueryResultLocation("id", "name", 40, 50)
|
result := NewInlineQueryResultLocation("id", "name", 40, 50)
|
||||||
|
|
||||||
if result.Type != "location" ||
|
if result.Type != "location" ||
|
||||||
result.ID != "id" ||
|
result.ID != "id" ||
|
||||||
|
@ -139,7 +137,7 @@ func TestNewInlineQueryResultLocation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewEditMessageText(t *testing.T) {
|
func TestNewEditMessageText(t *testing.T) {
|
||||||
edit := tgbotapi.NewEditMessageText(ChatID, ReplyToMessageID, "new text")
|
edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text")
|
||||||
|
|
||||||
if edit.Text != "new text" ||
|
if edit.Text != "new text" ||
|
||||||
edit.BaseEdit.ChatID != ChatID ||
|
edit.BaseEdit.ChatID != ChatID ||
|
||||||
|
@ -149,7 +147,7 @@ func TestNewEditMessageText(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewEditMessageCaption(t *testing.T) {
|
func TestNewEditMessageCaption(t *testing.T) {
|
||||||
edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption")
|
edit := NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption")
|
||||||
|
|
||||||
if edit.Caption != "new caption" ||
|
if edit.Caption != "new caption" ||
|
||||||
edit.BaseEdit.ChatID != ChatID ||
|
edit.BaseEdit.ChatID != ChatID ||
|
||||||
|
@ -159,15 +157,15 @@ func TestNewEditMessageCaption(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewEditMessageReplyMarkup(t *testing.T) {
|
func TestNewEditMessageReplyMarkup(t *testing.T) {
|
||||||
markup := tgbotapi.InlineKeyboardMarkup{
|
markup := InlineKeyboardMarkup{
|
||||||
InlineKeyboard: [][]tgbotapi.InlineKeyboardButton{
|
InlineKeyboard: [][]InlineKeyboardButton{
|
||||||
[]tgbotapi.InlineKeyboardButton{
|
[]InlineKeyboardButton{
|
||||||
tgbotapi.InlineKeyboardButton{Text: "test"},
|
InlineKeyboardButton{Text: "test"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
edit := tgbotapi.NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup)
|
edit := NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup)
|
||||||
|
|
||||||
if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" ||
|
if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" ||
|
||||||
edit.BaseEdit.ChatID != ChatID ||
|
edit.BaseEdit.ChatID != ChatID ||
|
||||||
|
|
134
types_test.go
134
types_test.go
|
@ -1,14 +1,12 @@
|
||||||
package tgbotapi_test
|
package tgbotapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUserStringWith(t *testing.T) {
|
func TestUserStringWith(t *testing.T) {
|
||||||
user := tgbotapi.User{
|
user := User{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
FirstName: "Test",
|
FirstName: "Test",
|
||||||
LastName: "Test",
|
LastName: "Test",
|
||||||
|
@ -23,7 +21,7 @@ func TestUserStringWith(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserStringWithUserName(t *testing.T) {
|
func TestUserStringWithUserName(t *testing.T) {
|
||||||
user := tgbotapi.User{
|
user := User{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
FirstName: "Test",
|
FirstName: "Test",
|
||||||
LastName: "Test",
|
LastName: "Test",
|
||||||
|
@ -37,7 +35,7 @@ func TestUserStringWithUserName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageTime(t *testing.T) {
|
func TestMessageTime(t *testing.T) {
|
||||||
message := tgbotapi.Message{Date: 0}
|
message := Message{Date: 0}
|
||||||
|
|
||||||
date := time.Unix(0, 0)
|
date := time.Unix(0, 0)
|
||||||
if message.Time() != date {
|
if message.Time() != date {
|
||||||
|
@ -46,8 +44,8 @@ func TestMessageTime(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageIsCommandWithCommand(t *testing.T) {
|
func TestMessageIsCommandWithCommand(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: "/command"}
|
message := Message{Text: "/command"}
|
||||||
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||||
|
|
||||||
if !message.IsCommand() {
|
if !message.IsCommand() {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -55,7 +53,7 @@ func TestMessageIsCommandWithCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsCommandWithText(t *testing.T) {
|
func TestIsCommandWithText(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: "some text"}
|
message := Message{Text: "some text"}
|
||||||
|
|
||||||
if message.IsCommand() {
|
if message.IsCommand() {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -63,7 +61,7 @@ func TestIsCommandWithText(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsCommandWithEmptyText(t *testing.T) {
|
func TestIsCommandWithEmptyText(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: ""}
|
message := Message{Text: ""}
|
||||||
|
|
||||||
if message.IsCommand() {
|
if message.IsCommand() {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -71,8 +69,8 @@ func TestIsCommandWithEmptyText(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandWithCommand(t *testing.T) {
|
func TestCommandWithCommand(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: "/command"}
|
message := Message{Text: "/command"}
|
||||||
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||||
|
|
||||||
if message.Command() != "command" {
|
if message.Command() != "command" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -80,7 +78,7 @@ func TestCommandWithCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandWithEmptyText(t *testing.T) {
|
func TestCommandWithEmptyText(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: ""}
|
message := Message{Text: ""}
|
||||||
|
|
||||||
if message.Command() != "" {
|
if message.Command() != "" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -88,7 +86,7 @@ func TestCommandWithEmptyText(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandWithNonCommand(t *testing.T) {
|
func TestCommandWithNonCommand(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: "test text"}
|
message := Message{Text: "test text"}
|
||||||
|
|
||||||
if message.Command() != "" {
|
if message.Command() != "" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -96,8 +94,8 @@ func TestCommandWithNonCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandWithBotName(t *testing.T) {
|
func TestCommandWithBotName(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: "/command@testbot"}
|
message := Message{Text: "/command@testbot"}
|
||||||
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
||||||
|
|
||||||
if message.Command() != "command" {
|
if message.Command() != "command" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -105,8 +103,8 @@ func TestCommandWithBotName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandWithAtWithBotName(t *testing.T) {
|
func TestCommandWithAtWithBotName(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: "/command@testbot"}
|
message := Message{Text: "/command@testbot"}
|
||||||
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
||||||
|
|
||||||
if message.CommandWithAt() != "command@testbot" {
|
if message.CommandWithAt() != "command@testbot" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -114,37 +112,37 @@ func TestCommandWithAtWithBotName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageCommandArgumentsWithArguments(t *testing.T) {
|
func TestMessageCommandArgumentsWithArguments(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: "/command with arguments"}
|
message := Message{Text: "/command with arguments"}
|
||||||
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||||
if message.CommandArguments() != "with arguments" {
|
if message.CommandArguments() != "with arguments" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageCommandArgumentsWithMalformedArguments(t *testing.T) {
|
func TestMessageCommandArgumentsWithMalformedArguments(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: "/command-without argument space"}
|
message := Message{Text: "/command-without argument space"}
|
||||||
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||||
if message.CommandArguments() != "without argument space" {
|
if message.CommandArguments() != "without argument space" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageCommandArgumentsWithoutArguments(t *testing.T) {
|
func TestMessageCommandArgumentsWithoutArguments(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: "/command"}
|
message := Message{Text: "/command"}
|
||||||
if message.CommandArguments() != "" {
|
if message.CommandArguments() != "" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageCommandArgumentsForNonCommand(t *testing.T) {
|
func TestMessageCommandArgumentsForNonCommand(t *testing.T) {
|
||||||
message := tgbotapi.Message{Text: "test text"}
|
message := Message{Text: "test text"}
|
||||||
if message.CommandArguments() != "" {
|
if message.CommandArguments() != "" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageEntityParseURLGood(t *testing.T) {
|
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 {
|
if _, err := entity.ParseURL(); err != nil {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -152,7 +150,7 @@ func TestMessageEntityParseURLGood(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageEntityParseURLBad(t *testing.T) {
|
func TestMessageEntityParseURLBad(t *testing.T) {
|
||||||
entity := tgbotapi.MessageEntity{URL: ""}
|
entity := MessageEntity{URL: ""}
|
||||||
|
|
||||||
if _, err := entity.ParseURL(); err == nil {
|
if _, err := entity.ParseURL(); err == nil {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -160,7 +158,7 @@ func TestMessageEntityParseURLBad(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChatIsPrivate(t *testing.T) {
|
func TestChatIsPrivate(t *testing.T) {
|
||||||
chat := tgbotapi.Chat{ID: 10, Type: "private"}
|
chat := Chat{ID: 10, Type: "private"}
|
||||||
|
|
||||||
if !chat.IsPrivate() {
|
if !chat.IsPrivate() {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -168,7 +166,7 @@ func TestChatIsPrivate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChatIsGroup(t *testing.T) {
|
func TestChatIsGroup(t *testing.T) {
|
||||||
chat := tgbotapi.Chat{ID: 10, Type: "group"}
|
chat := Chat{ID: 10, Type: "group"}
|
||||||
|
|
||||||
if !chat.IsGroup() {
|
if !chat.IsGroup() {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -176,7 +174,7 @@ func TestChatIsGroup(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChatIsChannel(t *testing.T) {
|
func TestChatIsChannel(t *testing.T) {
|
||||||
chat := tgbotapi.Chat{ID: 10, Type: "channel"}
|
chat := Chat{ID: 10, Type: "channel"}
|
||||||
|
|
||||||
if !chat.IsChannel() {
|
if !chat.IsChannel() {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -184,7 +182,7 @@ func TestChatIsChannel(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChatIsSuperGroup(t *testing.T) {
|
func TestChatIsSuperGroup(t *testing.T) {
|
||||||
chat := tgbotapi.Chat{ID: 10, Type: "supergroup"}
|
chat := Chat{ID: 10, Type: "supergroup"}
|
||||||
|
|
||||||
if !chat.IsSuperGroup() {
|
if !chat.IsSuperGroup() {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -192,7 +190,7 @@ func TestChatIsSuperGroup(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFileLink(t *testing.T) {
|
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" {
|
if file.Link("token") != "https://api.telegram.org/file/bottoken/test/test.txt" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -201,41 +199,41 @@ func TestFileLink(t *testing.T) {
|
||||||
|
|
||||||
// Ensure all configs are sendable
|
// Ensure all configs are sendable
|
||||||
var (
|
var (
|
||||||
_ tgbotapi.Chattable = tgbotapi.AnimationConfig{}
|
_ Chattable = AnimationConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.AudioConfig{}
|
_ Chattable = AudioConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.CallbackConfig{}
|
_ Chattable = CallbackConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.ChatActionConfig{}
|
_ Chattable = ChatActionConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.ContactConfig{}
|
_ Chattable = ContactConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.DeleteChatPhotoConfig{}
|
_ Chattable = DeleteChatPhotoConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.DeleteChatStickerSetConfig{}
|
_ Chattable = DeleteChatStickerSetConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.DeleteMessageConfig{}
|
_ Chattable = DeleteMessageConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.DocumentConfig{}
|
_ Chattable = DocumentConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.EditMessageCaptionConfig{}
|
_ Chattable = EditMessageCaptionConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.EditMessageLiveLocationConfig{}
|
_ Chattable = EditMessageLiveLocationConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.EditMessageReplyMarkupConfig{}
|
_ Chattable = EditMessageReplyMarkupConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.EditMessageTextConfig{}
|
_ Chattable = EditMessageTextConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.ForwardConfig{}
|
_ Chattable = ForwardConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.GameConfig{}
|
_ Chattable = GameConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.GetGameHighScoresConfig{}
|
_ Chattable = GetGameHighScoresConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.InlineConfig{}
|
_ Chattable = InlineConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.InvoiceConfig{}
|
_ Chattable = InvoiceConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.KickChatMemberConfig{}
|
_ Chattable = KickChatMemberConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.LocationConfig{}
|
_ Chattable = LocationConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.MediaGroupConfig{}
|
_ Chattable = MediaGroupConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.MessageConfig{}
|
_ Chattable = MessageConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.PhotoConfig{}
|
_ Chattable = PhotoConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.PinChatMessageConfig{}
|
_ Chattable = PinChatMessageConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.SetChatDescriptionConfig{}
|
_ Chattable = SetChatDescriptionConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.SetChatPhotoConfig{}
|
_ Chattable = SetChatPhotoConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.SetChatTitleConfig{}
|
_ Chattable = SetChatTitleConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.SetGameScoreConfig{}
|
_ Chattable = SetGameScoreConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.StickerConfig{}
|
_ Chattable = StickerConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.UnpinChatMessageConfig{}
|
_ Chattable = UnpinChatMessageConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.UpdateConfig{}
|
_ Chattable = UpdateConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.UserProfilePhotosConfig{}
|
_ Chattable = UserProfilePhotosConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.VenueConfig{}
|
_ Chattable = VenueConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.VideoConfig{}
|
_ Chattable = VideoConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.VideoNoteConfig{}
|
_ Chattable = VideoNoteConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.VoiceConfig{}
|
_ Chattable = VoiceConfig{}
|
||||||
_ tgbotapi.Chattable = tgbotapi.WebhookConfig{}
|
_ Chattable = WebhookConfig{}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue