Chore: Replace sqlstore with db interface (#85366)

* replace sqlstore with db interface in a few packages

* remove from stats

* remove sqlstore in admin test

* remove sqlstore from api plugin tests

* fix another createUser

* remove sqlstore in publicdashboards

* remove sqlstore from orgs

* clean up orguser test

* more clean up in sso

* clean up service accounts

* further cleanup

* more cleanup in accesscontrol

* last cleanup in accesscontrol

* clean up teams

* more removals

* split cfg from db in testenv

* few remaining fixes

* fix test with bus

* pass cfg for testing inside db as an option

* set query retries when no opts provided

* revert golden test data

* rebase and rollback
This commit is contained in:
Serge Zaitsev
2024-04-04 15:04:47 +02:00
committed by GitHub
parent c41b0a71cf
commit faa1244518
69 changed files with 507 additions and 465 deletions

View File

@@ -409,13 +409,15 @@ type InitTestDBOpt struct {
// EnsureDefaultOrgAndUser flags whether to ensure that default org and user exist.
EnsureDefaultOrgAndUser bool
FeatureFlags []string
Cfg *setting.Cfg
}
// InitTestDBWithMigration initializes the test DB given custom migrations.
func InitTestDBWithMigration(t sqlutil.ITestDB, migration registry.DatabaseMigrator, opts ...InitTestDBOpt) *SQLStore {
t.Helper()
features := getFeaturesForTesting(opts...)
store, err := initTestDB(t, setting.NewCfg(), features, migration, opts...)
cfg := getCfgForTesting(opts...)
store, err := initTestDB(t, cfg, features, migration, opts...)
if err != nil {
t.Fatalf("failed to initialize sql store: %s", err)
}
@@ -426,8 +428,9 @@ func InitTestDBWithMigration(t sqlutil.ITestDB, migration registry.DatabaseMigra
func InitTestDB(t sqlutil.ITestDB, opts ...InitTestDBOpt) *SQLStore {
t.Helper()
features := getFeaturesForTesting(opts...)
cfg := getCfgForTesting(opts...)
store, err := initTestDB(t, setting.NewCfg(), features, migrations.ProvideOSSMigrations(features), opts...)
store, err := initTestDB(t, cfg, features, migrations.ProvideOSSMigrations(features), opts...)
if err != nil {
t.Fatalf("failed to initialize sql store: %s", err)
}
@@ -465,6 +468,16 @@ func CleanupTestDB() {
}
}
func getCfgForTesting(opts ...InitTestDBOpt) *setting.Cfg {
cfg := setting.NewCfg()
for _, opt := range opts {
if len(opt.FeatureFlags) > 0 {
cfg = opt.Cfg
}
}
return cfg
}
func getFeaturesForTesting(opts ...InitTestDBOpt) featuremgmt.FeatureToggles {
featureKeys := []any{
featuremgmt.FlagPanelTitleSearch,