diff --git a/pkg/api/org_users_test.go b/pkg/api/org_users_test.go index ea5f4930661..3c4caa64ecc 100644 --- a/pkg/api/org_users_test.go +++ b/pkg/api/org_users_test.go @@ -41,7 +41,7 @@ func setUpGetOrgUsersDB(t *testing.T, sqlStore db.DB, cfg *setting.Cfg) { cfg.AutoAssignOrg = true cfg.AutoAssignOrgId = int(testOrgID) - quotaService := quotaimpl.ProvideService(sqlStore, cfg) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(sqlStore), cfg) orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( diff --git a/pkg/cmd/grafana-cli/commands/conflict_user_command.go b/pkg/cmd/grafana-cli/commands/conflict_user_command.go index 9d7a534232b..1839dc7013f 100644 --- a/pkg/cmd/grafana-cli/commands/conflict_user_command.go +++ b/pkg/cmd/grafana-cli/commands/conflict_user_command.go @@ -79,7 +79,7 @@ func initializeConflictResolver(cmd *utils.ContextCommandLine, f Formatter, ctx if err != nil { return nil, fmt.Errorf("%v: %w", "failed to get users with conflicting logins", err) } - quotaService := quotaimpl.ProvideService(s, cfg) + quotaService := quotaimpl.ProvideService(replstore, cfg) userService, err := userimpl.ProvideService(s, nil, cfg, nil, nil, tracer, quotaService, supportbundlestest.NewFakeBundleService()) if err != nil { return nil, fmt.Errorf("%v: %w", "failed to get user service", err) diff --git a/pkg/infra/db/dbrepl.go b/pkg/infra/db/dbrepl.go index a8d8e23d676..028989b44ec 100644 --- a/pkg/infra/db/dbrepl.go +++ b/pkg/infra/db/dbrepl.go @@ -11,3 +11,9 @@ type ReplDB interface { // ReadReplica is the read-only database connection. If no read replica is configured, the implementation must return the primary DB. ReadReplica() *sqlstore.SQLStore } + +// FakeREplDBFromDBForTests returns a ReplDB that uses the given DB as the primary connection. It's a helper function for tests. +func FakeReplDBFromDB(primary DB) ReplDB { + ss := primary.(*sqlstore.SQLStore) + return sqlstore.FakeReplStoreFromStore(ss) +} diff --git a/pkg/services/org/orgimpl/store_test.go b/pkg/services/org/orgimpl/store_test.go index a4f839d6842..72288d14c26 100644 --- a/pkg/services/org/orgimpl/store_test.go +++ b/pkg/services/org/orgimpl/store_test.go @@ -906,7 +906,7 @@ func TestIntegration_SQLStore_RemoveOrgUser(t *testing.T) { func createOrgAndUserSvc(t *testing.T, store db.DB, cfg *setting.Cfg) (org.Service, user.Service) { t.Helper() - quotaService := quotaimpl.ProvideService(store, cfg) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) orgService, err := ProvideService(store, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( diff --git a/pkg/services/quota/quotaimpl/quota.go b/pkg/services/quota/quotaimpl/quota.go index b894f6ec97f..16a4f16a949 100644 --- a/pkg/services/quota/quotaimpl/quota.go +++ b/pkg/services/quota/quotaimpl/quota.go @@ -53,7 +53,7 @@ type service struct { targetToSrv *quota.TargetToSrv } -func ProvideService(db db.DB, cfg *setting.Cfg) quota.Service { +func ProvideService(db db.ReplDB, cfg *setting.Cfg) quota.Service { logger := log.New("quota_service") s := service{ store: &sqlStore{db: db, logger: logger}, diff --git a/pkg/services/quota/quotaimpl/store.go b/pkg/services/quota/quotaimpl/store.go index 78bc38fe4d9..743e4f20275 100644 --- a/pkg/services/quota/quotaimpl/store.go +++ b/pkg/services/quota/quotaimpl/store.go @@ -16,12 +16,12 @@ type store interface { } type sqlStore struct { - db db.DB + db db.ReplDB logger log.Logger } func (ss *sqlStore) DeleteByUser(ctx quota.Context, userID int64) error { - return ss.db.WithDbSession(ctx, func(sess *db.Session) error { + return ss.db.DB().WithDbSession(ctx, func(sess *db.Session) error { var rawSQL = "DELETE FROM quota WHERE user_id = ?" _, err := sess.Exec(rawSQL, userID) return err @@ -54,7 +54,7 @@ func (ss *sqlStore) Get(ctx quota.Context, scopeParams *quota.ScopeParameters) ( } func (ss *sqlStore) Update(ctx quota.Context, cmd *quota.UpdateQuotaCmd) error { - return ss.db.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error { + return ss.db.DB().WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error { // Check if quota is already defined in the DB quota := quota.Quota{ Target: cmd.Target, @@ -87,7 +87,7 @@ func (ss *sqlStore) Update(ctx quota.Context, cmd *quota.UpdateQuotaCmd) error { func (ss *sqlStore) getUserScopeQuota(ctx quota.Context, userID int64) (*quota.Map, error) { r := quota.Map{} - err := ss.db.WithDbSession(ctx, func(sess *sqlstore.DBSession) error { + err := ss.db.ReadReplica().WithDbSession(ctx, func(sess *sqlstore.DBSession) error { quotas := make([]*quota.Quota, 0) if err := sess.Table("quota").Where("user_id=? AND org_id=0", userID).Find("as); err != nil { return err @@ -111,7 +111,7 @@ func (ss *sqlStore) getUserScopeQuota(ctx quota.Context, userID int64) (*quota.M func (ss *sqlStore) getOrgScopeQuota(ctx quota.Context, OrgID int64) (*quota.Map, error) { r := quota.Map{} - err := ss.db.WithDbSession(ctx, func(sess *sqlstore.DBSession) error { + err := ss.db.ReadReplica().WithDbSession(ctx, func(sess *sqlstore.DBSession) error { quotas := make([]*quota.Quota, 0) if err := sess.Table("quota").Where("user_id=0 AND org_id=?", OrgID).Find("as); err != nil { return err diff --git a/pkg/services/quota/quotaimpl/store_test.go b/pkg/services/quota/quotaimpl/store_test.go index 2e8211871d1..0128f86ad1d 100644 --- a/pkg/services/quota/quotaimpl/store_test.go +++ b/pkg/services/quota/quotaimpl/store_test.go @@ -20,7 +20,7 @@ func TestIntegrationQuotaDataAccess(t *testing.T) { t.Skip("skipping integration test") } - ss := db.InitTestDB(t) + ss := db.InitTestReplDB(t) quotaStore := sqlStore{ db: ss, } diff --git a/pkg/services/serviceaccounts/tests/common.go b/pkg/services/serviceaccounts/tests/common.go index 66d15e35b9d..5ef35d18c59 100644 --- a/pkg/services/serviceaccounts/tests/common.go +++ b/pkg/services/serviceaccounts/tests/common.go @@ -36,17 +36,17 @@ type TestApiKey struct { ServiceAccountID *int64 } -func SetupUserServiceAccount(t *testing.T, db db.DB, cfg *setting.Cfg, testUser TestUser) *user.User { +func SetupUserServiceAccount(t *testing.T, store db.DB, cfg *setting.Cfg, testUser TestUser) *user.User { role := string(org.RoleViewer) if testUser.Role != "" { role = testUser.Role } - quotaService := quotaimpl.ProvideService(db, cfg) - orgService, err := orgimpl.ProvideService(db, cfg, quotaService) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) + orgService, err := orgimpl.ProvideService(store, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( - db, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), + store, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), quotaService, supportbundlestest.NewFakeBundleService(), ) require.NoError(t, err) @@ -112,7 +112,7 @@ func SetupApiKey(t *testing.T, store db.DB, cfg *setting.Cfg, testKey TestApiKey func SetupUsersServiceAccounts(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, testUsers []TestUser) (orgID int64) { role := string(org.RoleNone) - quotaService := quotaimpl.ProvideService(sqlStore, cfg) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(sqlStore), cfg) orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( diff --git a/pkg/services/sqlstore/replstore.go b/pkg/services/sqlstore/replstore.go index a4c38f1d508..223a5ebc7e3 100644 --- a/pkg/services/sqlstore/replstore.go +++ b/pkg/services/sqlstore/replstore.go @@ -264,3 +264,14 @@ func newReplStore(primary *SQLStore, readReplicas ...*SQLStore) *ReplStore { ret.repls = readReplicas return ret } + +// FakeReplStoreFromStore returns a ReplStore with the given primary +// SQLStore and no read replicas. This is a bare-minimum wrapper for testing, +// and should be removed when all services are using ReplStore in favor of +// InitTestReplDB. +func FakeReplStoreFromStore(primary *SQLStore) *ReplStore { + return &ReplStore{ + SQLStore: primary, + next: 0, + } +} diff --git a/pkg/services/team/teamimpl/store_test.go b/pkg/services/team/teamimpl/store_test.go index f63fd758e9b..d198073966e 100644 --- a/pkg/services/team/teamimpl/store_test.go +++ b/pkg/services/team/teamimpl/store_test.go @@ -17,6 +17,7 @@ import ( "github.com/grafana/grafana/pkg/services/org/orgimpl" "github.com/grafana/grafana/pkg/services/quota/quotaimpl" "github.com/grafana/grafana/pkg/services/serviceaccounts" + "github.com/grafana/grafana/pkg/services/sqlstore" "github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest" "github.com/grafana/grafana/pkg/services/team" "github.com/grafana/grafana/pkg/services/team/sortopts" @@ -48,7 +49,7 @@ func TestIntegrationTeamCommandsAndQueries(t *testing.T) { }, }, } - quotaService := quotaimpl.ProvideService(sqlStore, cfg) + quotaService := quotaimpl.ProvideService(sqlstore.FakeReplStoreFromStore(sqlStore), cfg) orgSvc, err := orgimpl.ProvideService(sqlStore, cfg, quotaService) require.NoError(t, err) userSvc, err := userimpl.ProvideService( @@ -435,7 +436,7 @@ func TestIntegrationTeamCommandsAndQueries(t *testing.T) { t.Run("Should be able to exclude service accounts from teamembers", func(t *testing.T) { sqlStore = db.InitTestDB(t) - quotaService := quotaimpl.ProvideService(sqlStore, cfg) + quotaService := quotaimpl.ProvideService(sqlstore.FakeReplStoreFromStore(sqlStore), cfg) orgSvc, err := orgimpl.ProvideService(sqlStore, cfg, quotaService) require.NoError(t, err) userSvc, err := userimpl.ProvideService( @@ -573,7 +574,7 @@ func TestIntegrationSQLStore_GetTeamMembers_ACFilter(t *testing.T) { require.NoError(t, errCreateTeam) team2, errCreateTeam := teamSvc.CreateTeam(context.Background(), "group2 name", "test2@example.org", testOrgID) require.NoError(t, errCreateTeam) - quotaService := quotaimpl.ProvideService(store, cfg) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) orgSvc, err := orgimpl.ProvideService(store, cfg, quotaService) require.NoError(t, err) userSvc, err := userimpl.ProvideService( diff --git a/pkg/services/user/userimpl/store_test.go b/pkg/services/user/userimpl/store_test.go index 45ed734c2f7..86f38407821 100644 --- a/pkg/services/user/userimpl/store_test.go +++ b/pkg/services/user/userimpl/store_test.go @@ -34,7 +34,7 @@ func TestIntegrationUserDataAccess(t *testing.T) { } ss, cfg := db.InitTestDBWithCfg(t) - quotaService := quotaimpl.ProvideService(ss, cfg) + quotaService := quotaimpl.ProvideService(sqlstore.FakeReplStoreFromStore(ss), cfg) orgService, err := orgimpl.ProvideService(ss, cfg, quotaService) require.NoError(t, err) userStore := ProvideStore(ss, setting.NewCfg()) @@ -903,7 +903,7 @@ func createFiveTestUsers(t *testing.T, svc user.Service, fn func(i int) *user.Cr func TestMetricsUsage(t *testing.T) { ss, cfg := db.InitTestDBWithCfg(t) userStore := ProvideStore(ss, setting.NewCfg()) - quotaService := quotaimpl.ProvideService(ss, cfg) + quotaService := quotaimpl.ProvideService(sqlstore.FakeReplStoreFromStore(ss), cfg) orgService, err := orgimpl.ProvideService(ss, cfg, quotaService) require.NoError(t, err) @@ -962,7 +962,7 @@ func assertEqualUser(t *testing.T, expected, got *user.User) { func createOrgAndUserSvc(t *testing.T, store db.DB, cfg *setting.Cfg) (org.Service, user.Service) { t.Helper() - quotaService := quotaimpl.ProvideService(store, cfg) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) orgService, err := orgimpl.ProvideService(store, cfg, quotaService) require.NoError(t, err) usrSvc, err := ProvideService( diff --git a/pkg/tests/api/alerting/api_alertmanager_test.go b/pkg/tests/api/alerting/api_alertmanager_test.go index 37d433c6439..7d9c2b59c8c 100644 --- a/pkg/tests/api/alerting/api_alertmanager_test.go +++ b/pkg/tests/api/alerting/api_alertmanager_test.go @@ -2656,17 +2656,17 @@ func rulesNamespaceWithoutVariableValues(t *testing.T, b []byte) (string, map[st return string(json), m } -func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { +func createUser(t *testing.T, store db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { t.Helper() cfg.AutoAssignOrg = true cfg.AutoAssignOrgId = 1 - quotaService := quotaimpl.ProvideService(db, cfg) - orgService, err := orgimpl.ProvideService(db, cfg, quotaService) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) + orgService, err := orgimpl.ProvideService(store, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( - db, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), + store, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), quotaService, supportbundlestest.NewFakeBundleService(), ) require.NoError(t, err) diff --git a/pkg/tests/api/correlations/common_test.go b/pkg/tests/api/correlations/common_test.go index c14f4b3a937..28525fe3854 100644 --- a/pkg/tests/api/correlations/common_test.go +++ b/pkg/tests/api/correlations/common_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/server" "github.com/grafana/grafana/pkg/services/correlations" @@ -144,7 +145,7 @@ func (c TestContext) createOrg(name string) int64 { c.t.Helper() store := c.env.SQLStore c.env.Cfg.AutoAssignOrg = false - quotaService := quotaimpl.ProvideService(store, c.env.Cfg) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), c.env.Cfg) orgService, err := orgimpl.ProvideService(store, c.env.Cfg, quotaService) require.NoError(c.t, err) orgId, err := orgService.GetOrCreate(context.Background(), name) @@ -158,7 +159,7 @@ func (c TestContext) createUser(cmd user.CreateUserCommand) User { c.env.Cfg.AutoAssignOrg = true c.env.Cfg.AutoAssignOrgId = 1 - quotaService := quotaimpl.ProvideService(store, c.env.Cfg) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), c.env.Cfg) orgService, err := orgimpl.ProvideService(store, c.env.Cfg, quotaService) require.NoError(c.t, err) usrSvc, err := userimpl.ProvideService( diff --git a/pkg/tests/api/dashboards/api_dashboards_test.go b/pkg/tests/api/dashboards/api_dashboards_test.go index 604f0df60b8..f3a6d3c1a23 100644 --- a/pkg/tests/api/dashboards/api_dashboards_test.go +++ b/pkg/tests/api/dashboards/api_dashboards_test.go @@ -115,17 +115,17 @@ func TestIntegrationDashboardQuota(t *testing.T) { }) } -func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { +func createUser(t *testing.T, store db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { t.Helper() cfg.AutoAssignOrg = true cfg.AutoAssignOrgId = 1 - quotaService := quotaimpl.ProvideService(db, cfg) - orgService, err := orgimpl.ProvideService(db, cfg, quotaService) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) + orgService, err := orgimpl.ProvideService(store, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( - db, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), + store, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), quotaService, supportbundlestest.NewFakeBundleService(), ) require.NoError(t, err) diff --git a/pkg/tests/api/folders/api_folder_test.go b/pkg/tests/api/folders/api_folder_test.go index c61e94b0cd9..dcb2ef7e28c 100644 --- a/pkg/tests/api/folders/api_folder_test.go +++ b/pkg/tests/api/folders/api_folder_test.go @@ -9,6 +9,9 @@ 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/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -21,8 +24,6 @@ import ( "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tests" "github.com/grafana/grafana/pkg/tests/testinfra" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const orgID = 1 @@ -207,17 +208,17 @@ func TestIntegrationNestedFoldersOn(t *testing.T) { }) } -func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { +func createUser(t *testing.T, store db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { t.Helper() cfg.AutoAssignOrg = true cfg.AutoAssignOrgId = orgID - quotaService := quotaimpl.ProvideService(db, cfg) - orgService, err := orgimpl.ProvideService(db, cfg, quotaService) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) + orgService, err := orgimpl.ProvideService(store, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( - db, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), + store, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), quotaService, supportbundlestest.NewFakeBundleService(), ) require.NoError(t, err) diff --git a/pkg/tests/api/plugins/api_plugins_test.go b/pkg/tests/api/plugins/api_plugins_test.go index ba04251c1fb..cfdd8851692 100644 --- a/pkg/tests/api/plugins/api_plugins_test.go +++ b/pkg/tests/api/plugins/api_plugins_test.go @@ -193,17 +193,17 @@ func TestIntegrationPluginAssets(t *testing.T) { }) } -func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) { +func createUser(t *testing.T, store db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) { t.Helper() cfg.AutoAssignOrg = true cfg.AutoAssignOrgId = 1 - quotaService := quotaimpl.ProvideService(db, cfg) - orgService, err := orgimpl.ProvideService(db, cfg, quotaService) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) + orgService, err := orgimpl.ProvideService(store, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( - db, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), + store, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), quotaService, supportbundlestest.NewFakeBundleService(), ) require.NoError(t, err) diff --git a/pkg/tests/api/stats/admin_test.go b/pkg/tests/api/stats/admin_test.go index 3e264a75e0c..eb65250778c 100644 --- a/pkg/tests/api/stats/admin_test.go +++ b/pkg/tests/api/stats/admin_test.go @@ -81,17 +81,17 @@ func grafanaSetup(t *testing.T, opts testinfra.GrafanaOpts) string { return fmt.Sprintf("http://%s:%s@%s/api/admin/stats", "grafana", "password", grafanaListedAddr) } -func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { +func createUser(t *testing.T, store db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { t.Helper() cfg.AutoAssignOrg = true cfg.AutoAssignOrgId = 1 - quotaService := quotaimpl.ProvideService(db, cfg) - orgService, err := orgimpl.ProvideService(db, cfg, quotaService) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) + orgService, err := orgimpl.ProvideService(store, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( - db, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), + store, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), quotaService, supportbundlestest.NewFakeBundleService(), ) require.NoError(t, err) diff --git a/pkg/tests/apis/helper.go b/pkg/tests/apis/helper.go index 4d896fa5690..080dc5e8715 100644 --- a/pkg/tests/apis/helper.go +++ b/pkg/tests/apis/helper.go @@ -19,13 +19,13 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer/yaml" yamlutil "k8s.io/apimachinery/pkg/util/yaml" - "k8s.io/client-go/discovery" "k8s.io/client-go/dynamic" "k8s.io/client-go/rest" "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/apimachinery/utils" + "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/server" @@ -399,7 +399,7 @@ func (c *K8sTestHelper) CreateUser(name string, orgName string, basicRole org.Ro c.env.Cfg.AutoAssignOrgId = 1 // the default }() - quotaService := quotaimpl.ProvideService(store, c.env.Cfg) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), c.env.Cfg) orgService, err := orgimpl.ProvideService(store, c.env.Cfg, quotaService) require.NoError(c.t, err) diff --git a/pkg/tests/testinfra/testinfra.go b/pkg/tests/testinfra/testinfra.go index 277fd4e5b9b..3da3265607a 100644 --- a/pkg/tests/testinfra/testinfra.go +++ b/pkg/tests/testinfra/testinfra.go @@ -451,7 +451,7 @@ func CreateUser(t *testing.T, store db.DB, cfg *setting.Cfg, cmd user.CreateUser cfg.AutoAssignOrgId = 1 cmd.OrgID = 1 - quotaService := quotaimpl.ProvideService(store, cfg) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) orgService, err := orgimpl.ProvideService(store, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( diff --git a/pkg/tests/utils.go b/pkg/tests/utils.go index f81683c80f4..c1208211e95 100644 --- a/pkg/tests/utils.go +++ b/pkg/tests/utils.go @@ -9,6 +9,8 @@ import ( "github.com/go-openapi/strfmt" goapi "github.com/grafana/grafana-openapi-client-go/client" + "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" @@ -19,20 +21,19 @@ import ( "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/services/user/userimpl" "github.com/grafana/grafana/pkg/setting" - "github.com/stretchr/testify/require" ) -func CreateUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { +func CreateUser(t *testing.T, store db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { t.Helper() cfg.AutoAssignOrg = true cfg.AutoAssignOrgId = 1 - quotaService := quotaimpl.ProvideService(db, cfg) - orgService, err := orgimpl.ProvideService(db, cfg, quotaService) + quotaService := quotaimpl.ProvideService(db.FakeReplDBFromDB(store), cfg) + orgService, err := orgimpl.ProvideService(store, cfg, quotaService) require.NoError(t, err) usrSvc, err := userimpl.ProvideService( - db, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), + store, orgService, cfg, nil, nil, tracing.InitializeTracerForTest(), quotaService, supportbundlestest.NewFakeBundleService(), ) require.NoError(t, err)