telebot/telebot_test.go

83 lines
1.9 KiB
Go
Raw Normal View History

2015-06-25 19:32:41 +00:00
package telebot
import (
2015-06-27 11:30:35 +00:00
"fmt"
"os"
"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.")
}
2017-11-21 02:28:39 +00:00
_, err := NewBot(Settings{Token: token})
2015-07-06 16:58:54 +00:00
if err != nil {
t.Fatal("couldn't create bot:", err)
2015-07-06 16:58:54 +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)
}
bot.Send(&User{}, "")
bot.Send(&Chat{}, "")
}
2015-07-06 16:58:54 +00:00
func TestFile(t *testing.T) {
file := FromDisk("telebot.go")
if file.InCloud() {
2015-07-06 16:58:54 +00:00
t.Fatal("Newly created file can't exist on Telegram servers!")
}
2015-07-06 16:58:54 +00:00
file.FileID = "magic"
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")
}
}