2015-06-25 19:32:41 +00:00
|
|
|
package telebot
|
|
|
|
|
2015-06-26 07:34:10 +00:00
|
|
|
import (
|
2015-06-27 11:30:35 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2015-06-26 07:34:10 +00:00
|
|
|
"testing"
|
|
|
|
)
|
2015-06-25 19:32:41 +00:00
|
|
|
|
2015-07-06 16:58:54 +00:00
|
|
|
func TestBot(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping test in short mode.")
|
|
|
|
}
|
|
|
|
|
2015-06-27 11:30:35 +00:00
|
|
|
token := os.Getenv("TELEBOT_SECRET")
|
|
|
|
if token == "" {
|
|
|
|
fmt.Println("ERROR: " +
|
|
|
|
"In order to test telebot functionality, you need to set up " +
|
|
|
|
"TELEBOT_SECRET environmental variable, which represents an API " +
|
|
|
|
"key to a Telegram bot.\n")
|
|
|
|
t.Fatal("Could't find TELEBOT_SECRET, aborting.")
|
2015-06-26 07:34:10 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 02:28:39 +00:00
|
|
|
_, err := NewBot(Settings{Token: token})
|
2015-07-06 16:58:54 +00:00
|
|
|
if err != nil {
|
2017-08-15 13:44:01 +00:00
|
|
|
t.Fatal("couldn't create bot:", err)
|
2015-07-06 16:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 13:42:18 +00:00
|
|
|
func TestRecipient(t *testing.T) {
|
|
|
|
token := os.Getenv("TELEBOT_SECRET")
|
|
|
|
if token == "" {
|
|
|
|
fmt.Println("ERROR: " +
|
|
|
|
"In order to test telebot functionality, you need to set up " +
|
|
|
|
"TELEBOT_SECRET environmental variable, which represents an API " +
|
|
|
|
"key to a Telegram bot.\n")
|
|
|
|
t.Fatal("Could't find TELEBOT_SECRET, aborting.")
|
|
|
|
}
|
|
|
|
|
|
|
|
bot, err := NewBot(Settings{Token: token})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("couldn't create bot:", err)
|
|
|
|
}
|
|
|
|
|
2017-11-17 06:32:51 +00:00
|
|
|
bot.Send(&User{}, "")
|
|
|
|
bot.Send(&Chat{}, "")
|
2015-10-16 22:36:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-06 16:58:54 +00:00
|
|
|
func TestFile(t *testing.T) {
|
2017-11-19 01:44:31 +00:00
|
|
|
file := FromDisk("telebot.go")
|
2015-06-26 07:34:10 +00:00
|
|
|
|
2017-11-19 01:44:31 +00:00
|
|
|
if file.InCloud() {
|
2015-07-06 16:58:54 +00:00
|
|
|
t.Fatal("Newly created file can't exist on Telegram servers!")
|
|
|
|
}
|
2015-06-27 15:44:12 +00:00
|
|
|
|
2015-07-06 16:58:54 +00:00
|
|
|
file.FileID = "magic"
|
2015-06-27 10:30:25 +00:00
|
|
|
|
2017-11-19 01:44:31 +00:00
|
|
|
if file.FileLocal != "telebot.go" {
|
2015-07-06 16:58:54 +00:00
|
|
|
t.Fatal("File doesn't preserve its original filename.")
|
|
|
|
}
|
|
|
|
}
|
2018-12-12 22:45:03 +00:00
|
|
|
|
|
|
|
func TestCustomURL(t *testing.T) {
|
|
|
|
token := os.Getenv("TELEBOT_SECRET")
|
|
|
|
if token == "" {
|
|
|
|
fmt.Println("ERROR: " +
|
|
|
|
"In order to test telebot functionality, you need to set up " +
|
|
|
|
"TELEBOT_SECRET environmental variable, which represents an API " +
|
|
|
|
"key to a Telegram bot.\n")
|
|
|
|
t.Fatal("Could't find TELEBOT_SECRET, aborting.")
|
|
|
|
}
|
|
|
|
|
|
|
|
customURL := "http://api.telegram.org"
|
|
|
|
|
|
|
|
bot, err := NewBot(Settings{Token: token, URL: customURL})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("couldn't create bot:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if bot.URL != customURL {
|
|
|
|
t.Fatal("custom api url is not set")
|
|
|
|
}
|
|
|
|
}
|