Optimize tokens count from service accounts query (#96663)
* optimize tokens count from service accounts query * add unit tests for tokens count * skip broken test * fix lint error * rename Tokens to TokenCount
This commit is contained in:
@@ -107,9 +107,18 @@ func SetupApiKey(t *testing.T, store db.DB, cfg *setting.Cfg, testKey TestApiKey
|
||||
return key
|
||||
}
|
||||
|
||||
func SetupApiKeys(t *testing.T, store db.DB, cfg *setting.Cfg, testKeys []TestApiKey) []*apikey.APIKey {
|
||||
result := make([]*apikey.APIKey, len(testKeys))
|
||||
for i, testKey := range testKeys {
|
||||
result[i] = SetupApiKey(t, store, cfg, testKey)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// SetupUsersServiceAccounts creates in "test org" all users or service accounts passed in parameter
|
||||
// To achieve this, it sets the AutoAssignOrg and AutoAssignOrgId settings.
|
||||
func SetupUsersServiceAccounts(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, testUsers []TestUser) (orgID int64) {
|
||||
func SetupUsersServiceAccounts(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, testUsers []TestUser) (users []user.User, orgID int64) {
|
||||
role := string(org.RoleNone)
|
||||
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
@@ -129,8 +138,9 @@ func SetupUsersServiceAccounts(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, t
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = int(org.ID)
|
||||
|
||||
users = make([]user.User, len(testUsers))
|
||||
for i := range testUsers {
|
||||
_, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||
newUser, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||
Login: testUsers[i].Login,
|
||||
IsServiceAccount: testUsers[i].IsServiceAccount,
|
||||
DefaultOrgRole: role,
|
||||
@@ -138,6 +148,8 @@ func SetupUsersServiceAccounts(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, t
|
||||
OrgID: org.ID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
users[i] = *newUser
|
||||
}
|
||||
return org.ID
|
||||
return users, org.ID
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user