mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Make Cfg field private in SQLStore (#85593)
* make cfg private in sqlstore * fix db init in tests * fix case * fix folder test init * fix imports * make another Cfg private * remove another Cfg * remove unused variable * use store cfg, it has side-effects * fix mutated cfg in tests
This commit is contained in:
parent
f6e472f879
commit
522a98c126
@ -814,9 +814,9 @@ func getDashboardShouldReturn200WithConfig(t *testing.T, sc *scenarioContext, pr
|
||||
features := featuremgmt.WithFeatures()
|
||||
var err error
|
||||
if dashboardStore == nil {
|
||||
sql := db.InitTestDB(t)
|
||||
sql, cfg := db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err = database.ProvideDashboardStore(sql, sql.Cfg, features, tagimpl.ProvideService(sql), quotaService)
|
||||
dashboardStore, err = database.ProvideDashboardStore(sql, cfg, features, tagimpl.ProvideService(sql), quotaService)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -201,13 +201,12 @@ func BenchmarkFolderListAndSearch(b *testing.B) {
|
||||
|
||||
func setupDB(b testing.TB) benchScenario {
|
||||
b.Helper()
|
||||
db := sqlstore.InitTestDB(b)
|
||||
db, cfg := sqlstore.InitTestDB(b)
|
||||
IDs := map[int64]struct{}{}
|
||||
|
||||
opts := sqlstore.NativeSettingsForDialect(db.GetDialect())
|
||||
|
||||
quotaService := quotatest.New(false, nil)
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
teamSvc, err := teamimpl.ProvideService(db, cfg)
|
||||
require.NoError(b, err)
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgtest"
|
||||
"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"
|
||||
@ -61,8 +62,7 @@ func TestOrgUsersAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
hs := setupSimpleHTTPServer(featuremgmt.WithFeatures())
|
||||
settings := hs.Cfg
|
||||
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore.Cfg = settings
|
||||
sqlStore := db.InitTestDB(t, sqlstore.InitTestDBOpt{Cfg: settings})
|
||||
hs.SQLStore = sqlStore
|
||||
orgService := orgtest.NewOrgServiceFake()
|
||||
orgService.ExpectedSearchOrgUsersResult = &org.SearchOrgUsersQueryResult{}
|
||||
|
@ -39,6 +39,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/secrets/database"
|
||||
"github.com/grafana/grafana/pkg/services/secrets/fakes"
|
||||
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
tempuser "github.com/grafana/grafana/pkg/services/temp_user"
|
||||
"github.com/grafana/grafana/pkg/services/temp_user/tempuserimpl"
|
||||
@ -53,8 +54,7 @@ const newEmail = "newemail@localhost"
|
||||
|
||||
func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
settings := setting.NewCfg()
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore.Cfg = settings
|
||||
sqlStore := db.InitTestDB(t, sqlstore.InitTestDBOpt{Cfg: settings})
|
||||
hs := &HTTPServer{
|
||||
Cfg: settings,
|
||||
SQLStore: sqlStore,
|
||||
@ -78,7 +78,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
srv := authinfoimpl.ProvideService(
|
||||
authInfoStore, remotecache.NewFakeCacheStorage(), secretsService)
|
||||
hs.authInfoService = srv
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotatest.New(false, nil))
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, settings, quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
userSvc, err := userimpl.ProvideService(sqlStore, orgSvc, sc.cfg, nil, nil, quotatest.New(false, nil), supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
@ -148,7 +148,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
Login: "admin",
|
||||
IsAdmin: true,
|
||||
}
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotatest.New(false, nil))
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, sc.cfg, quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
userSvc, err := userimpl.ProvideService(sqlStore, orgSvc, sc.cfg, nil, nil, quotatest.New(false, nil), supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
@ -379,8 +379,7 @@ func TestHTTPServer_UpdateUser(t *testing.T) {
|
||||
func setupUpdateEmailTests(t *testing.T, cfg *setting.Cfg) (*user.User, *HTTPServer, *notifications.NotificationServiceMock) {
|
||||
t.Helper()
|
||||
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore.Cfg = cfg
|
||||
sqlStore := db.InitTestDB(t, sqlstore.InitTestDBOpt{Cfg: cfg})
|
||||
|
||||
tempUserService := tempuserimpl.ProvideService(sqlStore, cfg)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, cfg, quotatest.New(false, nil))
|
||||
@ -606,8 +605,7 @@ func TestUser_UpdateEmail(t *testing.T) {
|
||||
}
|
||||
|
||||
nsMock := notifications.MockNotificationService()
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore.Cfg = settings
|
||||
sqlStore := db.InitTestDB(t, sqlstore.InitTestDBOpt{Cfg: settings})
|
||||
|
||||
tempUserSvc := tempuserimpl.ProvideService(sqlStore, settings)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, settings, quotatest.New(false, nil))
|
||||
|
@ -771,7 +771,7 @@ ORDER BY
|
||||
|
||||
func notServiceAccount(ss *sqlstore.SQLStore) string {
|
||||
return fmt.Sprintf("is_service_account = %s",
|
||||
ss.Dialect.BooleanStr(false))
|
||||
ss.GetDialect().BooleanStr(false))
|
||||
}
|
||||
|
||||
// confirm function asks for user input
|
||||
|
@ -109,9 +109,9 @@ func TestBuildConflictBlock(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
// Restore after destructive operation
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
||||
userStore := userimpl.ProvideStore(sqlStore, sqlStore.Cfg)
|
||||
userStore := userimpl.ProvideStore(sqlStore, cfg)
|
||||
for _, u := range tc.users {
|
||||
u := user.User{
|
||||
Email: u.Email,
|
||||
@ -217,9 +217,9 @@ conflict: test2
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
// Restore after destructive operation
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
||||
userStore := userimpl.ProvideStore(sqlStore, sqlStore.Cfg)
|
||||
userStore := userimpl.ProvideStore(sqlStore, cfg)
|
||||
for _, u := range tc.users {
|
||||
u := user.User{
|
||||
Email: u.Email,
|
||||
@ -398,9 +398,9 @@ func TestGetConflictingUsers(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
// Restore after destructive operation
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
||||
userStore := userimpl.ProvideStore(sqlStore, sqlStore.Cfg)
|
||||
userStore := userimpl.ProvideStore(sqlStore, cfg)
|
||||
for _, u := range tc.users {
|
||||
u := user.User{
|
||||
Email: u.Email,
|
||||
@ -510,9 +510,9 @@ func TestGenerateConflictingUsersFile(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
// Restore after destructive operation
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
||||
userStore := userimpl.ProvideStore(sqlStore, sqlStore.Cfg)
|
||||
userStore := userimpl.ProvideStore(sqlStore, cfg)
|
||||
for _, u := range tc.users {
|
||||
cmd := user.User{
|
||||
Email: u.Email,
|
||||
@ -580,7 +580,7 @@ func TestRunValidateConflictUserFile(t *testing.T) {
|
||||
rawSQL := fmt.Sprintf(
|
||||
"INSERT INTO %s (email, login, org_id, version, is_admin, created, updated) VALUES (?,?,?,0,%s,\"2024-03-18T15:25:32\",\"2024-03-18T15:25:32\")",
|
||||
sqlStore.Quote("user"),
|
||||
sqlStore.Dialect.BooleanStr(false),
|
||||
sqlStore.GetDialect().BooleanStr(false),
|
||||
)
|
||||
result, err := sess.Exec(rawSQL, dupUserLogincmd.Email, dupUserLogincmd.Login, dupUserLogincmd.OrgID)
|
||||
if err != nil {
|
||||
@ -660,7 +660,7 @@ func TestIntegrationMergeUser(t *testing.T) {
|
||||
rawSQL := fmt.Sprintf(
|
||||
"INSERT INTO %s (email, login, org_id, version, is_admin, created, updated) VALUES (?,?,?,0,%s,?,?)",
|
||||
sqlStore.Quote("user"),
|
||||
sqlStore.Dialect.BooleanStr(false),
|
||||
sqlStore.GetDialect().BooleanStr(false),
|
||||
)
|
||||
result, err := sess.Exec(rawSQL, cmd.Email, cmd.Login, cmd.OrgID, cmd.Created, cmd.Updated)
|
||||
if err != nil {
|
||||
@ -692,7 +692,7 @@ func TestIntegrationMergeUser(t *testing.T) {
|
||||
rawSQL := fmt.Sprintf(
|
||||
"INSERT INTO %s (email, login, org_id, version, is_admin, created, updated) VALUES (?,?,?,0,%s,?,?)",
|
||||
sqlStore.Quote("user"),
|
||||
sqlStore.Dialect.BooleanStr(false),
|
||||
sqlStore.GetDialect().BooleanStr(false),
|
||||
)
|
||||
result, err := sess.Exec(rawSQL, cmd.Email, cmd.Login, cmd.OrgID, cmd.Created, cmd.Updated)
|
||||
if err != nil {
|
||||
@ -860,7 +860,7 @@ conflict: test2
|
||||
rawSQL := fmt.Sprintf(
|
||||
"INSERT INTO %s (email, login, org_id, version, is_admin, created, updated) VALUES (?,?,?,0,%s,?,?)",
|
||||
sqlStore.Quote("user"),
|
||||
sqlStore.Dialect.BooleanStr(false),
|
||||
sqlStore.GetDialect().BooleanStr(false),
|
||||
)
|
||||
result, err := sess.Exec(rawSQL, cmd.Email, cmd.Login, cmd.OrgID, cmd.Created, cmd.Updated)
|
||||
if err != nil {
|
||||
|
@ -54,13 +54,16 @@ type Session = sqlstore.DBSession
|
||||
type InitTestDBOpt = sqlstore.InitTestDBOpt
|
||||
|
||||
var SetupTestDB = sqlstore.SetupTestDB
|
||||
var InitTestDB = sqlstore.InitTestDB
|
||||
var CleanupTestDB = sqlstore.CleanupTestDB
|
||||
var ProvideService = sqlstore.ProvideService
|
||||
|
||||
func InitTestDBwithCfg(t sqlutil.ITestDB, opts ...InitTestDBOpt) (*sqlstore.SQLStore, *setting.Cfg) {
|
||||
store := InitTestDB(t, opts...)
|
||||
return store, store.Cfg
|
||||
func InitTestDB(t sqlutil.ITestDB, opts ...InitTestDBOpt) *sqlstore.SQLStore {
|
||||
db, _ := InitTestDBWithCfg(t, opts...)
|
||||
return db
|
||||
}
|
||||
|
||||
func InitTestDBWithCfg(t sqlutil.ITestDB, opts ...InitTestDBOpt) (*sqlstore.SQLStore, *setting.Cfg) {
|
||||
return sqlstore.InitTestDB(t, opts...)
|
||||
}
|
||||
|
||||
func IsTestDbSQLite() bool {
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/usagestats"
|
||||
"github.com/grafana/grafana/pkg/services/secrets"
|
||||
"github.com/grafana/grafana/pkg/services/secrets/fakes"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
)
|
||||
@ -33,15 +34,15 @@ func createTestClient(t *testing.T, opts *setting.RemoteCacheOptions, sqlstore d
|
||||
}
|
||||
|
||||
func TestCachedBasedOnConfig(t *testing.T) {
|
||||
cfg := setting.NewCfg()
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
err := cfg.Load(setting.CommandLineArgs{
|
||||
HomePath: "../../../",
|
||||
})
|
||||
require.Nil(t, err, "Failed to load config")
|
||||
|
||||
client := createTestClient(t, cfg.RemoteCacheOptions, db.InitTestDB(t))
|
||||
client := createTestClient(t, cfg.RemoteCacheOptions, db)
|
||||
runTestsForClient(t, client)
|
||||
runCountTestsForClient(t, cfg.RemoteCacheOptions, db.InitTestDB(t))
|
||||
runCountTestsForClient(t, cfg.RemoteCacheOptions, db)
|
||||
}
|
||||
|
||||
func TestInvalidCacheTypeReturnsError(t *testing.T) {
|
||||
|
@ -24,7 +24,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestConcurrentUsersMetrics(t *testing.T) {
|
||||
sqlStore, cfg := db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
statsService := statsimpl.ProvideService(&setting.Cfg{}, sqlStore)
|
||||
s := createService(t, cfg, sqlStore, statsService)
|
||||
|
||||
@ -42,7 +42,7 @@ func TestConcurrentUsersMetrics(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConcurrentUsersStats(t *testing.T) {
|
||||
sqlStore, cfg := db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
statsService := statsimpl.ProvideService(&setting.Cfg{}, sqlStore)
|
||||
s := createService(t, cfg, sqlStore, statsService)
|
||||
|
||||
|
@ -33,8 +33,7 @@ func TestIntegrationWillRunInstrumentationServerWhenTargetHasNoHttpServer(t *tes
|
||||
t.Skip("skipping - sqlite not supported for storage server target")
|
||||
}
|
||||
|
||||
testdb := db.InitTestDB(t)
|
||||
cfg := testdb.Cfg
|
||||
_, cfg := db.InitTestDBWithCfg(t)
|
||||
cfg.GRPCServerNetwork = "tcp"
|
||||
cfg.GRPCServerAddress = "localhost:10000"
|
||||
addStorageServerToConfig(t, cfg, dbType)
|
||||
|
@ -388,7 +388,7 @@ func createUsersAndTeams(t *testing.T, svcs helperServices, orgID int64, users [
|
||||
}
|
||||
|
||||
func setupTestEnv(t testing.TB) (*AccessControlStore, rs.Store, user.Service, team.Service, org.Service) {
|
||||
sql, cfg := db.InitTestDBwithCfg(t)
|
||||
sql, cfg := db.InitTestDBWithCfg(t)
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgRole = "Viewer"
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
@ -558,9 +558,9 @@ func seedResourcePermissions(
|
||||
}
|
||||
|
||||
func setupTestEnv(t testing.TB) (*store, db.DB, *setting.Cfg) {
|
||||
sql := db.InitTestDB(t)
|
||||
sql, cfg := db.InitTestDBWithCfg(t)
|
||||
asService := NewActionSetService()
|
||||
return NewStore(sql, featuremgmt.WithFeatures(), &asService), sql, sql.Cfg
|
||||
return NewStore(sql, featuremgmt.WithFeatures(), &asService), sql, cfg
|
||||
}
|
||||
|
||||
func TestStore_IsInherited(t *testing.T) {
|
||||
|
@ -27,8 +27,7 @@ func TestIntegrationAuthorize(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
sql := db.InitTestDB(t)
|
||||
cfg := sql.Cfg
|
||||
sql, cfg := db.InitTestDBWithCfg(t)
|
||||
|
||||
dash1 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
UserID: 1,
|
||||
|
@ -209,14 +209,14 @@ func TestIntegrationAnnotationListingWithInheritedRBAC(t *testing.T) {
|
||||
annotationsTexts := make([]string, 0, folder.MaxNestedFolderDepth+1)
|
||||
|
||||
setupFolderStructure := func() db.DB {
|
||||
sql := db.InitTestDB(t)
|
||||
sql, cfg := db.InitTestDBWithCfg(t)
|
||||
|
||||
// enable nested folders so that the folder table is populated for all the tests
|
||||
features := featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders)
|
||||
|
||||
tagService := tagimpl.ProvideService(sql)
|
||||
|
||||
dashStore, err := dashboardstore.ProvideDashboardStore(sql, sql.Cfg, features, tagService, quotatest.New(false, nil))
|
||||
dashStore, err := dashboardstore.ProvideDashboardStore(sql, cfg, features, tagService, quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
|
||||
origNewGuardian := guardian.New
|
||||
@ -225,10 +225,9 @@ func TestIntegrationAnnotationListingWithInheritedRBAC(t *testing.T) {
|
||||
guardian.New = origNewGuardian
|
||||
})
|
||||
|
||||
ac := acimpl.ProvideAccessControl(sql.Cfg)
|
||||
folderSvc := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), sql.Cfg, dashStore, folderimpl.ProvideDashboardFolderStore(sql), sql, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
ac := acimpl.ProvideAccessControl(cfg)
|
||||
folderSvc := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, dashStore, folderimpl.ProvideDashboardFolderStore(sql), sql, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
cfg.AnnotationMaximumTagsLength = 60
|
||||
|
||||
store := NewXormStore(cfg, log.New("annotation.test"), sql, tagService)
|
||||
|
@ -42,8 +42,7 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
sql := db.InitTestDB(t)
|
||||
cfg := sql.Cfg
|
||||
sql, cfg := db.InitTestDBWithCfg(t)
|
||||
|
||||
dashboard1 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
UserID: 1,
|
||||
|
@ -47,8 +47,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
var dashboardStore dashboards.Store
|
||||
|
||||
setup := func() {
|
||||
sql := db.InitTestDB(t)
|
||||
sqlStore, cfg = sql, sql.Cfg
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
var err error
|
||||
dashboardStore, err = ProvideDashboardStore(sqlStore, cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
@ -147,8 +146,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
var currentUser *user.SignedInUser
|
||||
|
||||
setup2 := func() {
|
||||
sql := db.InitTestDB(t)
|
||||
sqlStore, cfg = sql, sql.Cfg
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
var err error
|
||||
dashboardStore, err = ProvideDashboardStore(sqlStore, cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
@ -253,8 +251,7 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
||||
var viewer *user.SignedInUser
|
||||
|
||||
setup := func() {
|
||||
sql := db.InitTestDB(t)
|
||||
sqlStore, cfg = sql, sql.Cfg
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
|
||||
// enable nested folders so that the folder table is populated for all the tests
|
||||
|
@ -18,9 +18,9 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := ProvideDashboardStore(sqlStore, cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
|
||||
folderCmd := dashboards.SaveDashboardCommand{
|
||||
|
@ -49,7 +49,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
var dashboardStore dashboards.Store
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
var err error
|
||||
dashboardStore, err = ProvideDashboardStore(sqlStore, cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
@ -651,7 +651,7 @@ func TestIntegrationDashboard_Filter(t *testing.T) {
|
||||
},
|
||||
Filters: []interface{}{
|
||||
searchstore.TitleFilter{
|
||||
Dialect: sqlStore.Dialect,
|
||||
Dialect: sqlStore.GetDialect(),
|
||||
Title: "Beta",
|
||||
},
|
||||
},
|
||||
@ -711,9 +711,9 @@ func TestIntegrationFindDashboardsByTitle(t *testing.T) {
|
||||
orgID := int64(1)
|
||||
insertTestDashboard(t, dashboardStore, "dashboard under general", orgID, 0, "", false)
|
||||
|
||||
ac := acimpl.ProvideAccessControl(sqlStore.Cfg)
|
||||
ac := acimpl.ProvideAccessControl(cfg)
|
||||
folderStore := folderimpl.ProvideDashboardFolderStore(sqlStore)
|
||||
folderServiceWithFlagOn := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), sqlStore.Cfg, dashboardStore, folderStore, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
folderServiceWithFlagOn := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, dashboardStore, folderStore, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
|
||||
user := &user.SignedInUser{
|
||||
OrgID: 1,
|
||||
@ -828,9 +828,9 @@ func TestIntegrationFindDashboardsByFolder(t *testing.T) {
|
||||
orgID := int64(1)
|
||||
insertTestDashboard(t, dashboardStore, "dashboard under general", orgID, 0, "", false)
|
||||
|
||||
ac := acimpl.ProvideAccessControl(sqlStore.Cfg)
|
||||
ac := acimpl.ProvideAccessControl(cfg)
|
||||
folderStore := folderimpl.ProvideDashboardFolderStore(sqlStore)
|
||||
folderServiceWithFlagOn := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), sqlStore.Cfg, dashboardStore, folderStore, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
folderServiceWithFlagOn := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, dashboardStore, folderStore, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
|
||||
user := &user.SignedInUser{
|
||||
OrgID: 1,
|
||||
|
@ -28,7 +28,7 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
var dashboardStore dashboards.Store
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
var err error
|
||||
dashboardStore, err = database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
@ -40,7 +40,7 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
title := "Very Unique Name"
|
||||
var sqlStore db.DB
|
||||
var folder1, folder2 *dashboards.Dashboard
|
||||
sqlStore = db.InitTestDB(t)
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
folderStore := ProvideDashboardFolderStore(sqlStore)
|
||||
folder2 = insertTestFolder(t, dashboardStore, "TEST", orgId, "", "prod")
|
||||
_ = insertTestDashboard(t, dashboardStore, title, orgId, folder2.ID, folder2.UID, "prod")
|
||||
|
@ -58,7 +58,7 @@ func TestIntegrationProvideFolderService(t *testing.T) {
|
||||
t.Run("should register scope resolvers", func(t *testing.T) {
|
||||
cfg := setting.NewCfg()
|
||||
ac := acmock.New()
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db := db.InitTestDB(t)
|
||||
ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, nil, nil, db, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil)
|
||||
|
||||
require.Len(t, ac.Calls.RegisterAttributeScopeResolver, 3)
|
||||
@ -71,12 +71,11 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
}
|
||||
t.Run("Folder service tests", func(t *testing.T) {
|
||||
dashStore := &dashboards.FakeDashboardStore{}
|
||||
db := sqlstore.InitTestDB(t)
|
||||
nestedFolderStore := ProvideStore(db, db.Cfg)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
nestedFolderStore := ProvideStore(db, cfg)
|
||||
|
||||
folderStore := foldertest.NewFakeFolderStore(t)
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
features := featuremgmt.WithFeatures()
|
||||
|
||||
ac := acmock.New().WithPermissions([]accesscontrol.Permission{
|
||||
@ -354,16 +353,14 @@ func TestIntegrationNestedFolderService(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
folderStore := ProvideDashboardFolderStore(db)
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
featuresFlagOn := featuremgmt.WithFeatures("nestedFolders")
|
||||
dashStore, err := database.ProvideDashboardStore(db, db.Cfg, featuresFlagOn, tagimpl.ProvideService(db), quotaService)
|
||||
dashStore, err := database.ProvideDashboardStore(db, cfg, featuresFlagOn, tagimpl.ProvideService(db), quotaService)
|
||||
require.NoError(t, err)
|
||||
nestedFolderStore := ProvideStore(db, db.Cfg)
|
||||
nestedFolderStore := ProvideStore(db, cfg)
|
||||
|
||||
b := bus.ProvideBus(tracing.InitializeTracerForTest())
|
||||
ac := acimpl.ProvideAccessControl(cfg)
|
||||
@ -479,9 +476,9 @@ func TestIntegrationNestedFolderService(t *testing.T) {
|
||||
})
|
||||
t.Run("With nested folder feature flag off", func(t *testing.T) {
|
||||
featuresFlagOff := featuremgmt.WithFeatures()
|
||||
dashStore, err := database.ProvideDashboardStore(db, db.Cfg, featuresFlagOff, tagimpl.ProvideService(db), quotaService)
|
||||
dashStore, err := database.ProvideDashboardStore(db, cfg, featuresFlagOff, tagimpl.ProvideService(db), quotaService)
|
||||
require.NoError(t, err)
|
||||
nestedFolderStore := ProvideStore(db, db.Cfg)
|
||||
nestedFolderStore := ProvideStore(db, cfg)
|
||||
|
||||
serviceWithFlagOff := &Service{
|
||||
cfg: cfg,
|
||||
@ -644,9 +641,9 @@ func TestIntegrationNestedFolderService(t *testing.T) {
|
||||
lps, err := librarypanels.ProvideService(cfg, db, routeRegister, elementService, tc.service)
|
||||
require.NoError(t, err)
|
||||
|
||||
dashStore, err := database.ProvideDashboardStore(db, db.Cfg, tc.featuresFlag, tagimpl.ProvideService(db), quotaService)
|
||||
dashStore, err := database.ProvideDashboardStore(db, cfg, tc.featuresFlag, tagimpl.ProvideService(db), quotaService)
|
||||
require.NoError(t, err)
|
||||
nestedFolderStore := ProvideStore(db, db.Cfg)
|
||||
nestedFolderStore := ProvideStore(db, cfg)
|
||||
tc.service.dashboardStore = dashStore
|
||||
tc.service.store = nestedFolderStore
|
||||
|
||||
@ -737,11 +734,11 @@ func TestNestedFolderServiceFeatureToggle(t *testing.T) {
|
||||
|
||||
dashboardFolderStore := foldertest.NewFakeFolderStore(t)
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
folderService := &Service{
|
||||
cfg: cfg,
|
||||
store: nestedFolderStore,
|
||||
db: sqlstore.InitTestDB(t),
|
||||
db: db,
|
||||
dashboardStore: &dashStore,
|
||||
dashboardFolderStore: dashboardFolderStore,
|
||||
features: featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders),
|
||||
@ -765,7 +762,7 @@ func TestFolderServiceDualWrite(t *testing.T) {
|
||||
guardian.New = g
|
||||
})
|
||||
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db, _ := sqlstore.InitTestDB(t)
|
||||
cfg := setting.NewCfg()
|
||||
features := featuremgmt.WithFeatures()
|
||||
nestedFolderStore := ProvideStore(db, cfg)
|
||||
@ -778,7 +775,7 @@ func TestFolderServiceDualWrite(t *testing.T) {
|
||||
folderService := &Service{
|
||||
cfg: setting.NewCfg(),
|
||||
store: nestedFolderStore,
|
||||
db: sqlstore.InitTestDB(t),
|
||||
db: db,
|
||||
dashboardStore: dashStore,
|
||||
dashboardFolderStore: dashboardFolderStore,
|
||||
features: featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders),
|
||||
@ -845,7 +842,8 @@ func TestNestedFolderService(t *testing.T) {
|
||||
|
||||
nestedFolderStore := NewFakeStore()
|
||||
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures(), acimpl.ProvideAccessControl(setting.NewCfg()), sqlstore.InitTestDB(t))
|
||||
db, _ := sqlstore.InitTestDB(t)
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures(), acimpl.ProvideAccessControl(setting.NewCfg()), db)
|
||||
_, err := folderSvc.Create(context.Background(), &folder.CreateFolderCommand{
|
||||
OrgID: orgID,
|
||||
Title: dash.Title,
|
||||
@ -877,7 +875,8 @@ func TestNestedFolderService(t *testing.T) {
|
||||
dashboardFolderStore := foldertest.NewFakeFolderStore(t)
|
||||
nestedFolderStore := NewFakeStore()
|
||||
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures("nestedFolders"), acimpl.ProvideAccessControl(setting.NewCfg()), sqlstore.InitTestDB(t))
|
||||
db, _ := sqlstore.InitTestDB(t)
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures("nestedFolders"), acimpl.ProvideAccessControl(setting.NewCfg()), db)
|
||||
_, err := folderSvc.Create(context.Background(), &folder.CreateFolderCommand{
|
||||
OrgID: orgID,
|
||||
Title: dash.Title,
|
||||
@ -942,7 +941,8 @@ func TestNestedFolderService(t *testing.T) {
|
||||
nestedFolderUser.Permissions[orgID] = map[string][]string{dashboards.ActionFoldersWrite: {dashboards.ScopeFoldersProvider.GetResourceScopeUID("some_parent")}}
|
||||
|
||||
nestedFolderStore := NewFakeStore()
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures("nestedFolders"), acimpl.ProvideAccessControl(setting.NewCfg()), sqlstore.InitTestDB(t))
|
||||
db, _ := sqlstore.InitTestDB(t)
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures("nestedFolders"), acimpl.ProvideAccessControl(setting.NewCfg()), db)
|
||||
_, err := folderSvc.Create(context.Background(), &folder.CreateFolderCommand{
|
||||
OrgID: orgID,
|
||||
Title: dash.Title,
|
||||
@ -969,9 +969,10 @@ func TestNestedFolderService(t *testing.T) {
|
||||
dashboardFolderStore := foldertest.NewFakeFolderStore(t)
|
||||
nestedFolderStore := NewFakeStore()
|
||||
|
||||
db, _ := sqlstore.InitTestDB(t)
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures("nestedFolders"), actest.FakeAccessControl{
|
||||
ExpectedEvaluate: true,
|
||||
}, sqlstore.InitTestDB(t))
|
||||
}, db)
|
||||
f, err := folderSvc.Create(context.Background(), &folder.CreateFolderCommand{
|
||||
OrgID: orgID,
|
||||
Title: "myFolder",
|
||||
@ -1019,9 +1020,10 @@ func TestNestedFolderService(t *testing.T) {
|
||||
SignedInUser: usr,
|
||||
}
|
||||
|
||||
db, _ := sqlstore.InitTestDB(t)
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures("nestedFolders"), actest.FakeAccessControl{
|
||||
ExpectedEvaluate: true,
|
||||
}, sqlstore.InitTestDB(t))
|
||||
}, db)
|
||||
_, err := folderSvc.Create(context.Background(), &cmd)
|
||||
require.Error(t, err, folder.ErrCircularReference)
|
||||
// CreateFolder should not call the folder store's create method.
|
||||
@ -1048,9 +1050,10 @@ func TestNestedFolderService(t *testing.T) {
|
||||
nestedFolderStore.ExpectedError = errors.New("FAILED")
|
||||
|
||||
// the service return success as long as the legacy create succeeds
|
||||
db, _ := sqlstore.InitTestDB(t)
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures("nestedFolders"), actest.FakeAccessControl{
|
||||
ExpectedEvaluate: true,
|
||||
}, sqlstore.InitTestDB(t))
|
||||
}, db)
|
||||
_, err := folderSvc.Create(context.Background(), &folder.CreateFolderCommand{
|
||||
OrgID: orgID,
|
||||
Title: "myFolder",
|
||||
@ -1232,9 +1235,10 @@ func TestNestedFolderService(t *testing.T) {
|
||||
//nestedFolderStore.ExpectedFolder = &folder.Folder{UID: "myFolder", ParentUID: "newFolder"}
|
||||
nestedFolderStore.ExpectedParentFolders = parents
|
||||
|
||||
db, _ := sqlstore.InitTestDB(t)
|
||||
folderSvc := setup(t, dashStore, dashboardFolderStore, nestedFolderStore, featuremgmt.WithFeatures("nestedFolders"), actest.FakeAccessControl{
|
||||
ExpectedEvaluate: true,
|
||||
}, sqlstore.InitTestDB(t))
|
||||
}, db)
|
||||
_, err := folderSvc.Create(context.Background(), &folder.CreateFolderCommand{
|
||||
Title: "folder",
|
||||
OrgID: orgID,
|
||||
@ -1277,16 +1281,14 @@ func TestIntegrationNestedFolderSharedWithMe(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
folderStore := ProvideDashboardFolderStore(db)
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
featuresFlagOn := featuremgmt.WithFeatures("nestedFolders")
|
||||
dashStore, err := database.ProvideDashboardStore(db, db.Cfg, featuresFlagOn, tagimpl.ProvideService(db), quotaService)
|
||||
dashStore, err := database.ProvideDashboardStore(db, cfg, featuresFlagOn, tagimpl.ProvideService(db), quotaService)
|
||||
require.NoError(t, err)
|
||||
nestedFolderStore := ProvideStore(db, db.Cfg)
|
||||
nestedFolderStore := ProvideStore(db, cfg)
|
||||
|
||||
b := bus.ProvideBus(tracing.InitializeTracerForTest())
|
||||
ac := acimpl.ProvideAccessControl(cfg)
|
||||
@ -1631,7 +1633,7 @@ func TestIntegrationNestedFolderSharedWithMe(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFolderServiceGetFolder(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db, _ := sqlstore.InitTestDB(t)
|
||||
|
||||
signedInAdminUser := user.SignedInUser{UserID: 1, OrgID: orgID, Permissions: map[int64]map[string][]string{
|
||||
orgID: {
|
||||
@ -1653,9 +1655,9 @@ func TestFolderServiceGetFolder(t *testing.T) {
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
featuresFlagOff := featuremgmt.WithFeatures()
|
||||
dashStore, err := database.ProvideDashboardStore(db, db.Cfg, featuresFlagOff, tagimpl.ProvideService(db), quotaService)
|
||||
dashStore, err := database.ProvideDashboardStore(db, cfg, featuresFlagOff, tagimpl.ProvideService(db), quotaService)
|
||||
require.NoError(t, err)
|
||||
nestedFolderStore := ProvideStore(db, db.Cfg)
|
||||
nestedFolderStore := ProvideStore(db, cfg)
|
||||
|
||||
b := bus.ProvideBus(tracing.InitializeTracerForTest())
|
||||
ac := acimpl.ProvideAccessControl(cfg)
|
||||
@ -1731,16 +1733,14 @@ func TestFolderServiceGetFolder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFolderServiceGetFolders(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
folderStore := ProvideDashboardFolderStore(db)
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
featuresFlagOff := featuremgmt.WithFeatures()
|
||||
dashStore, err := database.ProvideDashboardStore(db, db.Cfg, featuresFlagOff, tagimpl.ProvideService(db), quotaService)
|
||||
dashStore, err := database.ProvideDashboardStore(db, cfg, featuresFlagOff, tagimpl.ProvideService(db), quotaService)
|
||||
require.NoError(t, err)
|
||||
nestedFolderStore := ProvideStore(db, db.Cfg)
|
||||
nestedFolderStore := ProvideStore(db, cfg)
|
||||
|
||||
b := bus.ProvideBus(tracing.InitializeTracerForTest())
|
||||
ac := acimpl.ProvideAccessControl(cfg)
|
||||
@ -1809,7 +1809,7 @@ func TestFolderServiceGetFolders(t *testing.T) {
|
||||
// TODO replace it with an API test under /pkg/tests/api/folders
|
||||
// whenever the golang client with get updated to allow filtering child folders by permission
|
||||
func TestGetChildrenFilterByPermission(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
|
||||
signedInAdminUser := user.SignedInUser{UserID: 1, OrgID: orgID, Permissions: map[int64]map[string][]string{
|
||||
orgID: {
|
||||
@ -1822,12 +1822,10 @@ func TestGetChildrenFilterByPermission(t *testing.T) {
|
||||
quotaService := quotatest.New(false, nil)
|
||||
folderStore := ProvideDashboardFolderStore(db)
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
featuresFlagOff := featuremgmt.WithFeatures()
|
||||
dashStore, err := database.ProvideDashboardStore(db, db.Cfg, featuresFlagOff, tagimpl.ProvideService(db), quotaService)
|
||||
dashStore, err := database.ProvideDashboardStore(db, cfg, featuresFlagOff, tagimpl.ProvideService(db), quotaService)
|
||||
require.NoError(t, err)
|
||||
nestedFolderStore := ProvideStore(db, db.Cfg)
|
||||
nestedFolderStore := ProvideStore(db, cfg)
|
||||
|
||||
b := bus.ProvideBus(tracing.InitializeTracerForTest())
|
||||
ac := acimpl.ProvideAccessControl(cfg)
|
||||
|
@ -31,10 +31,10 @@ func TestIntegrationCreate(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, cfg)
|
||||
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
orgID := CreateOrg(t, db, cfg)
|
||||
|
||||
t.Run("creating a folder without providing a UID should fail", func(t *testing.T) {
|
||||
_, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
|
||||
@ -151,10 +151,10 @@ func TestIntegrationDelete(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, cfg)
|
||||
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
orgID := CreateOrg(t, db, cfg)
|
||||
|
||||
/*
|
||||
t.Run("attempt to delete unknown folder should fail", func(t *testing.T) {
|
||||
@ -198,10 +198,10 @@ func TestIntegrationUpdate(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, cfg)
|
||||
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
orgID := CreateOrg(t, db, cfg)
|
||||
|
||||
// create parent folder
|
||||
parent, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
|
||||
@ -373,10 +373,10 @@ func TestIntegrationGet(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, cfg)
|
||||
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
orgID := CreateOrg(t, db, cfg)
|
||||
|
||||
// create folder
|
||||
uid1 := util.GenerateShortUID()
|
||||
@ -490,10 +490,10 @@ func TestIntegrationGetParents(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, cfg)
|
||||
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
orgID := CreateOrg(t, db, cfg)
|
||||
|
||||
// create folder
|
||||
uid1 := util.GenerateShortUID()
|
||||
@ -558,10 +558,10 @@ func TestIntegrationGetChildren(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, cfg)
|
||||
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
orgID := CreateOrg(t, db, cfg)
|
||||
|
||||
// create folder
|
||||
uid1 := util.GenerateShortUID()
|
||||
@ -738,10 +738,10 @@ func TestIntegrationGetHeight(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, cfg)
|
||||
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
orgID := CreateOrg(t, db, cfg)
|
||||
|
||||
// create folder
|
||||
uid1 := util.GenerateShortUID()
|
||||
@ -771,10 +771,10 @@ func TestIntegrationGetFolders(t *testing.T) {
|
||||
}
|
||||
|
||||
foldersNum := 10
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
db, cfg := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, cfg)
|
||||
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
orgID := CreateOrg(t, db, cfg)
|
||||
|
||||
// create folders
|
||||
uids := make([]string, 0)
|
||||
|
@ -379,22 +379,22 @@ func scenarioWithPanel(t *testing.T, desc string, fn func(t *testing.T, sc scena
|
||||
t.Helper()
|
||||
|
||||
features := featuremgmt.WithFeatures()
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
ac := actest.FakeAccessControl{}
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := database.ProvideDashboardStore(sqlStore, sqlStore.Cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
folderPermissions := acmock.NewMockedPermissionsService()
|
||||
dashboardPermissions := acmock.NewMockedPermissionsService()
|
||||
folderStore := folderimpl.ProvideDashboardFolderStore(sqlStore)
|
||||
dashboardService, svcErr := dashboardservice.ProvideDashboardServiceImpl(
|
||||
sqlStore.Cfg, dashboardStore, folderStore,
|
||||
cfg, dashboardStore, folderStore,
|
||||
features, folderPermissions, dashboardPermissions, ac,
|
||||
foldertest.NewFakeService(),
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, svcErr)
|
||||
guardian.InitAccessControlGuardian(sqlStore.Cfg, ac, dashboardService)
|
||||
guardian.InitAccessControlGuardian(cfg, ac, dashboardService)
|
||||
|
||||
testScenario(t, desc, func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
@ -439,28 +439,28 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
||||
webCtx := web.Context{Req: req}
|
||||
|
||||
features := featuremgmt.WithFeatures()
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := database.ProvideDashboardStore(sqlStore, sqlStore.Cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
ac := acimpl.ProvideAccessControl(sqlStore.Cfg)
|
||||
ac := acimpl.ProvideAccessControl(cfg)
|
||||
folderPermissions := acmock.NewMockedPermissionsService()
|
||||
folderPermissions.On("SetPermissions", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]accesscontrol.ResourcePermission{}, nil)
|
||||
dashboardPermissions := acmock.NewMockedPermissionsService()
|
||||
folderStore := folderimpl.ProvideDashboardFolderStore(sqlStore)
|
||||
dashService, dashSvcErr := dashboardservice.ProvideDashboardServiceImpl(
|
||||
sqlStore.Cfg, dashboardStore, folderStore,
|
||||
cfg, dashboardStore, folderStore,
|
||||
features, folderPermissions, dashboardPermissions, ac,
|
||||
foldertest.NewFakeService(),
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, dashSvcErr)
|
||||
guardian.InitAccessControlGuardian(sqlStore.Cfg, ac, dashService)
|
||||
guardian.InitAccessControlGuardian(cfg, ac, dashService)
|
||||
service := LibraryElementService{
|
||||
Cfg: sqlStore.Cfg,
|
||||
Cfg: cfg,
|
||||
features: featuremgmt.WithFeatures(),
|
||||
SQLStore: sqlStore,
|
||||
folderService: folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), sqlStore.Cfg, dashboardStore, folderStore, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil),
|
||||
folderService: folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, dashboardStore, folderStore, sqlStore, features, supportbundlestest.NewFakeBundleService(), nil),
|
||||
}
|
||||
|
||||
// deliberate difference between signed in user and user in db to make it crystal clear
|
||||
@ -471,9 +471,9 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
||||
Name: "User In DB",
|
||||
Login: userInDbName,
|
||||
}
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgSvc, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgSvc, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
_, err = usrSvc.Create(context.Background(), &cmd)
|
||||
require.NoError(t, err)
|
||||
|
@ -815,7 +815,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
||||
t.Run(desc, func(t *testing.T) {
|
||||
orgID := int64(1)
|
||||
role := org.RoleAdmin
|
||||
sqlStore, cfg := db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
|
||||
ac := actest.FakeAccessControl{ExpectedEvaluate: true}
|
||||
@ -870,9 +870,9 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
||||
Login: userInDbName,
|
||||
}
|
||||
ctx := appcontext.WithUser(context.Background(), usr)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgSvc, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgSvc, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
_, err = usrSvc.Create(context.Background(), &cmd)
|
||||
require.NoError(t, err)
|
||||
|
@ -27,7 +27,6 @@ func ProvideService(db db.DB, cfg *setting.Cfg, quotaService quota.Service) (org
|
||||
db: db,
|
||||
dialect: db.GetDialect(),
|
||||
log: log,
|
||||
cfg: cfg,
|
||||
},
|
||||
cfg: cfg,
|
||||
log: log,
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@ -54,7 +53,6 @@ type sqlStore struct {
|
||||
dialect migrator.Dialect
|
||||
//TODO: moved to service
|
||||
log log.Logger
|
||||
cfg *setting.Cfg
|
||||
deletes []string
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,6 @@ func TestIntegrationOrgUserDataAccess(t *testing.T) {
|
||||
orgUserStore := sqlStore{
|
||||
db: ss,
|
||||
dialect: ss.GetDialect(),
|
||||
cfg: setting.NewCfg(),
|
||||
}
|
||||
|
||||
t.Run("org user inserted", func(t *testing.T) {
|
||||
@ -330,8 +329,8 @@ func TestIntegrationOrgUserDataAccess(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("GetOrgUsers and UpdateOrgUsers", func(t *testing.T) {
|
||||
ss := db.InitTestDB(t)
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||
ss, cfg := db.InitTestDBWithCfg(t)
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, cfg)
|
||||
ac1cmd := &user.CreateUserCommand{Login: "ac1", Email: "ac1@test.com", Name: "ac1 name"}
|
||||
ac2cmd := &user.CreateUserCommand{Login: "ac2", Email: "ac2@test.com", Name: "ac2 name", IsAdmin: true}
|
||||
ac1, err := usrSvc.Create(context.Background(), ac1cmd)
|
||||
@ -475,12 +474,12 @@ func TestIntegrationOrgUserDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Given single org and 2 users inserted", func(t *testing.T) {
|
||||
ss = db.InitTestDB(t)
|
||||
ss.Cfg.AutoAssignOrg = true
|
||||
ss.Cfg.AutoAssignOrgId = 1
|
||||
ss.Cfg.AutoAssignOrgRole = "Viewer"
|
||||
ss, cfg := db.InitTestDBWithCfg(t)
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
cfg.AutoAssignOrgRole = "Viewer"
|
||||
|
||||
orgSvc, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||
orgSvc, usrSvc := createOrgAndUserSvc(t, ss, cfg)
|
||||
|
||||
testUser := &user.SignedInUser{
|
||||
Permissions: map[int64]map[string][]string{
|
||||
@ -535,16 +534,18 @@ func TestIntegrationSQLStore_AddOrgUser(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
store := db.InitTestDB(t)
|
||||
store.Cfg.AutoAssignOrg = true
|
||||
store.Cfg.AutoAssignOrgId = 1
|
||||
store.Cfg.AutoAssignOrgRole = "Viewer"
|
||||
store, cfg := db.InitTestDBWithCfg(t)
|
||||
defer func() {
|
||||
cfg.AutoAssignOrg, cfg.AutoAssignOrgId, cfg.AutoAssignOrgRole = false, 0, ""
|
||||
}()
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
cfg.AutoAssignOrgRole = "Viewer"
|
||||
orgUserStore := sqlStore{
|
||||
db: store,
|
||||
dialect: store.GetDialect(),
|
||||
cfg: setting.NewCfg(),
|
||||
}
|
||||
orgSvc, usrSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
||||
orgSvc, usrSvc := createOrgAndUserSvc(t, store, cfg)
|
||||
|
||||
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||
require.NoError(t, err)
|
||||
@ -604,19 +605,17 @@ func TestIntegration_SQLStore_GetOrgUsers(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
store := db.InitTestDB(t)
|
||||
store, cfg := db.InitTestDBWithCfg(t)
|
||||
orgUserStore := sqlStore{
|
||||
db: store,
|
||||
dialect: store.GetDialect(),
|
||||
cfg: setting.NewCfg(),
|
||||
}
|
||||
orgUserStore.cfg.IsEnterprise = true
|
||||
cfg.IsEnterprise = true
|
||||
defer func() {
|
||||
orgUserStore.cfg.IsEnterprise = false
|
||||
cfg.IsEnterprise = false
|
||||
}()
|
||||
store.Cfg = setting.NewCfg()
|
||||
|
||||
orgSvc, userSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
||||
orgSvc, userSvc := createOrgAndUserSvc(t, store, cfg)
|
||||
|
||||
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||
require.NoError(t, err)
|
||||
@ -724,13 +723,12 @@ func TestIntegration_SQLStore_GetOrgUsers_PopulatesCorrectly(t *testing.T) {
|
||||
userimpl.MockTimeNow(constNow)
|
||||
defer userimpl.ResetTimeNow()
|
||||
|
||||
store := db.InitTestDB(t, sqlstore.InitTestDBOpt{})
|
||||
store, cfg := db.InitTestDBWithCfg(t, sqlstore.InitTestDBOpt{})
|
||||
orgUserStore := sqlStore{
|
||||
db: store,
|
||||
dialect: store.GetDialect(),
|
||||
cfg: setting.NewCfg(),
|
||||
}
|
||||
_, usrSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
||||
_, usrSvc := createOrgAndUserSvc(t, store, cfg)
|
||||
|
||||
id, err := orgUserStore.Insert(context.Background(),
|
||||
&org.Org{
|
||||
@ -786,14 +784,13 @@ func TestIntegration_SQLStore_SearchOrgUsers(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
store := db.InitTestDB(t, sqlstore.InitTestDBOpt{})
|
||||
store, cfg := db.InitTestDBWithCfg(t, sqlstore.InitTestDBOpt{})
|
||||
orgUserStore := sqlStore{
|
||||
db: store,
|
||||
dialect: store.GetDialect(),
|
||||
cfg: setting.NewCfg(),
|
||||
}
|
||||
// orgUserStore.cfg.Skip
|
||||
orgSvc, userSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
||||
orgSvc, userSvc := createOrgAndUserSvc(t, store, cfg)
|
||||
|
||||
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||
require.NoError(t, err)
|
||||
@ -863,13 +860,12 @@ func TestIntegration_SQLStore_RemoveOrgUser(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
store := db.InitTestDB(t)
|
||||
store, cfg := db.InitTestDBWithCfg(t)
|
||||
orgUserStore := sqlStore{
|
||||
db: store,
|
||||
dialect: store.GetDialect(),
|
||||
cfg: setting.NewCfg(),
|
||||
}
|
||||
orgSvc, usrSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
||||
orgSvc, usrSvc := createOrgAndUserSvc(t, store, cfg)
|
||||
|
||||
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: MainOrgName})
|
||||
require.NoError(t, err)
|
||||
|
@ -89,7 +89,8 @@ func TestIntegrationPluginManager(t *testing.T) {
|
||||
pg := postgres.ProvideService(cfg)
|
||||
my := mysql.ProvideService()
|
||||
ms := mssql.ProvideService(cfg)
|
||||
sv2 := searchV2.ProvideService(cfg, db.InitTestDB(t, sqlstore.InitTestDBOpt{Cfg: cfg}), nil, nil, tracer, features, nil, nil, nil)
|
||||
db := db.InitTestDB(t, sqlstore.InitTestDBOpt{Cfg: cfg})
|
||||
sv2 := searchV2.ProvideService(cfg, db, nil, nil, tracer, features, nil, nil, nil)
|
||||
graf := grafanads.ProvideService(sv2, nil)
|
||||
pyroscope := pyroscope.ProvideService(hcp)
|
||||
parca := parca.ProvideService(hcp)
|
||||
|
@ -40,7 +40,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@ -258,7 +257,7 @@ func TestIntegrationUnauthenticatedUserCanGetPubdashPanelQueryData(t *testing.T)
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
db := db.InitTestDB(t)
|
||||
db, cfg := db.InitTestDBWithCfg(t)
|
||||
|
||||
cacheService := datasourcesService.ProvideCacheService(localcache.ProvideService(), db, guardian.ProvideGuardian())
|
||||
qds := buildQueryDataService(t, cacheService, nil, db)
|
||||
@ -300,7 +299,7 @@ func TestIntegrationUnauthenticatedUserCanGetPubdashPanelQueryData(t *testing.T)
|
||||
}
|
||||
|
||||
// create dashboard
|
||||
dashboardStoreService, err := dashboardStore.ProvideDashboardStore(db, db.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(db), quotatest.New(false, nil))
|
||||
dashboardStoreService, err := dashboardStore.ProvideDashboardStore(db, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(db), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
dashboard, err := dashboardStoreService.SaveDashboard(context.Background(), saveDashboardCmd)
|
||||
require.NoError(t, err)
|
||||
@ -318,8 +317,7 @@ func TestIntegrationUnauthenticatedUserCanGetPubdashPanelQueryData(t *testing.T)
|
||||
annotationsService := annotationstest.NewFakeAnnotationsRepo()
|
||||
|
||||
// create public dashboard
|
||||
store := publicdashboardsStore.ProvideStore(db, db.Cfg, featuremgmt.WithFeatures())
|
||||
cfg := setting.NewCfg()
|
||||
store := publicdashboardsStore.ProvideStore(db, cfg, featuremgmt.WithFeatures())
|
||||
cfg.PublicDashboardsEnabled = true
|
||||
ac := acmock.New()
|
||||
ws := publicdashboardsService.ProvideServiceWrapper(store)
|
||||
|
@ -63,7 +63,7 @@ func TestIntegrationListPublicDashboard(t *testing.T) {
|
||||
var publicdashboardStore *PublicDashboardStoreImpl
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t, db.InitTestDBOpt{})
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t, db.InitTestDBOpt{})
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
@ -178,7 +178,7 @@ func TestIntegrationExistsEnabledByAccessToken(t *testing.T) {
|
||||
var savedDashboard *dashboards.Dashboard
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
store, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
@ -251,7 +251,7 @@ func TestIntegrationExistsEnabledByDashboardUid(t *testing.T) {
|
||||
var savedDashboard *dashboards.Dashboard
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
store, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
@ -316,7 +316,7 @@ func TestIntegrationFindByDashboardUid(t *testing.T) {
|
||||
var savedDashboard *dashboards.Dashboard
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
store, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
@ -385,7 +385,7 @@ func TestIntegrationFindByAccessToken(t *testing.T) {
|
||||
var err error
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
dashboardStore, err = dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
@ -453,7 +453,7 @@ func TestIntegrationCreatePublicDashboard(t *testing.T) {
|
||||
var savedDashboard2 *dashboards.Dashboard
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t, db.InitTestDBOpt{})
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t, db.InitTestDBOpt{})
|
||||
quotaService := quotatest.New(false, nil)
|
||||
store, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
@ -533,7 +533,7 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
|
||||
var err error
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t, db.InitTestDBOpt{})
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t, db.InitTestDBOpt{})
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err = dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
@ -637,7 +637,7 @@ func TestIntegrationGetOrgIdByAccessToken(t *testing.T) {
|
||||
var err error
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err = dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
@ -710,7 +710,7 @@ func TestIntegrationDelete(t *testing.T) {
|
||||
var err error
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
dashboardStore, err = dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
@ -742,9 +742,9 @@ func TestIntegrationDelete(t *testing.T) {
|
||||
|
||||
func TestFindByFolder(t *testing.T) {
|
||||
t.Run("returns nil when dashboard is not a folder", func(t *testing.T) {
|
||||
sqlStore, _ := db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
dashboard := &dashboards.Dashboard{OrgID: 1, UID: "dashboarduid", IsFolder: false}
|
||||
store := ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
||||
store := ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
pubdashes, err := store.FindByFolder(context.Background(), dashboard.OrgID, dashboard.UID)
|
||||
|
||||
require.NoError(t, err)
|
||||
@ -752,8 +752,8 @@ func TestFindByFolder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("returns nil when parameters are empty", func(t *testing.T) {
|
||||
sqlStore, _ := db.InitTestDBwithCfg(t)
|
||||
store := ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
store := ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
pubdashes, err := store.FindByFolder(context.Background(), 0, "")
|
||||
|
||||
require.NoError(t, err)
|
||||
@ -761,11 +761,11 @@ func TestFindByFolder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("can get all pubdashes for dashboard folder and org", func(t *testing.T) {
|
||||
sqlStore, _ := db.InitTestDBwithCfg(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
pubdashStore := ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
||||
pubdashStore := ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
// insert folders
|
||||
folder := insertTestDashboard(t, dashboardStore, "This is a folder", 1, "", true, PublicShareType)
|
||||
folder2 := insertTestDashboard(t, dashboardStore, "This is another folder", 1, "", true, PublicShareType)
|
||||
@ -800,7 +800,7 @@ func TestGetMetrics(t *testing.T) {
|
||||
var savedDashboard4 *dashboards.Dashboard
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBwithCfg(t, db.InitTestDBOpt{})
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t, db.InitTestDBOpt{})
|
||||
quotaService := quotatest.New(false, nil)
|
||||
store, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards/database"
|
||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards/service/intervalv2"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
@ -27,14 +26,14 @@ func newPublicDashboardServiceImpl(
|
||||
) (*PublicDashboardServiceImpl, db.DB, *setting.Cfg) {
|
||||
t.Helper()
|
||||
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db, cfg := db.InitTestDBWithCfg(t)
|
||||
tagService := tagimpl.ProvideService(db)
|
||||
if annotationsRepo == nil {
|
||||
annotationsRepo = annotationsimpl.ProvideService(db, db.Cfg, featuremgmt.WithFeatures(), tagService)
|
||||
annotationsRepo = annotationsimpl.ProvideService(db, cfg, featuremgmt.WithFeatures(), tagService)
|
||||
}
|
||||
|
||||
if publicDashboardStore == nil {
|
||||
publicDashboardStore = database.ProvideStore(db, db.Cfg, featuremgmt.WithFeatures())
|
||||
publicDashboardStore = database.ProvideStore(db, cfg, featuremgmt.WithFeatures())
|
||||
}
|
||||
serviceWrapper := ProvideServiceWrapper(publicDashboardStore)
|
||||
|
||||
@ -50,5 +49,5 @@ func newPublicDashboardServiceImpl(
|
||||
serviceWrapper: serviceWrapper,
|
||||
license: license,
|
||||
features: featuremgmt.WithFeatures(),
|
||||
}, db, db.Cfg
|
||||
}, db, cfg
|
||||
}
|
||||
|
@ -1320,8 +1320,8 @@ func TestBuildMetricRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuildAnonymousUser(t *testing.T) {
|
||||
sqlStore := db.InitTestDB(t)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||
features := featuremgmt.WithFeatures()
|
||||
|
@ -465,7 +465,7 @@ func setup(t *testing.T) *testContext {
|
||||
dc := &fakeDataSourceCache{cache: dss}
|
||||
rv := &fakePluginRequestValidator{}
|
||||
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
secretsService := secretsmng.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||
ss := secretskvs.NewSQLSecretsKVStore(sqlStore, secretsService, log.New("test.logger"))
|
||||
fakeDatasourceService := &fakeDatasources.FakeDataSourceService{
|
||||
@ -473,7 +473,7 @@ func setup(t *testing.T) *testContext {
|
||||
SimulatePluginFailure: false,
|
||||
}
|
||||
|
||||
pCtxProvider := plugincontext.ProvideService(sqlStore.Cfg,
|
||||
pCtxProvider := plugincontext.ProvideService(cfg,
|
||||
localcache.ProvideService(), &pluginstore.FakePluginStore{
|
||||
PluginList: []pluginstore.Plugin{
|
||||
{JSONData: plugins.JSONData{ID: "postgres"}},
|
||||
|
@ -55,7 +55,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
||||
Form: url.Values{},
|
||||
}}
|
||||
ctx.Req.Header.Add("Content-Type", "application/json")
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
service := QueryHistoryService{
|
||||
Cfg: setting.NewCfg(),
|
||||
store: sqlStore,
|
||||
@ -63,9 +63,9 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
||||
}
|
||||
service.Cfg.QueryHistoryEnabled = true
|
||||
quotaService := quotatest.New(false, nil)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgSvc, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgSvc, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
|
||||
usr := user.SignedInUser{
|
||||
|
@ -39,7 +39,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/secrets/fakes"
|
||||
secretskvs "github.com/grafana/grafana/pkg/services/secrets/kvstore"
|
||||
secretsmng "github.com/grafana/grafana/pkg/services/secrets/manager"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
storesrv "github.com/grafana/grafana/pkg/services/store"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
@ -65,8 +64,8 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
sqlStore := sqlstore.InitTestDB(t)
|
||||
sqlStore.Cfg.Quota = setting.QuotaSettings{
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
cfg.Quota = setting.QuotaSettings{
|
||||
Enabled: true,
|
||||
|
||||
Org: setting.OrgQuota{
|
||||
@ -92,12 +91,12 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) {
|
||||
}
|
||||
|
||||
b := bus.ProvideBus(tracing.InitializeTracerForTest())
|
||||
quotaService := ProvideService(sqlStore, sqlStore.Cfg)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
quotaService := ProvideService(sqlStore, cfg)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userService, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
userService, err := userimpl.ProvideService(sqlStore, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
setupEnv(t, sqlStore, sqlStore.Cfg, b, quotaService)
|
||||
setupEnv(t, sqlStore, cfg, b, quotaService)
|
||||
|
||||
u, err := userService.Create(context.Background(), &user.CreateUserCommand{
|
||||
Name: "TestUser",
|
||||
@ -126,28 +125,28 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) {
|
||||
}
|
||||
tag, err := quota.NewTag(quota.TargetSrv(org.QuotaTargetSrv), quota.Target(org.OrgQuotaTarget), scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Global.Org, defaultGlobalLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Global.Org, defaultGlobalLimits[tag])
|
||||
tag, err = quota.NewTag(quota.TargetSrv(user.QuotaTargetSrv), quota.Target(user.QuotaTarget), scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Global.User, defaultGlobalLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Global.User, defaultGlobalLimits[tag])
|
||||
tag, err = quota.NewTag(dashboards.QuotaTargetSrv, dashboards.QuotaTarget, scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Global.Dashboard, defaultGlobalLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Global.Dashboard, defaultGlobalLimits[tag])
|
||||
tag, err = quota.NewTag(datasources.QuotaTargetSrv, datasources.QuotaTarget, scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Global.DataSource, defaultGlobalLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Global.DataSource, defaultGlobalLimits[tag])
|
||||
tag, err = quota.NewTag(apikey.QuotaTargetSrv, apikey.QuotaTarget, scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Global.ApiKey, defaultGlobalLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Global.ApiKey, defaultGlobalLimits[tag])
|
||||
tag, err = quota.NewTag(auth.QuotaTargetSrv, auth.QuotaTarget, scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Global.Session, defaultGlobalLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Global.Session, defaultGlobalLimits[tag])
|
||||
tag, err = quota.NewTag(ngalertmodels.QuotaTargetSrv, ngalertmodels.QuotaTarget, scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Global.AlertRule, defaultGlobalLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Global.AlertRule, defaultGlobalLimits[tag])
|
||||
tag, err = quota.NewTag(storesrv.QuotaTargetSrv, storesrv.QuotaTarget, scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Global.File, defaultGlobalLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Global.File, defaultGlobalLimits[tag])
|
||||
|
||||
// fetch default limit/usage for org
|
||||
defaultOrgLimits := make(map[quota.Tag]int64)
|
||||
@ -163,19 +162,19 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) {
|
||||
}
|
||||
tag, err = quota.NewTag(quota.TargetSrv(org.QuotaTargetSrv), quota.Target(org.OrgUserQuotaTarget), scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Org.User, defaultOrgLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Org.User, defaultOrgLimits[tag])
|
||||
tag, err = quota.NewTag(dashboards.QuotaTargetSrv, dashboards.QuotaTarget, scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Org.Dashboard, defaultOrgLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Org.Dashboard, defaultOrgLimits[tag])
|
||||
tag, err = quota.NewTag(datasources.QuotaTargetSrv, datasources.QuotaTarget, scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Org.DataSource, defaultOrgLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Org.DataSource, defaultOrgLimits[tag])
|
||||
tag, err = quota.NewTag(apikey.QuotaTargetSrv, apikey.QuotaTarget, scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Org.ApiKey, defaultOrgLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Org.ApiKey, defaultOrgLimits[tag])
|
||||
tag, err = quota.NewTag(ngalertmodels.QuotaTargetSrv, ngalertmodels.QuotaTarget, scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.Org.AlertRule, defaultOrgLimits[tag])
|
||||
require.Equal(t, cfg.Quota.Org.AlertRule, defaultOrgLimits[tag])
|
||||
|
||||
// fetch default limit/usage for user
|
||||
defaultUserLimits := make(map[quota.Tag]int64)
|
||||
@ -191,7 +190,7 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) {
|
||||
}
|
||||
tag, err = quota.NewTag(quota.TargetSrv(org.QuotaTargetSrv), quota.Target(org.OrgUserQuotaTarget), scope)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sqlStore.Cfg.Quota.User.Org, defaultUserLimits[tag])
|
||||
require.Equal(t, cfg.Quota.User.Org, defaultUserLimits[tag])
|
||||
|
||||
t.Run("Given saved org quota for users", func(t *testing.T) {
|
||||
// update quota for the created org and limit users to 1
|
||||
@ -225,10 +224,13 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) {
|
||||
|
||||
t.Run("Should be able to get zero used org alert quota when table does not exist (ngalert is not enabled - default case)", func(t *testing.T) {
|
||||
// disable Grafana Alerting
|
||||
cfg := *sqlStore.Cfg
|
||||
alertingCfg := cfg.UnifiedAlerting
|
||||
defer func() {
|
||||
cfg.UnifiedAlerting = alertingCfg
|
||||
}()
|
||||
cfg.UnifiedAlerting = setting.UnifiedAlertingSettings{Enabled: util.Pointer(false)}
|
||||
|
||||
quotaSrv := ProvideService(sqlStore, &cfg)
|
||||
quotaSrv := ProvideService(sqlStore, cfg)
|
||||
q, err := getQuotaBySrvTargetScope(t, quotaSrv, ngalertmodels.QuotaTargetSrv, ngalertmodels.QuotaTarget, quota.OrgScope, "a.ScopeParameters{OrgID: o.ID})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
@ -221,8 +221,7 @@ func TestStore_DeleteServiceAccount(t *testing.T) {
|
||||
|
||||
func setupTestDatabase(t *testing.T) (db.DB, *ServiceAccountsStoreImpl) {
|
||||
t.Helper()
|
||||
db := db.InitTestDB(t)
|
||||
cfg := db.Cfg
|
||||
db, cfg := db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
apiKeyService, err := apikeyimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
|
@ -64,7 +64,7 @@ func TestIntegrationBulkOps(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
db := InitTestDB(t)
|
||||
db, _ := InitTestDB(t)
|
||||
err := db.engine.Sync(new(bulkTestItem))
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -697,13 +697,13 @@ func setupTest(t *testing.T, numFolders, numDashboards int, permissions []access
|
||||
func setupNestedTest(t *testing.T, usr *user.SignedInUser, perms []accesscontrol.Permission, orgID int64, features featuremgmt.FeatureToggles) db.DB {
|
||||
t.Helper()
|
||||
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db, cfg := db.InitTestDBWithCfg(t)
|
||||
|
||||
// dashboard store commands that should be called.
|
||||
dashStore, err := database.ProvideDashboardStore(db, db.Cfg, features, tagimpl.ProvideService(db), quotatest.New(false, nil))
|
||||
dashStore, err := database.ProvideDashboardStore(db, cfg, features, tagimpl.ProvideService(db), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
|
||||
folderSvc := folderimpl.ProvideService(mock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), db.Cfg, dashStore, folderimpl.ProvideDashboardFolderStore(db), db, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
folderSvc := folderimpl.ProvideService(mock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, dashStore, folderimpl.ProvideDashboardFolderStore(db), db, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
|
||||
// create parent folder
|
||||
parent, err := folderSvc.Create(context.Background(), &folder.CreateFolderCommand{
|
||||
|
@ -77,14 +77,14 @@ func setupBenchMark(b *testing.B, usr user.SignedInUser, features featuremgmt.Fe
|
||||
nestingLevel = folder.MaxNestedFolderDepth
|
||||
}
|
||||
|
||||
store := db.InitTestDB(b)
|
||||
store, cfg := db.InitTestDBWithCfg(b)
|
||||
|
||||
quotaService := quotatest.New(false, nil)
|
||||
|
||||
dashboardWriteStore, err := database.ProvideDashboardStore(store, store.Cfg, features, tagimpl.ProvideService(store), quotaService)
|
||||
dashboardWriteStore, err := database.ProvideDashboardStore(store, cfg, features, tagimpl.ProvideService(store), quotaService)
|
||||
require.NoError(b, err)
|
||||
|
||||
folderSvc := folderimpl.ProvideService(mock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), store.Cfg, dashboardWriteStore, folderimpl.ProvideDashboardFolderStore(store), store, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
folderSvc := folderimpl.ProvideService(mock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, dashboardWriteStore, folderimpl.ProvideDashboardFolderStore(store), store, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
|
||||
origNewGuardian := guardian.New
|
||||
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{CanViewValue: true, CanSaveValue: true})
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestRetryingDisabled(t *testing.T) {
|
||||
store := InitTestDB(t)
|
||||
store, _ := InitTestDB(t)
|
||||
require.Equal(t, 0, store.dbCfg.QueryRetries)
|
||||
|
||||
funcToTest := map[string]func(ctx context.Context, callback DBTransactionFunc) error{
|
||||
@ -63,7 +63,7 @@ func TestRetryingDisabled(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRetryingOnFailures(t *testing.T) {
|
||||
store := InitTestDB(t)
|
||||
store, _ := InitTestDB(t)
|
||||
store.dbCfg.QueryRetries = 5
|
||||
|
||||
funcToTest := map[string]func(ctx context.Context, callback DBTransactionFunc) error{
|
||||
|
@ -37,7 +37,7 @@ import (
|
||||
type ContextSessionKey struct{}
|
||||
|
||||
type SQLStore struct {
|
||||
Cfg *setting.Cfg
|
||||
cfg *setting.Cfg
|
||||
features featuremgmt.FeatureToggles
|
||||
sqlxsession *session.SessionDB
|
||||
|
||||
@ -45,7 +45,7 @@ type SQLStore struct {
|
||||
dbCfg *DatabaseConfig
|
||||
engine *xorm.Engine
|
||||
log log.Logger
|
||||
Dialect migrator.Dialect
|
||||
dialect migrator.Dialect
|
||||
skipEnsureDefaultOrgAndUser bool
|
||||
migrations registry.DatabaseMigrator
|
||||
tracer tracing.Tracer
|
||||
@ -114,7 +114,7 @@ func NewSQLStoreWithoutSideEffects(cfg *setting.Cfg,
|
||||
func newSQLStore(cfg *setting.Cfg, engine *xorm.Engine,
|
||||
migrations registry.DatabaseMigrator, bus bus.Bus, tracer tracing.Tracer, opts ...InitTestDBOpt) (*SQLStore, error) {
|
||||
ss := &SQLStore{
|
||||
Cfg: cfg,
|
||||
cfg: cfg,
|
||||
log: log.New("sqlstore"),
|
||||
skipEnsureDefaultOrgAndUser: false,
|
||||
migrations: migrations,
|
||||
@ -131,7 +131,7 @@ func newSQLStore(cfg *setting.Cfg, engine *xorm.Engine,
|
||||
return nil, fmt.Errorf("%v: %w", "failed to connect to database", err)
|
||||
}
|
||||
|
||||
ss.Dialect = migrator.NewDialect(ss.engine.DriverName())
|
||||
ss.dialect = migrator.NewDialect(ss.engine.DriverName())
|
||||
|
||||
// if err := ss.Reset(); err != nil {
|
||||
// return nil, err
|
||||
@ -155,7 +155,7 @@ func (ss *SQLStore) Migrate(isDatabaseLockingEnabled bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
migrator := migrator.NewMigrator(ss.engine, ss.Cfg)
|
||||
migrator := migrator.NewMigrator(ss.engine, ss.cfg)
|
||||
ss.migrations.AddMigration(migrator)
|
||||
|
||||
return migrator.Start(isDatabaseLockingEnabled, ss.dbCfg.MigrationLockAttemptTimeout)
|
||||
@ -178,7 +178,7 @@ func (ss *SQLStore) Quote(value string) string {
|
||||
|
||||
// GetDialect return the dialect
|
||||
func (ss *SQLStore) GetDialect() migrator.Dialect {
|
||||
return ss.Dialect
|
||||
return ss.dialect
|
||||
}
|
||||
|
||||
func (ss *SQLStore) GetDBType() core.DbType {
|
||||
@ -210,7 +210,7 @@ func (ss *SQLStore) ensureMainOrgAndAdminUser(test bool) error {
|
||||
var stats stats.SystemUserCountStats
|
||||
// TODO: Should be able to rename "Count" to "count", for more standard SQL style
|
||||
// Just have to make sure it gets deserialized properly into models.SystemUserCountStats
|
||||
rawSQL := `SELECT COUNT(id) AS Count FROM ` + ss.Dialect.Quote("user")
|
||||
rawSQL := `SELECT COUNT(id) AS Count FROM ` + ss.dialect.Quote("user")
|
||||
if _, err := sess.SQL(rawSQL).Get(&stats); err != nil {
|
||||
return fmt.Errorf("could not determine if admin user exists: %w", err)
|
||||
}
|
||||
@ -220,19 +220,19 @@ func (ss *SQLStore) ensureMainOrgAndAdminUser(test bool) error {
|
||||
}
|
||||
|
||||
// ensure admin user
|
||||
if !ss.Cfg.DisableInitAdminCreation {
|
||||
if !ss.cfg.DisableInitAdminCreation {
|
||||
ss.log.Debug("Creating default admin user")
|
||||
|
||||
if _, err := ss.createUser(ctx, sess, user.CreateUserCommand{
|
||||
Login: ss.Cfg.AdminUser,
|
||||
Email: ss.Cfg.AdminEmail,
|
||||
Password: user.Password(ss.Cfg.AdminPassword),
|
||||
Login: ss.cfg.AdminUser,
|
||||
Email: ss.cfg.AdminEmail,
|
||||
Password: user.Password(ss.cfg.AdminPassword),
|
||||
IsAdmin: true,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("failed to create admin user: %s", err)
|
||||
}
|
||||
|
||||
ss.log.Info("Created default admin", "user", ss.Cfg.AdminUser)
|
||||
ss.log.Info("Created default admin", "user", ss.cfg.AdminUser)
|
||||
}
|
||||
|
||||
ss.log.Debug("Creating default org", "name", mainOrgName)
|
||||
@ -254,14 +254,14 @@ func (ss *SQLStore) initEngine(engine *xorm.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
dbCfg, err := NewDatabaseConfig(ss.Cfg, ss.features)
|
||||
dbCfg, err := NewDatabaseConfig(ss.cfg, ss.features)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ss.dbCfg = dbCfg
|
||||
|
||||
if ss.Cfg.DatabaseInstrumentQueries {
|
||||
if ss.cfg.DatabaseInstrumentQueries {
|
||||
ss.dbCfg.Type = WrapDatabaseDriverWithHooks(ss.dbCfg.Type, ss.tracer)
|
||||
}
|
||||
|
||||
@ -316,7 +316,7 @@ func (ss *SQLStore) initEngine(engine *xorm.Engine) error {
|
||||
engine.SetConnMaxLifetime(time.Second * time.Duration(ss.dbCfg.ConnMaxLifetime))
|
||||
|
||||
// configure sql logging
|
||||
debugSQL := ss.Cfg.Raw.Section("database").Key("log_queries").MustBool(false)
|
||||
debugSQL := ss.cfg.Raw.Section("database").Key("log_queries").MustBool(false)
|
||||
if !debugSQL {
|
||||
engine.SetLogger(&xorm.DiscardLogger{})
|
||||
} else {
|
||||
@ -425,7 +425,7 @@ func InitTestDBWithMigration(t sqlutil.ITestDB, migration registry.DatabaseMigra
|
||||
}
|
||||
|
||||
// InitTestDB initializes the test DB.
|
||||
func InitTestDB(t sqlutil.ITestDB, opts ...InitTestDBOpt) *SQLStore {
|
||||
func InitTestDB(t sqlutil.ITestDB, opts ...InitTestDBOpt) (*SQLStore, *setting.Cfg) {
|
||||
t.Helper()
|
||||
features := getFeaturesForTesting(opts...)
|
||||
cfg := getCfgForTesting(opts...)
|
||||
@ -434,7 +434,7 @@ func InitTestDB(t sqlutil.ITestDB, opts ...InitTestDBOpt) *SQLStore {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to initialize sql store: %s", err)
|
||||
}
|
||||
return store
|
||||
return store, store.cfg
|
||||
}
|
||||
|
||||
func SetupTestDB() {
|
||||
@ -605,9 +605,9 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
// nolint:staticcheck
|
||||
testSQLStore.Cfg.IsFeatureToggleEnabled = features.IsEnabledGlobally
|
||||
testSQLStore.cfg.IsFeatureToggleEnabled = features.IsEnabledGlobally
|
||||
|
||||
if err := testSQLStore.Dialect.TruncateDBTables(testSQLStore.GetEngine()); err != nil {
|
||||
if err := testSQLStore.dialect.TruncateDBTables(testSQLStore.GetEngine()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := testSQLStore.Reset(); err != nil {
|
||||
|
@ -20,7 +20,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestIntegrationIsUniqueConstraintViolation(t *testing.T) {
|
||||
store := InitTestDB(t)
|
||||
store, _ := InitTestDB(t)
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
@ -32,12 +32,12 @@ func TestIntegrationIsUniqueConstraintViolation(t *testing.T) {
|
||||
// Attempt to insert org with provided ID (primary key) twice
|
||||
now := time.Now()
|
||||
org := org.Org{Name: "test org primary key violation", Created: now, Updated: now, ID: 42}
|
||||
err := sess.InsertId(&org, store.Dialect)
|
||||
err := sess.InsertId(&org, store.dialect)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Provide a different name to avoid unique constraint violation
|
||||
org.Name = "test org 2"
|
||||
return sess.InsertId(&org, store.Dialect)
|
||||
return sess.InsertId(&org, store.dialect)
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -46,12 +46,12 @@ func TestIntegrationIsUniqueConstraintViolation(t *testing.T) {
|
||||
// Attempt to insert org with reserved name
|
||||
now := time.Now()
|
||||
org := org.Org{Name: "test org unique constrain violation", Created: now, Updated: now, ID: 43}
|
||||
err := sess.InsertId(&org, store.Dialect)
|
||||
err := sess.InsertId(&org, store.dialect)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Provide a different ID to avoid primary key violation
|
||||
org.ID = 44
|
||||
return sess.InsertId(&org, store.Dialect)
|
||||
return sess.InsertId(&org, store.dialect)
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -62,7 +62,7 @@ func TestIntegrationIsUniqueConstraintViolation(t *testing.T) {
|
||||
return tc.f(t, sess)
|
||||
})
|
||||
require.Error(t, err)
|
||||
assert.True(t, store.Dialect.IsUniqueConstraintViolation(err))
|
||||
assert.True(t, store.dialect.IsUniqueConstraintViolation(err))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ func TestIntegrationReuseSessionWithTransaction(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
ss := InitTestDB(t)
|
||||
ss, _ := InitTestDB(t)
|
||||
|
||||
t.Run("top level transaction", func(t *testing.T) {
|
||||
var outerSession *DBSession
|
||||
@ -73,7 +73,7 @@ func TestIntegrationPublishAfterCommitWithNestedTransactions(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
ss := InitTestDB(t)
|
||||
ss, _ := InitTestDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
// On X success
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
const mainOrgName = "Main Org."
|
||||
|
||||
func (ss *SQLStore) getOrgIDForNewUser(sess *DBSession, args user.CreateUserCommand) (int64, error) {
|
||||
if ss.Cfg.AutoAssignOrg && args.OrgID != 0 {
|
||||
if ss.cfg.AutoAssignOrg && args.OrgID != 0 {
|
||||
if err := verifyExistingOrg(sess, args.OrgID); err != nil {
|
||||
return -1, err
|
||||
}
|
||||
@ -114,11 +114,11 @@ func (ss *SQLStore) createUser(ctx context.Context, sess *DBSession, args user.C
|
||||
Updated: time.Now(),
|
||||
}
|
||||
|
||||
if ss.Cfg.AutoAssignOrg && !usr.IsAdmin {
|
||||
if ss.cfg.AutoAssignOrg && !usr.IsAdmin {
|
||||
if len(args.DefaultOrgRole) > 0 {
|
||||
orgUser.Role = org.RoleType(args.DefaultOrgRole)
|
||||
} else {
|
||||
orgUser.Role = org.RoleType(ss.Cfg.AutoAssignOrgRole)
|
||||
orgUser.Role = org.RoleType(ss.cfg.AutoAssignOrgRole)
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,8 +144,8 @@ func verifyExistingOrg(sess *DBSession, orgId int64) error {
|
||||
func (ss *SQLStore) getOrCreateOrg(sess *DBSession, orgName string) (int64, error) {
|
||||
var org org.Org
|
||||
|
||||
if ss.Cfg.AutoAssignOrg {
|
||||
has, err := sess.Where("id=?", ss.Cfg.AutoAssignOrgId).Get(&org)
|
||||
if ss.cfg.AutoAssignOrg {
|
||||
has, err := sess.Where("id=?", ss.cfg.AutoAssignOrgId).Get(&org)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -154,18 +154,18 @@ func (ss *SQLStore) getOrCreateOrg(sess *DBSession, orgName string) (int64, erro
|
||||
}
|
||||
ss.log.Debug("auto assigned organization not found")
|
||||
|
||||
if ss.Cfg.AutoAssignOrgId != 1 {
|
||||
if ss.cfg.AutoAssignOrgId != 1 {
|
||||
ss.log.Error("Could not create user: organization ID does not exist", "orgID",
|
||||
ss.Cfg.AutoAssignOrgId)
|
||||
ss.cfg.AutoAssignOrgId)
|
||||
return 0, fmt.Errorf("could not create user: organization ID %d does not exist",
|
||||
ss.Cfg.AutoAssignOrgId)
|
||||
ss.cfg.AutoAssignOrgId)
|
||||
}
|
||||
|
||||
org.Name = mainOrgName
|
||||
org.Created = time.Now()
|
||||
org.Updated = org.Created
|
||||
org.ID = int64(ss.Cfg.AutoAssignOrgId)
|
||||
if err := sess.InsertId(&org, ss.Dialect); err != nil {
|
||||
org.ID = int64(ss.cfg.AutoAssignOrgId)
|
||||
if err := sess.InsertId(&org, ss.dialect); err != nil {
|
||||
ss.log.Error("failed to insert organization with provided id", "org_id", org.ID, "err", err)
|
||||
// ignore failure if for some reason the organization exists
|
||||
if ss.GetDialect().IsUniqueConstraintViolation(err) {
|
||||
|
@ -14,13 +14,13 @@ func TestIntegrationGetOrCreateOrg(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping integration test in short mode")
|
||||
}
|
||||
ss := InitTestDB(t)
|
||||
ss, _ := InitTestDB(t)
|
||||
|
||||
err := ss.WithNewDbSession(context.Background(), func(sess *DBSession) error {
|
||||
// Create the org only:
|
||||
ss.Cfg.AutoAssignOrg = true
|
||||
ss.Cfg.DisableInitAdminCreation = true
|
||||
ss.Cfg.AutoAssignOrgId = 1
|
||||
ss.cfg.AutoAssignOrg = true
|
||||
ss.cfg.DisableInitAdminCreation = true
|
||||
ss.cfg.AutoAssignOrgId = 1
|
||||
createdOrgID, err := ss.getOrCreateOrg(sess, mainOrgName)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(1), createdOrgID)
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/stats"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@ -33,9 +32,9 @@ func TestIntegrationStatsDataAccess(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db, cfg := db.InitTestDBWithCfg(t)
|
||||
statsService := &sqlStatsService{db: db}
|
||||
populateDB(t, db, db.Cfg)
|
||||
populateDB(t, db, cfg)
|
||||
|
||||
t.Run("Get system stats should not results in error", func(t *testing.T) {
|
||||
query := stats.GetSystemStatsQuery{}
|
||||
@ -50,7 +49,7 @@ func TestIntegrationStatsDataAccess(t *testing.T) {
|
||||
assert.Equal(t, int64(0), result.APIKeys)
|
||||
assert.Equal(t, int64(2), result.Correlations)
|
||||
assert.NotNil(t, result.DatabaseCreatedTime)
|
||||
assert.Equal(t, db.Dialect.DriverName(), result.DatabaseDriver)
|
||||
assert.Equal(t, db.GetDialect().DriverName(), result.DatabaseDriver)
|
||||
})
|
||||
|
||||
t.Run("Get system user count stats should not results in error", func(t *testing.T) {
|
||||
@ -155,8 +154,8 @@ func TestIntegration_GetAdminStats(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
db := sqlstore.InitTestDB(t)
|
||||
statsService := ProvideService(&setting.Cfg{}, db)
|
||||
db, cfg := db.InitTestDBWithCfg(t)
|
||||
statsService := ProvideService(cfg, db)
|
||||
|
||||
query := stats.GetAdminStatsQuery{}
|
||||
_, err := statsService.GetAdminStats(context.Background(), &query)
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity/db/dbimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
)
|
||||
|
||||
@ -125,15 +124,15 @@ func TestCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
func setUpTestServer(t *testing.T) entity.EntityStoreServer {
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
|
||||
entityDB, err := dbimpl.ProvideEntityDB(
|
||||
sqlStore,
|
||||
setting.NewCfg(),
|
||||
cfg,
|
||||
featuremgmt.WithFeatures(featuremgmt.FlagUnifiedStorage))
|
||||
require.NoError(t, err)
|
||||
|
||||
traceConfig, err := tracing.ParseTracingConfig(sqlStore.Cfg)
|
||||
traceConfig, err := tracing.ParseTracingConfig(cfg)
|
||||
require.NoError(t, err)
|
||||
tracer, err := tracing.ProvideService(traceConfig)
|
||||
require.NoError(t, err)
|
||||
|
@ -34,8 +34,8 @@ func TestIntegrationTeamCommandsAndQueries(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
t.Run("Testing Team commands and queries", func(t *testing.T) {
|
||||
sqlStore := db.InitTestDB(t)
|
||||
teamSvc, err := ProvideService(sqlStore, sqlStore.Cfg)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
teamSvc, err := ProvideService(sqlStore, cfg)
|
||||
require.NoError(t, err)
|
||||
testUser := &user.SignedInUser{
|
||||
OrgID: 1,
|
||||
@ -47,10 +47,10 @@ func TestIntegrationTeamCommandsAndQueries(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userSvc, err := userimpl.ProvideService(sqlStore, orgSvc, sqlStore.Cfg, teamSvc, nil, quotaService,
|
||||
userSvc, err := userimpl.ProvideService(sqlStore, orgSvc, cfg, teamSvc, nil, quotaService,
|
||||
supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -401,10 +401,10 @@ 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, sqlStore.Cfg)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
orgSvc, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userSvc, err := userimpl.ProvideService(sqlStore, orgSvc, sqlStore.Cfg, teamSvc, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
userSvc, err := userimpl.ProvideService(sqlStore, orgSvc, cfg, teamSvc, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
setup()
|
||||
userCmd = user.CreateUserCommand{
|
||||
@ -489,8 +489,8 @@ func TestIntegrationSQLStore_SearchTeams(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
store := db.InitTestDB(t, db.InitTestDBOpt{})
|
||||
teamSvc, err := ProvideService(store, store.Cfg)
|
||||
store, cfg := db.InitTestDBWithCfg(t, db.InitTestDBOpt{})
|
||||
teamSvc, err := ProvideService(store, cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Seed 10 teams
|
||||
@ -560,9 +560,9 @@ func TestIntegrationSQLStore_GetTeamMembers_ACFilter(t *testing.T) {
|
||||
require.NoError(t, errAddMember)
|
||||
}
|
||||
|
||||
store := db.InitTestDB(t, db.InitTestDBOpt{})
|
||||
setup(store, store.Cfg)
|
||||
teamSvc, err := ProvideService(store, store.Cfg)
|
||||
store, cfg := db.InitTestDBWithCfg(t, db.InitTestDBOpt{})
|
||||
setup(store, cfg)
|
||||
teamSvc, err := ProvideService(store, cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
type getTeamMembersTestCase struct {
|
||||
|
@ -31,8 +31,8 @@ func TestIntegrationTempUserCommandsAndQueries(t *testing.T) {
|
||||
Status: tempuser.TmpUserInvitePending,
|
||||
}
|
||||
setup := func(t *testing.T) {
|
||||
db := db.InitTestDB(t)
|
||||
store = &xormStore{db: db, cfg: db.Cfg}
|
||||
db, cfg := db.InitTestDBWithCfg(t)
|
||||
store = &xormStore{db: db, cfg: cfg}
|
||||
tempUser, err = store.CreateTempUser(context.Background(), &cmd)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
@ -112,8 +112,8 @@ func TestIntegrationTempUserCommandsAndQueries(t *testing.T) {
|
||||
Status: tempuser.TmpUserEmailUpdateStarted,
|
||||
InvitedByUserID: userID,
|
||||
}
|
||||
db := db.InitTestDB(t)
|
||||
store = &xormStore{db: db, cfg: db.Cfg}
|
||||
db, cfg := db.InitTestDBWithCfg(t)
|
||||
store = &xormStore{db: db, cfg: cfg}
|
||||
|
||||
for i := 0; i < verifications; i++ {
|
||||
tempUser, err = store.CreateTempUser(context.Background(), &cmd)
|
||||
@ -152,8 +152,8 @@ func TestIntegrationTempUserCommandsAndQueries(t *testing.T) {
|
||||
Status: tempuser.TmpUserEmailUpdateStarted,
|
||||
InvitedByUserID: 99,
|
||||
}
|
||||
db := db.InitTestDB(t)
|
||||
store = &xormStore{db: db, cfg: db.Cfg}
|
||||
db, cfg := db.InitTestDBWithCfg(t)
|
||||
store = &xormStore{db: db, cfg: cfg}
|
||||
|
||||
tempUser, err = store.CreateTempUser(context.Background(), &cmd)
|
||||
require.Nil(t, err)
|
||||
|
@ -64,8 +64,7 @@ func TestIntegrationUserGet(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
ss := db.InitTestDB(t)
|
||||
cfg := ss.Cfg
|
||||
ss, cfg := db.InitTestDBWithCfg(t)
|
||||
userStore := ProvideStore(ss, cfg)
|
||||
|
||||
_, errUser := userStore.Insert(context.Background(),
|
||||
@ -108,12 +107,12 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
ss := db.InitTestDB(t)
|
||||
quotaService := quotaimpl.ProvideService(ss, ss.Cfg)
|
||||
orgService, err := orgimpl.ProvideService(ss, ss.Cfg, quotaService)
|
||||
ss, cfg := db.InitTestDBWithCfg(t)
|
||||
quotaService := quotaimpl.ProvideService(ss, cfg)
|
||||
orgService, err := orgimpl.ProvideService(ss, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userStore := ProvideStore(ss, setting.NewCfg())
|
||||
usrSvc, err := ProvideService(ss, orgService, ss.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := ProvideService(ss, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
usr := &user.SignedInUser{
|
||||
OrgID: 1,
|
||||
@ -183,7 +182,7 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("Testing DB - creates and loads user", func(t *testing.T) {
|
||||
ss := db.InitTestDB(t)
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, cfg)
|
||||
|
||||
cmd := user.CreateUserCommand{
|
||||
Email: "usertest@test.com",
|
||||
@ -460,7 +459,7 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("get signed in user", func(t *testing.T) {
|
||||
ss := db.InitTestDB(t)
|
||||
orgService, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||
orgService, usrSvc := createOrgAndUserSvc(t, ss, cfg)
|
||||
users := createFiveTestUsers(t, usrSvc, func(i int) *user.CreateUserCommand {
|
||||
return &user.CreateUserCommand{
|
||||
Email: fmt.Sprint("user", i, "@test.com"),
|
||||
@ -501,7 +500,7 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("Testing DB - grafana admin users", func(t *testing.T) {
|
||||
ss := db.InitTestDB(t)
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, cfg)
|
||||
usr, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||
Email: "admin@test.com",
|
||||
Name: "admin",
|
||||
@ -557,8 +556,8 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("Testing DB - return list users based on their is_disabled flag", func(t *testing.T) {
|
||||
ss = db.InitTestDB(t)
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||
userStore := ProvideStore(ss, ss.Cfg)
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, cfg)
|
||||
userStore := ProvideStore(ss, cfg)
|
||||
|
||||
createFiveTestUsers(t, usrSvc, func(i int) *user.CreateUserCommand {
|
||||
return &user.CreateUserCommand{
|
||||
@ -591,7 +590,7 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
|
||||
// Re-init DB
|
||||
ss := db.InitTestDB(t)
|
||||
orgService, usrSvc = createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||
orgService, usrSvc = createOrgAndUserSvc(t, ss, cfg)
|
||||
|
||||
users := createFiveTestUsers(t, usrSvc, func(i int) *user.CreateUserCommand {
|
||||
return &user.CreateUserCommand{
|
||||
@ -615,7 +614,7 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
// A user is an org member and has been assigned permissions
|
||||
// Re-init DB
|
||||
ss = db.InitTestDB(t)
|
||||
orgService, usrSvc = createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||
orgService, usrSvc = createOrgAndUserSvc(t, ss, cfg)
|
||||
users = createFiveTestUsers(t, usrSvc, func(i int) *user.CreateUserCommand {
|
||||
return &user.CreateUserCommand{
|
||||
Email: fmt.Sprint("user", i, "@test.com"),
|
||||
@ -657,9 +656,9 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("Testing DB - return list of users that the SignedInUser has permission to read", func(t *testing.T) {
|
||||
ss := db.InitTestDB(t)
|
||||
orgService, err := orgimpl.ProvideService(ss, ss.Cfg, quotaService)
|
||||
orgService, err := orgimpl.ProvideService(ss, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := ProvideService(ss, orgService, ss.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := ProvideService(ss, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
|
||||
createFiveTestUsers(t, usrSvc, func(i int) *user.CreateUserCommand {
|
||||
@ -934,9 +933,9 @@ func TestIntegrationUserUpdate(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
ss := db.InitTestDB(t)
|
||||
userStore := ProvideStore(ss, setting.NewCfg())
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||
ss, cfg := db.InitTestDBWithCfg(t)
|
||||
userStore := ProvideStore(ss, cfg)
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, cfg)
|
||||
|
||||
users := createFiveTestUsers(t, usrSvc, func(i int) *user.CreateUserCommand {
|
||||
return &user.CreateUserCommand{
|
||||
@ -999,13 +998,13 @@ func createFiveTestUsers(t *testing.T, svc user.Service, fn func(i int) *user.Cr
|
||||
}
|
||||
|
||||
func TestMetricsUsage(t *testing.T) {
|
||||
ss := db.InitTestDB(t)
|
||||
ss, cfg := db.InitTestDBWithCfg(t)
|
||||
userStore := ProvideStore(ss, setting.NewCfg())
|
||||
quotaService := quotaimpl.ProvideService(ss, ss.Cfg)
|
||||
orgService, err := orgimpl.ProvideService(ss, ss.Cfg, quotaService)
|
||||
quotaService := quotaimpl.ProvideService(ss, cfg)
|
||||
orgService, err := orgimpl.ProvideService(ss, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||
_, usrSvc := createOrgAndUserSvc(t, ss, cfg)
|
||||
|
||||
t.Run("Get empty role metrics for an org", func(t *testing.T) {
|
||||
orgId := int64(1)
|
||||
|
@ -42,16 +42,16 @@ func TestHandleRequest(t *testing.T) {
|
||||
actualReq = req
|
||||
return backend.NewQueryDataResponse(), nil
|
||||
}
|
||||
sqlStore := db.InitTestDB(t)
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
secretsService := secretsmng.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||
secretsStore := secretskvs.NewSQLSecretsKVStore(sqlStore, secretsService, log.New("test.logger"))
|
||||
datasourcePermissions := acmock.NewMockedPermissionsService()
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dsCache := datasourceservice.ProvideCacheService(localcache.ProvideService(), sqlStore, guardian.ProvideGuardian())
|
||||
dsService, err := datasourceservice.ProvideService(nil, secretsService, secretsStore, sqlStore.Cfg, featuremgmt.WithFeatures(), acmock.New(), datasourcePermissions, quotaService, &pluginstore.FakePluginStore{})
|
||||
dsService, err := datasourceservice.ProvideService(nil, secretsService, secretsStore, cfg, featuremgmt.WithFeatures(), acmock.New(), datasourcePermissions, quotaService, &pluginstore.FakePluginStore{})
|
||||
require.NoError(t, err)
|
||||
|
||||
pCtxProvider := plugincontext.ProvideService(sqlStore.Cfg, localcache.ProvideService(), &pluginstore.FakePluginStore{
|
||||
pCtxProvider := plugincontext.ProvideService(cfg, localcache.ProvideService(), &pluginstore.FakePluginStore{
|
||||
PluginList: []pluginstore.Plugin{{JSONData: plugins.JSONData{ID: "test"}}},
|
||||
}, dsCache, dsService, pluginSettings.ProvideService(sqlStore, secretsService), pluginconfig.NewFakePluginRequestConfigProvider())
|
||||
s := ProvideService(client, nil, dsService, pCtxProvider)
|
||||
|
Loading…
Reference in New Issue
Block a user