-
Notifications
You must be signed in to change notification settings - Fork 0
/
pingalert_test.go
43 lines (40 loc) · 1.2 KB
/
pingalert_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
package main
import (
"fmt"
"os"
"strconv"
"testing"
"github.com/asendia/salmonping/db"
"github.com/joho/godotenv"
)
func TestCreateTextMessage(t *testing.T) {
godotenv.Load()
botToken := os.Getenv("TELEGRAM_BOT_TOKEN")
if botToken == "" {
fmt.Printf("TELEGRAM_BOT_TOKEN is empty, optional and skipped")
return
}
chatID, err := strconv.ParseInt(os.Getenv("TELEGRAM_CHAT_ID"), 10, 64)
if err != nil {
t.Errorf("Error parsing TELEGRAM_CHAT_ID")
return
}
anomalies := []db.SelectOnlineListingPingsRow{
{Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{Status: "unknown", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{Status: "closed", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
}
text := createTextMessage(anomalies)
err = sendTelegramMessage(botToken, chatID, text)
if err != nil {
panic(err)
}
anomaly := []db.SelectOnlineListingPingsRow{
{Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
}
text = createTextMessage(anomaly)
err = sendTelegramMessage(botToken, chatID, text)
if err != nil {
panic(err)
}
}