telebot/telebot_test.go

72 lines
1.4 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.")
}
2015-07-03 18:54:40 +00:00
_, err := NewBot(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(_ *testing.T) {
bot := Bot{}
bot.SendMessage(User{}, "", nil)
bot.SendMessage(Chat{}, "", nil)
}
2015-07-06 16:58:54 +00:00
func TestFile(t *testing.T) {
file, err := NewFile("telebot.go")
if err != nil {
t.Fatal(err)
}
2015-07-06 16:58:54 +00:00
if file.Exists() {
t.Fatal("Newly created file can't exist on Telegram servers!")
}
2015-07-06 16:58:54 +00:00
file.FileID = "magic"
2015-07-06 16:58:54 +00:00
if !file.Exists() {
t.Fatal("File with defined FileID is supposed to exist, fail.")
}
if file.Local() != "telebot.go" {
t.Fatal("File doesn't preserve its original filename.")
}
}
func TestChat(t *testing.T) {
user := Chat{Type: "group", Title: "bazinga"}
2015-06-27 11:30:35 +00:00
// According to API, chat object with group Type is a group chat.
2015-07-06 16:58:54 +00:00
if !user.IsGroupChat() {
t.Fatal("Can't tell private and group chats apart!")
2015-07-06 16:58:54 +00:00
}
2015-06-27 11:30:35 +00:00
2015-07-06 16:58:54 +00:00
// Reverse.
user.Title = ""
user.Type = "private"
2015-07-06 16:58:54 +00:00
if user.IsGroupChat() {
t.Fatal("Can't tell private and group chats apart!")
2015-07-06 16:58:54 +00:00
}
}