feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
65
app/models/contact_test.go
Обычный файл
65
app/models/contact_test.go
Обычный файл
@@ -0,0 +1,65 @@
|
||||
package models_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/app/models"
|
||||
)
|
||||
|
||||
// TestSystemContacts verifies that SystemContacts returns only contacts with
|
||||
// is_system=true and ignores contacts with is_system=false or nil.
|
||||
func TestSystemContacts(t *testing.T) {
|
||||
models.Drop()
|
||||
models.Migrate()
|
||||
|
||||
account := &models.Account{Name: "test-account"}
|
||||
require.NoError(t, models.DB().Create(account).Error)
|
||||
accountID := account.ID
|
||||
|
||||
trueVal, falseVal := true, false
|
||||
|
||||
systemContact := &models.Contact{
|
||||
AccountID: &accountID,
|
||||
Name: "system-admin",
|
||||
Kind: "email",
|
||||
Value: "ops@example.com",
|
||||
IsSystem: &trueVal,
|
||||
}
|
||||
regularContact := &models.Contact{
|
||||
AccountID: &accountID,
|
||||
Name: "regular",
|
||||
Kind: "email",
|
||||
Value: "user@example.com",
|
||||
IsSystem: &falseVal,
|
||||
}
|
||||
nilSystemContact := &models.Contact{
|
||||
AccountID: &accountID,
|
||||
Name: "nil-system",
|
||||
Kind: "email",
|
||||
Value: "nil@example.com",
|
||||
}
|
||||
|
||||
require.NoError(t, models.DB().Create(systemContact).Error)
|
||||
require.NoError(t, models.DB().Create(regularContact).Error)
|
||||
require.NoError(t, models.DB().Create(nilSystemContact).Error)
|
||||
|
||||
got, err := models.SystemContacts()
|
||||
require.NoError(t, err)
|
||||
|
||||
var ids []int64
|
||||
var names []string
|
||||
for _, c := range got {
|
||||
ids = append(ids, c.ID)
|
||||
names = append(names, c.Name)
|
||||
}
|
||||
|
||||
assert.Contains(t, names, "system-admin")
|
||||
assert.NotContains(t, names, "regular")
|
||||
assert.NotContains(t, names, "nil-system")
|
||||
assert.Contains(t, ids, systemContact.ID)
|
||||
assert.NotContains(t, ids, regularContact.ID)
|
||||
assert.NotContains(t, ids, nilSystemContact.ID)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user