Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
54 строки
1.5 KiB
Go
54 строки
1.5 KiB
Go
package notify
|
|
|
|
import (
|
|
"testing"
|
|
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
|
|
"rocketgit.ru/rsmon/worker/app/models"
|
|
)
|
|
|
|
func TestTelegram_NilCred(t *testing.T) {
|
|
if err := Telegram(nil, 123, "x"); err == nil {
|
|
t.Fatal("expected error for nil cred")
|
|
}
|
|
}
|
|
|
|
func TestTelegram_WrongKind(t *testing.T) {
|
|
cred := &models.NotificationCredential{Kind: models.CredentialKindSMTP}
|
|
if err := Telegram(cred, 123, "x"); err == nil {
|
|
t.Fatal("expected error for wrong kind")
|
|
}
|
|
}
|
|
|
|
func TestTelegram_EmptyToken(t *testing.T) {
|
|
enabled := true
|
|
cred := &models.NotificationCredential{
|
|
Kind: models.CredentialKindTelegram,
|
|
Enabled: &enabled,
|
|
}
|
|
if err := Telegram(cred, 123, "x"); err == nil {
|
|
t.Fatal("expected error for empty token")
|
|
}
|
|
}
|
|
|
|
func TestTelegramEndpoint_Default(t *testing.T) {
|
|
if got := telegramEndpoint(""); got != tgbotapi.APIEndpoint {
|
|
t.Fatalf("expected default endpoint %q, got %q", tgbotapi.APIEndpoint, got)
|
|
}
|
|
}
|
|
|
|
func TestTelegramEndpoint_CustomURL(t *testing.T) {
|
|
cases := []struct{ in, want string }{
|
|
{"https://api.telegram.org", "https://api.telegram.org/bot%s/%s"},
|
|
{"https://api.telegram.org/", "https://api.telegram.org/bot%s/%s"},
|
|
{"https://user:pass@deploy.rscz.ru/", "https://user:pass@deploy.rscz.ru/bot%s/%s"},
|
|
{"https://deploy.rscz.ru", "https://deploy.rscz.ru/bot%s/%s"},
|
|
}
|
|
for _, tc := range cases {
|
|
if got := telegramEndpoint(tc.in); got != tc.want {
|
|
t.Errorf("telegramEndpoint(%q) = %q; want %q", tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|