Files
worker/app/models/group_test.go
Gleb Tv 2c7a0236da feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
2026-07-13 17:55:14 +03:00

59 строки
1.4 KiB
Go

package models_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"rsgit.ru/rsmon/rsmon/app/models"
)
// TestSystemGroups verifies that SystemGroups returns only groups with
// is_system=true and ignores groups with is_system=false or nil.
func TestSystemGroups(t *testing.T) {
models.Drop()
models.Migrate()
account := &models.Account{Name: "test-account"}
require.NoError(t, models.DB().Create(account).Error)
trueVal, falseVal := true, false
systemGroup := &models.Group{
AccountID: account.ID,
Name: "system-internal",
IsSystem: &trueVal,
}
regularGroup := &models.Group{
AccountID: account.ID,
Name: "regular",
IsSystem: &falseVal,
}
nilSystemGroup := &models.Group{
AccountID: account.ID,
Name: "nil-system",
}
require.NoError(t, models.DB().Create(systemGroup).Error)
require.NoError(t, models.DB().Create(regularGroup).Error)
require.NoError(t, models.DB().Create(nilSystemGroup).Error)
got, err := models.SystemGroups()
require.NoError(t, err)
var ids []int64
var names []string
for _, g := range got {
ids = append(ids, g.ID)
names = append(names, g.Name)
}
assert.Contains(t, names, "system-internal")
assert.NotContains(t, names, "regular")
assert.NotContains(t, names, "nil-system")
assert.Contains(t, ids, systemGroup.ID)
assert.NotContains(t, ids, regularGroup.ID)
assert.NotContains(t, ids, nilSystemGroup.ID)
}