Chore: Replace sqlstore with db interface (#85366)

* replace sqlstore with db interface in a few packages

* remove from stats

* remove sqlstore in admin test

* remove sqlstore from api plugin tests

* fix another createUser

* remove sqlstore in publicdashboards

* remove sqlstore from orgs

* clean up orguser test

* more clean up in sso

* clean up service accounts

* further cleanup

* more cleanup in accesscontrol

* last cleanup in accesscontrol

* clean up teams

* more removals

* split cfg from db in testenv

* few remaining fixes

* fix test with bus

* pass cfg for testing inside db as an option

* set query retries when no opts provided

* revert golden test data

* rebase and rollback
This commit is contained in:
Serge Zaitsev
2024-04-04 15:04:47 +02:00
committed by GitHub
parent c41b0a71cf
commit faa1244518
69 changed files with 507 additions and 465 deletions
+17 -13
View File
@@ -9,14 +9,15 @@ import (
"github.com/go-openapi/runtime"
"github.com/grafana/grafana-openapi-client-go/client/folders"
"github.com/grafana/grafana-openapi-client-go/models"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/org/orgimpl"
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/services/user/userimpl"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tests"
"github.com/grafana/grafana/pkg/tests/testinfra"
"github.com/stretchr/testify/assert"
@@ -35,9 +36,10 @@ func TestIntegrationUpdateFolder(t *testing.T) {
EnableQuota: true,
})
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
store, cfg := env.SQLStore, env.Cfg
// Create user
createUser(t, store, user.CreateUserCommand{
createUser(t, store, cfg, user.CreateUserCommand{
DefaultOrgRole: string(org.RoleAdmin),
Password: "admin",
Login: "admin",
@@ -71,9 +73,10 @@ func TestIntegrationCreateFolder(t *testing.T) {
EnableQuota: true,
})
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
store, cfg := env.SQLStore, env.Cfg
// Create user
createUser(t, store, user.CreateUserCommand{
createUser(t, store, cfg, user.CreateUserCommand{
DefaultOrgRole: string(org.RoleAdmin),
Password: "admin",
Login: "admin",
@@ -111,9 +114,10 @@ func TestIntegrationNestedFoldersOn(t *testing.T) {
EnableFeatureToggles: []string{featuremgmt.FlagNestedFolders},
})
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
store, cfg := env.SQLStore, env.Cfg
// Create user
createUser(t, store, user.CreateUserCommand{
createUser(t, store, cfg, user.CreateUserCommand{
DefaultOrgRole: string(org.RoleAdmin),
Password: "admin",
Login: "admin",
@@ -202,16 +206,16 @@ func TestIntegrationNestedFoldersOn(t *testing.T) {
})
}
func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) int64 {
func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 {
t.Helper()
store.Cfg.AutoAssignOrg = true
store.Cfg.AutoAssignOrgId = orgID
cfg.AutoAssignOrg = true
cfg.AutoAssignOrgId = orgID
quotaService := quotaimpl.ProvideService(store, store.Cfg)
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
quotaService := quotaimpl.ProvideService(db, cfg)
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
require.NoError(t, err)
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
usrSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
require.NoError(t, err)
u, err := usrSvc.Create(context.Background(), &cmd)