Dashboards: Add feature restore dashboards backend (#83131)
Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
co-authored by
Sofia Papagiannaki
parent
edae5fc791
commit
42d75ac737
@@ -525,12 +525,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
_ = insertTestDashboard(t, dashboardStore, "delete me 1", 1, folder.ID, folder.UID, false, "delete this 1")
|
||||
_ = insertTestDashboard(t, dashboardStore, "delete me 2", 1, folder.ID, folder.UID, false, "delete this 2")
|
||||
|
||||
err := dashboardStore.DeleteDashboardsInFolders(
|
||||
context.Background(),
|
||||
&dashboards.DeleteDashboardsInFolderRequest{
|
||||
FolderUIDs: []string{folder.UID},
|
||||
OrgID: 1,
|
||||
})
|
||||
err := dashboardStore.SoftDeleteDashboardsInFolders(context.Background(), folder.OrgID, []string{folder.UID})
|
||||
require.NoError(t, err)
|
||||
|
||||
count, err := dashboardStore.CountDashboardsInFolders(context.Background(), &dashboards.CountDashboardsInFolderRequest{FolderUIDs: []string{folder.UID}, OrgID: 1})
|
||||
@@ -539,6 +534,127 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestIntegrationGetSoftDeletedDashboard(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var cfg *setting.Cfg
|
||||
var savedFolder, savedDash *dashboards.Dashboard
|
||||
var dashboardStore dashboards.Store
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
var err error
|
||||
dashboardStore, err = ProvideDashboardStore(sqlStore, cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, "", true, "prod", "webapp")
|
||||
savedDash = insertTestDashboard(t, dashboardStore, "test dash 23", 1, savedFolder.ID, savedFolder.UID, false, "prod", "webapp")
|
||||
insertTestDashboard(t, dashboardStore, "test dash 45", 1, savedFolder.ID, savedFolder.UID, false, "prod")
|
||||
}
|
||||
|
||||
t.Run("Should soft delete a dashboard", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
// Confirm there are 2 dashboards in the folder
|
||||
amount, err := dashboardStore.CountDashboardsInFolders(context.Background(), &dashboards.CountDashboardsInFolderRequest{FolderUIDs: []string{savedFolder.UID}, OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(2), amount)
|
||||
|
||||
// Soft delete the dashboard
|
||||
err = dashboardStore.SoftDeleteDashboard(context.Background(), savedDash.OrgID, savedDash.UID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// There is only 1 dashboard in the folder after soft delete
|
||||
amount, err = dashboardStore.CountDashboardsInFolders(context.Background(), &dashboards.CountDashboardsInFolderRequest{FolderUIDs: []string{savedFolder.UID}, OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(1), amount)
|
||||
|
||||
var dash *dashboards.Dashboard
|
||||
// Get the soft deleted dashboard should be empty
|
||||
dash, _ = dashboardStore.GetDashboard(context.Background(), &dashboards.GetDashboardQuery{UID: savedDash.UID, OrgID: savedDash.OrgID})
|
||||
assert.Error(t, dashboards.ErrDashboardNotFound)
|
||||
assert.Nil(t, dash)
|
||||
|
||||
// Get the soft deleted dashboard
|
||||
dash, err = dashboardStore.GetSoftDeletedDashboard(context.Background(), savedDash.OrgID, savedDash.UID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, savedDash.ID, dash.ID)
|
||||
assert.Equal(t, savedDash.UID, dash.UID)
|
||||
assert.Equal(t, savedDash.Title, dash.Title)
|
||||
})
|
||||
|
||||
t.Run("Should not fail when trying to soft delete a soft deleted dashboard", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
// Soft delete the dashboard
|
||||
err := dashboardStore.SoftDeleteDashboard(context.Background(), savedDash.OrgID, savedDash.UID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Soft delete the dashboard
|
||||
err = dashboardStore.SoftDeleteDashboard(context.Background(), savedDash.OrgID, savedDash.UID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Get the soft deleted dashboard
|
||||
dash, err := dashboardStore.GetSoftDeletedDashboard(context.Background(), savedDash.OrgID, savedDash.UID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, savedDash.ID, dash.ID)
|
||||
assert.Equal(t, savedDash.UID, dash.UID)
|
||||
assert.Equal(t, savedDash.Title, dash.Title)
|
||||
})
|
||||
|
||||
t.Run("Should restore a dashboard", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
// Confirm there are 2 dashboards in the folder
|
||||
amount, err := dashboardStore.CountDashboardsInFolders(context.Background(), &dashboards.CountDashboardsInFolderRequest{FolderUIDs: []string{savedFolder.UID}, OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(2), amount)
|
||||
|
||||
// Soft delete the dashboard
|
||||
err = dashboardStore.SoftDeleteDashboard(context.Background(), savedDash.OrgID, savedDash.UID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// There is only 1 dashboard in the folder after soft delete
|
||||
amount, err = dashboardStore.CountDashboardsInFolders(context.Background(), &dashboards.CountDashboardsInFolderRequest{FolderUIDs: []string{savedFolder.UID}, OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(1), amount)
|
||||
|
||||
// Get the soft deleted dashboard
|
||||
dash, err := dashboardStore.GetSoftDeletedDashboard(context.Background(), savedDash.OrgID, savedDash.UID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, savedDash.ID, dash.ID)
|
||||
assert.Equal(t, savedDash.UID, dash.UID)
|
||||
assert.Equal(t, savedDash.Title, dash.Title)
|
||||
|
||||
// Restore deleted dashboard
|
||||
// nolint:staticcheck
|
||||
err = dashboardStore.RestoreDashboard(context.Background(), savedDash.OrgID, savedDash.UID, &folder.Folder{ID: savedDash.FolderID, UID: savedDash.FolderUID})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Restore increases the amount of dashboards in the folder
|
||||
amount, err = dashboardStore.CountDashboardsInFolders(context.Background(), &dashboards.CountDashboardsInFolderRequest{FolderUIDs: []string{savedFolder.UID}, OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(2), amount)
|
||||
|
||||
// Get the soft deleted dashboard should be empty
|
||||
dash, err = dashboardStore.GetSoftDeletedDashboard(context.Background(), savedDash.OrgID, savedDash.UID)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, dash)
|
||||
|
||||
// Get the restored dashboard
|
||||
dash, err = dashboardStore.GetDashboard(context.Background(), &dashboards.GetDashboardQuery{UID: savedDash.UID, OrgID: savedDash.OrgID})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, savedDash.ID, dash.ID)
|
||||
assert.Equal(t, savedDash.UID, dash.UID)
|
||||
assert.Equal(t, savedDash.Title, dash.Title)
|
||||
// nolint:staticcheck
|
||||
assert.Equal(t, savedDash.FolderID, dash.FolderID)
|
||||
assert.Equal(t, savedDash.FolderUID, dash.FolderUID)
|
||||
})
|
||||
}
|
||||
|
||||
func TestIntegrationDashboardDataAccessGivenPluginWithImportedDashboards(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
|
||||
Reference in New Issue
Block a user