Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
59 строки
1.4 KiB
Go
59 строки
1.4 KiB
Go
package models_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"rocketgit.ru/rsmon/worker/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)
|
|
}
|