Files
notify/telegram_test.go
2025-11-29 14:45:32 +03:00

66 lines
1.4 KiB
Go

package notify_test
import (
"os"
"testing"
"git.gm6.ru/icewind/notify"
"gopkg.in/yaml.v2"
)
type ConfigTelegram struct {
GroupID int64 `yaml:"group_id"`
Token string `yaml:"token"`
}
func loadConfig(t *testing.T) (conf ConfigTelegram) {
cData, err := os.ReadFile("test_data/telegram.yaml")
if err != nil {
t.Fatal(err)
}
if err = yaml.Unmarshal(cData, &conf); err != nil {
t.Fatal(err)
}
return
}
func TestMessage(t *testing.T) {
conf := loadConfig(t)
bot, err := notify.NewTelegram(conf.Token, true)
if err != nil {
t.Fatal(err)
}
m, err := bot.SendTextMessage(conf.GroupID, "Привет ))")
if err != nil {
t.Fatal(err)
}
t.Log(m)
}
func TestSendTable(t *testing.T) {
rows := [][]string{
{"Название", "Цена", "Кол-во", "Рост"},
{"Яблоки", "120", "5", "3.5"},
{"Бананы", "-90", "30", "12 000"},
{"Киви", "+200", "1", "-1.2"},
{"Груши", "100", "10", "0.5"},
{"Апельсины", "150", "10", "1.5"},
{"Мандарины", "100", "10", "0.5"},
{"Персики", "100", "10", "0.5"},
{"Виноград", "100", "10", "0.5"},
{"Абрикосы", "100", "10", "0.5"},
{"Слива Абрикосы Абрикосы", "100", "10", "0.5"},
}
msg := notify.BuildTelegramTable(rows)
conf := loadConfig(t)
bot, err := notify.NewTelegram(conf.Token, true)
m, err := bot.SendHTMLMessage(conf.GroupID, "<pre>"+msg+"</pre>")
if err != nil {
t.Fatal(err)
}
t.Log(m)
}