Add support for uploading multiple files.
This commit is contained in:
parent
2f7211a708
commit
ce4fc988c9
8 changed files with 414 additions and 524 deletions
68
bot_test.go
68
bot_test.go
|
@ -92,7 +92,7 @@ func TestSendWithMessageForward(t *testing.T) {
|
|||
func TestSendWithNewPhoto(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewPhotoUpload(ChatID, "tests/image.jpg")
|
||||
msg := NewPhoto(ChatID, "tests/image.jpg")
|
||||
msg.Caption = "Test"
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -107,7 +107,7 @@ func TestSendWithNewPhotoWithFileBytes(t *testing.T) {
|
|||
data, _ := ioutil.ReadFile("tests/image.jpg")
|
||||
b := FileBytes{Name: "image.jpg", Bytes: data}
|
||||
|
||||
msg := NewPhotoUpload(ChatID, b)
|
||||
msg := NewPhoto(ChatID, b)
|
||||
msg.Caption = "Test"
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -122,7 +122,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
|
|||
f, _ := os.Open("tests/image.jpg")
|
||||
reader := FileReader{Name: "image.jpg", Reader: f, Size: -1}
|
||||
|
||||
msg := NewPhotoUpload(ChatID, reader)
|
||||
msg := NewPhoto(ChatID, reader)
|
||||
msg.Caption = "Test"
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -134,7 +134,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
|
|||
func TestSendWithNewPhotoReply(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewPhotoUpload(ChatID, "tests/image.jpg")
|
||||
msg := NewPhoto(ChatID, "tests/image.jpg")
|
||||
msg.ReplyToMessageID = ReplyToMessageID
|
||||
|
||||
_, err := bot.Send(msg)
|
||||
|
@ -147,7 +147,7 @@ func TestSendWithNewPhotoReply(t *testing.T) {
|
|||
func TestSendNewPhotoToChannel(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewPhotoUploadToChannel(Channel, "tests/image.jpg")
|
||||
msg := NewPhotoToChannel(Channel, "tests/image.jpg")
|
||||
msg.Caption = "Test"
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -163,7 +163,7 @@ func TestSendNewPhotoToChannelFileBytes(t *testing.T) {
|
|||
data, _ := ioutil.ReadFile("tests/image.jpg")
|
||||
b := FileBytes{Name: "image.jpg", Bytes: data}
|
||||
|
||||
msg := NewPhotoUploadToChannel(Channel, b)
|
||||
msg := NewPhotoToChannel(Channel, b)
|
||||
msg.Caption = "Test"
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -179,7 +179,7 @@ func TestSendNewPhotoToChannelFileReader(t *testing.T) {
|
|||
f, _ := os.Open("tests/image.jpg")
|
||||
reader := FileReader{Name: "image.jpg", Reader: f, Size: -1}
|
||||
|
||||
msg := NewPhotoUploadToChannel(Channel, reader)
|
||||
msg := NewPhotoToChannel(Channel, reader)
|
||||
msg.Caption = "Test"
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -192,7 +192,7 @@ func TestSendNewPhotoToChannelFileReader(t *testing.T) {
|
|||
func TestSendWithExistingPhoto(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewPhotoShare(ChatID, ExistingPhotoFileID)
|
||||
msg := NewPhoto(ChatID, FileID(ExistingPhotoFileID))
|
||||
msg.Caption = "Test"
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -204,7 +204,19 @@ func TestSendWithExistingPhoto(t *testing.T) {
|
|||
func TestSendWithNewDocument(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewDocumentUpload(ChatID, "tests/image.jpg")
|
||||
msg := NewDocument(ChatID, "tests/image.jpg")
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendWithNewDocumentAndThumb(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewDocument(ChatID, "tests/voice.ogg")
|
||||
msg.AddFile("thumb", "tests/image.jpg")
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
if err != nil {
|
||||
|
@ -215,7 +227,7 @@ func TestSendWithNewDocument(t *testing.T) {
|
|||
func TestSendWithExistingDocument(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewDocumentShare(ChatID, ExistingDocumentFileID)
|
||||
msg := NewDocument(ChatID, FileID(ExistingDocumentFileID))
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
if err != nil {
|
||||
|
@ -226,7 +238,7 @@ func TestSendWithExistingDocument(t *testing.T) {
|
|||
func TestSendWithNewAudio(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewAudioUpload(ChatID, "tests/audio.mp3")
|
||||
msg := NewAudio(ChatID, "tests/audio.mp3")
|
||||
msg.Title = "TEST"
|
||||
msg.Duration = 10
|
||||
msg.Performer = "TEST"
|
||||
|
@ -242,7 +254,7 @@ func TestSendWithNewAudio(t *testing.T) {
|
|||
func TestSendWithExistingAudio(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewAudioShare(ChatID, ExistingAudioFileID)
|
||||
msg := NewAudio(ChatID, FileID(ExistingAudioFileID))
|
||||
msg.Title = "TEST"
|
||||
msg.Duration = 10
|
||||
msg.Performer = "TEST"
|
||||
|
@ -257,7 +269,7 @@ func TestSendWithExistingAudio(t *testing.T) {
|
|||
func TestSendWithNewVoice(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewVoiceUpload(ChatID, "tests/voice.ogg")
|
||||
msg := NewVoice(ChatID, "tests/voice.ogg")
|
||||
msg.Duration = 10
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -269,7 +281,7 @@ func TestSendWithNewVoice(t *testing.T) {
|
|||
func TestSendWithExistingVoice(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewVoiceShare(ChatID, ExistingVoiceFileID)
|
||||
msg := NewVoice(ChatID, FileID(ExistingVoiceFileID))
|
||||
msg.Duration = 10
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -311,7 +323,7 @@ func TestSendWithVenue(t *testing.T) {
|
|||
func TestSendWithNewVideo(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewVideoUpload(ChatID, "tests/video.mp4")
|
||||
msg := NewVideo(ChatID, "tests/video.mp4")
|
||||
msg.Duration = 10
|
||||
msg.Caption = "TEST"
|
||||
|
||||
|
@ -325,7 +337,7 @@ func TestSendWithNewVideo(t *testing.T) {
|
|||
func TestSendWithExistingVideo(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewVideoShare(ChatID, ExistingVideoFileID)
|
||||
msg := NewVideo(ChatID, FileID(ExistingVideoFileID))
|
||||
msg.Duration = 10
|
||||
msg.Caption = "TEST"
|
||||
|
||||
|
@ -339,7 +351,7 @@ func TestSendWithExistingVideo(t *testing.T) {
|
|||
func TestSendWithNewVideoNote(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewVideoNoteUpload(ChatID, 240, "tests/videonote.mp4")
|
||||
msg := NewVideoNote(ChatID, 240, "tests/videonote.mp4")
|
||||
msg.Duration = 10
|
||||
|
||||
_, err := bot.Send(msg)
|
||||
|
@ -352,7 +364,7 @@ func TestSendWithNewVideoNote(t *testing.T) {
|
|||
func TestSendWithExistingVideoNote(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewVideoNoteShare(ChatID, 240, ExistingVideoNoteFileID)
|
||||
msg := NewVideoNote(ChatID, 240, FileID(ExistingVideoNoteFileID))
|
||||
msg.Duration = 10
|
||||
|
||||
_, err := bot.Send(msg)
|
||||
|
@ -365,7 +377,7 @@ func TestSendWithExistingVideoNote(t *testing.T) {
|
|||
func TestSendWithNewSticker(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewStickerUpload(ChatID, "tests/image.jpg")
|
||||
msg := NewSticker(ChatID, "tests/image.jpg")
|
||||
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -377,7 +389,7 @@ func TestSendWithNewSticker(t *testing.T) {
|
|||
func TestSendWithExistingSticker(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewStickerShare(ChatID, ExistingStickerFileID)
|
||||
msg := NewSticker(ChatID, FileID(ExistingStickerFileID))
|
||||
|
||||
_, err := bot.Send(msg)
|
||||
|
||||
|
@ -389,7 +401,7 @@ func TestSendWithExistingSticker(t *testing.T) {
|
|||
func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewStickerUpload(ChatID, "tests/image.jpg")
|
||||
msg := NewSticker(ChatID, "tests/image.jpg")
|
||||
msg.ReplyMarkup = ReplyKeyboardRemove{
|
||||
RemoveKeyboard: true,
|
||||
Selective: false,
|
||||
|
@ -404,7 +416,7 @@ func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
|
|||
func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
msg := NewStickerShare(ChatID, ExistingStickerFileID)
|
||||
msg := NewSticker(ChatID, FileID(ExistingStickerFileID))
|
||||
msg.ReplyMarkup = ReplyKeyboardRemove{
|
||||
RemoveKeyboard: true,
|
||||
Selective: false,
|
||||
|
@ -526,9 +538,9 @@ func TestSendWithMediaGroup(t *testing.T) {
|
|||
bot, _ := getBot(t)
|
||||
|
||||
cfg := NewMediaGroup(ChatID, []interface{}{
|
||||
NewInputMediaPhoto("https://i.imgur.com/unQLJIb.jpg"),
|
||||
NewInputMediaPhoto("https://i.imgur.com/J5qweNZ.jpg"),
|
||||
NewInputMediaVideo("https://i.imgur.com/F6RmI24.mp4"),
|
||||
NewInputMediaPhoto(FileURL("https://i.imgur.com/unQLJIb.jpg")),
|
||||
NewInputMediaPhoto("tests/image.jpg"),
|
||||
NewInputMediaVideo("tests/video.mp4"),
|
||||
})
|
||||
|
||||
messages, err := bot.SendMediaGroup(cfg)
|
||||
|
@ -537,11 +549,11 @@ func TestSendWithMediaGroup(t *testing.T) {
|
|||
}
|
||||
|
||||
if messages == nil {
|
||||
t.Error()
|
||||
t.Error("No received messages")
|
||||
}
|
||||
|
||||
if len(messages) != 3 {
|
||||
t.Error()
|
||||
if len(messages) != len(cfg.Media) {
|
||||
t.Errorf("Different number of messages: %d", len(messages))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue