Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
54 строки
1.4 KiB
Go
54 строки
1.4 KiB
Go
package factories
|
|
|
|
import (
|
|
"github.com/icrowley/fake"
|
|
|
|
"rocketgit.ru/rsmon/worker/app/models"
|
|
)
|
|
|
|
// NotificationFactory provides functionality.
|
|
func NotificationFactory(account *models.Account, contactIDs, groupIDs []int64, alertDelay int64, notifyRestore bool) models.Notification {
|
|
BeforeExpiration := int64(3600)
|
|
notification := models.Notification{
|
|
Name: fake.Company(),
|
|
ContactIDs: contactIDs,
|
|
GroupIDs: groupIDs,
|
|
AlertDelay: &alertDelay,
|
|
NotifyDown: true,
|
|
NotifyRestore: notifyRestore,
|
|
BeforeExpiration: &BeforeExpiration,
|
|
}
|
|
if account == nil {
|
|
c := AccountFactory()
|
|
account = &c
|
|
}
|
|
notification.Account = account
|
|
notification.AccountID = account.ID
|
|
|
|
return notification
|
|
}
|
|
|
|
// PersistedNotification provides functionality.
|
|
func PersistedNotification(account *models.Account, contactIDs, groupIDs []int64, alertDelay int64, notifyRestore bool) models.Notification { //nolint:lll
|
|
notification := NotificationFactory(account, contactIDs, groupIDs, alertDelay, notifyRestore)
|
|
|
|
if notification.Account.ID == 0 {
|
|
err := models.DB().Save(¬ification.Account).Error
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
notification.AccountID = notification.Account.ID
|
|
}
|
|
err := models.DB().Save(¬ification).Error
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
err = notification.PersistRelations()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return notification
|
|
}
|