feat(unified): data migration integration tests (#114418)
* feat: unified storage migrations integration tests * chore: add comment and adjust db path name * chore: refactor test cases into interface
This commit is contained in:
@@ -49,6 +49,12 @@ func StartGrafana(t *testing.T, grafDir, cfgPath string) (string, db.DB) {
|
||||
}
|
||||
|
||||
func StartGrafanaEnv(t *testing.T, grafDir, cfgPath string) (string, *server.TestEnv) {
|
||||
addr, env, testDB := StartGrafanaEnvWithDB(t, grafDir, cfgPath)
|
||||
t.Cleanup(testDB.Cleanup)
|
||||
return addr, env
|
||||
}
|
||||
|
||||
func StartGrafanaEnvWithDB(t *testing.T, grafDir, cfgPath string) (string, *server.TestEnv, *sqlutil.TestDB) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -93,7 +99,6 @@ func StartGrafanaEnv(t *testing.T, grafDir, cfgPath string) (string, *server.Tes
|
||||
// Use proper database type based on the environment variable GRAFANA_TEST_DB in tests
|
||||
testDB, err := sqlutil.GetTestDB(sqlutil.GetTestDBType())
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(testDB.Cleanup)
|
||||
|
||||
dbCfg := cfg.Raw.Section("database")
|
||||
dbCfg.Key("type").SetValue(testDB.DriverName)
|
||||
@@ -169,7 +174,7 @@ func StartGrafanaEnv(t *testing.T, grafDir, cfgPath string) (string, *server.Tes
|
||||
|
||||
t.Logf("Grafana is listening on %s", addr)
|
||||
|
||||
return addr, env
|
||||
return addr, env, testDB
|
||||
}
|
||||
|
||||
// CreateGrafDir creates the Grafana directory.
|
||||
@@ -538,6 +543,12 @@ func CreateGrafDir(t *testing.T, opts GrafanaOpts) (string, string) {
|
||||
_, err = section.NewKey("max_page_size_bytes", fmt.Sprintf("%d", opts.UnifiedStorageMaxPageSizeBytes))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
if opts.DisableDataMigrations {
|
||||
section, err := getOrCreateSection("unified_storage")
|
||||
require.NoError(t, err)
|
||||
_, err = section.NewKey("disable_data_migrations", "true")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
if opts.PermittedProvisioningPaths != "" {
|
||||
_, err = pathsSect.NewKey("permitted_provisioning_paths", opts.PermittedProvisioningPaths)
|
||||
require.NoError(t, err)
|
||||
@@ -637,6 +648,8 @@ type GrafanaOpts struct {
|
||||
EnableSCIM bool
|
||||
APIServerRuntimeConfig string
|
||||
DisableControllers bool
|
||||
DisableDBCleanup bool
|
||||
DisableDataMigrations bool
|
||||
SecretsManagerEnableDBMigrations bool
|
||||
|
||||
// Allow creating grafana dir beforehand
|
||||
|
||||
Reference in New Issue
Block a user