-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify_test.go
81 lines (66 loc) · 2.24 KB
/
notify_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
72
73
74
75
76
77
78
79
80
81
package notify
import (
"os"
"testing"
"time"
)
// TestSendEditDeleteDiscord tests the Send, Edit, and Delete functions for Discord.
func TestSendEditDeleteDiscord(t *testing.T) {
discordID, ok := os.LookupEnv("DISCORD_ID")
if !ok {
t.Error("Discord webhook ID must be set in the environment variable 'DISCORD_ID'")
}
discordToken, ok := os.LookupEnv("DISCORD_TOKEN")
if !ok {
t.Error("Discord webhook token must be set in the environment variable 'DISCORD_TOKEN'")
}
msg := "This is a **bold**, _italic_, [inline URL](http://www.example.com/), `code`."
discordClient := NewDiscord(discordID, discordToken)
// Send messages
id, err := discordClient.Send(msg)
if err != nil {
t.Errorf("Failed to send Discord message: %v", err)
}
// Wait for messages to be sent
time.Sleep(3 * time.Second)
// Edit messages
if err := discordClient.Edit(id, "Redacted Discord Message"); err != nil {
t.Errorf("Failed to edit Discord message: %v", err)
}
// Wait for messages to be edited
time.Sleep(3 * time.Second)
// Delete messages
if err := discordClient.Delete(id); err != nil {
t.Errorf("Failed to delete Discord message: %v", err)
}
}
// TestSendEditDeleteTelegram tests the Send, Edit, and Delete functions for Telegram.
func TestSendEditDeleteTelegram(t *testing.T) {
telegramID, ok := os.LookupEnv("TELEGRAM_ID")
if !ok {
t.Error("Telegram chat ID must be set in the environment variable 'TELEGRAM_ID'")
}
telegramToken, ok := os.LookupEnv("TELEGRAM_TOKEN")
if !ok {
t.Error("Telegram bot token must be set in the environment variable 'TELEGRAM_TOKEN'")
}
msg := "This is a **bold**, _italic_, [inline URL](http://www.example.com/), `code`."
telegramClient := NewTelegram(telegramID, telegramToken)
// Send messages
id, err := telegramClient.Send(msg)
if err != nil {
t.Errorf("Failed to send Telegram message: %v", err)
}
// Wait for messages to be sent
time.Sleep(3 * time.Second)
// Edit messages
if err := telegramClient.Edit(id, "Redacted Telegram Message"); err != nil {
t.Errorf("Failed to edit Telegram message: %v", err)
}
// Wait for messages to be edited
time.Sleep(3 * time.Second)
// Delete messages
if err := telegramClient.Delete(id); err != nil {
t.Errorf("Failed to delete Telegram message: %v", err)
}
}