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
|
|
|
}
|
|
|
|
|
2015-07-03 18:54:40 +00:00
|
|
|
_, err := NewBot(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-16 22:36:07 +00:00
|
|
|
func TestRecipient(_ *testing.T) {
|
2017-08-11 02:30:17 +00:00
|
|
|
bot := Bot{}
|
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) {
|
|
|
|
file, err := NewFile("telebot.go")
|
2015-06-26 07:34:10 +00:00
|
|
|
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-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
|
|
|
|
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.")
|
|
|
|
}
|
|
|
|
}
|
2015-06-27 10:30:25 +00:00
|
|
|
|
2015-10-16 16:36:20 +00:00
|
|
|
func TestChat(t *testing.T) {
|
|
|
|
user := Chat{Type: "group", Title: "bazinga"}
|
2015-06-27 11:30:35 +00:00
|
|
|
|
2015-10-16 16:36:20 +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() {
|
2015-10-16 16:36:20 +00:00
|
|
|
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 = ""
|
2015-10-16 16:36:20 +00:00
|
|
|
user.Type = "private"
|
|
|
|
|
2015-07-06 16:58:54 +00:00
|
|
|
if user.IsGroupChat() {
|
2015-10-16 16:36:20 +00:00
|
|
|
t.Fatal("Can't tell private and group chats apart!")
|
2015-07-06 16:58:54 +00:00
|
|
|
}
|
2015-06-26 07:34:10 +00:00
|
|
|
}
|