forked from tucnak/telebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelebot_test.go
71 lines (57 loc) · 1.4 KB
/
telebot_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package telebot
import (
"fmt"
"os"
"testing"
)
func TestBot(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
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.")
}
_, err := NewBot(token)
if err != nil {
t.Fatal("Couldn't create bot:", err)
}
}
func TestRecipient(_ *testing.T) {
bot := Bot{}
bot.SendMessage(User{}, "", nil)
bot.SendMessage(Chat{}, "", nil)
}
func TestFile(t *testing.T) {
file, err := NewFile("telebot.go")
if err != nil {
t.Fatal(err)
}
if file.Exists() {
t.Fatal("Newly created file can't exist on Telegram servers!")
}
file.FileID = "magic"
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"}
// According to API, chat object with group Type is a group chat.
if !user.IsGroupChat() {
t.Fatal("Can't tell private and group chats apart!")
}
// Reverse.
user.Title = ""
user.Type = "private"
if user.IsGroupChat() {
t.Fatal("Can't tell private and group chats apart!")
}
}