Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
55 строки
1.4 KiB
Go
55 строки
1.4 KiB
Go
package notify
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"rocketgit.ru/rsmon/worker/app/models"
|
|
)
|
|
|
|
func TestEmail_NilCred(t *testing.T) {
|
|
if err := Email(nil, "to@x.com", "s", "b", ""); err == nil {
|
|
t.Fatal("expected error for nil cred")
|
|
}
|
|
}
|
|
|
|
func TestEmail_WrongKind(t *testing.T) {
|
|
cred := &models.NotificationCredential{Kind: models.CredentialKindTelegram}
|
|
if err := Email(cred, "to@x.com", "s", "b", ""); err == nil {
|
|
t.Fatal("expected error for wrong kind")
|
|
}
|
|
}
|
|
|
|
func TestEmail_MissingRequiredFields(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
cred *models.NotificationCredential
|
|
}{
|
|
{"nil server", &models.NotificationCredential{Kind: models.CredentialKindSMTP}},
|
|
{"nil port", &models.NotificationCredential{
|
|
Kind: models.CredentialKindSMTP,
|
|
Server: strPtr("smtp.x.com"),
|
|
}},
|
|
{"nil login", &models.NotificationCredential{
|
|
Kind: models.CredentialKindSMTP,
|
|
Server: strPtr("smtp.x.com"),
|
|
Port: intPtr(587),
|
|
}},
|
|
{"nil fromaddr", &models.NotificationCredential{
|
|
Kind: models.CredentialKindSMTP,
|
|
Server: strPtr("smtp.x.com"),
|
|
Port: intPtr(587),
|
|
Login: strPtr("u"),
|
|
}},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if err := Email(tc.cred, "to@x.com", "s", "b", ""); err == nil {
|
|
t.Fatalf("expected error for %s", tc.name)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func strPtr(s string) *string { return &s }
|
|
func intPtr(i int) *int { return &i }
|