Split Delete expired dashboard version store (#49610)
* Split Delete expired dashboard version store * Add method to fakes * Fix lint * Fix lint 2 * Use split store method in cleanup * Add tests * Remove DeleteExpiredVersions from sqlstore * Fix lint * Fix integration tests
This commit is contained in:
@@ -14,10 +14,11 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIntegrationDashboardVersion(t *testing.T) {
|
||||
func TestIntegrationGetDashboardVersion(t *testing.T) {
|
||||
ss := sqlstore.InitTestDB(t)
|
||||
dashVerStore := sqlStore{db: ss}
|
||||
|
||||
@@ -60,6 +61,27 @@ func TestIntegrationDashboardVersion(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestIntegrationDeleteExpiredVersions(t *testing.T) {
|
||||
versionsToWrite := 10
|
||||
ss := sqlstore.InitTestDB(t)
|
||||
dashVerStore := sqlStore{db: ss}
|
||||
|
||||
for i := 0; i < versionsToWrite-1; i++ {
|
||||
insertTestDashboard(t, ss, "test dash 53", 1, int64(i), false, "diff-all")
|
||||
}
|
||||
|
||||
t.Run("Clean up old dashboard versions", func(t *testing.T) {
|
||||
versionIDsToDelete := []interface{}{1, 2, 3, 4}
|
||||
res, err := dashVerStore.DeleteBatch(
|
||||
context.Background(),
|
||||
&dashver.DeleteExpiredVersionsCommand{DeletedRows: 4},
|
||||
versionIDsToDelete,
|
||||
)
|
||||
require.Nil(t, err)
|
||||
assert.EqualValues(t, 4, res)
|
||||
})
|
||||
}
|
||||
|
||||
func getDashboard(t *testing.T, sqlStore *sqlstore.SQLStore, dashboard *models.Dashboard) error {
|
||||
t.Helper()
|
||||
return sqlStore.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||
|
||||
Reference in New Issue
Block a user