mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
Add store split for Get Dashboard version method (#49138)
* Add store split for Get Dashboard version method * Implement dashboard version service * Fix api tests * Remove GetDashboarVersion from sqlstore * Add fakes for Get dashboard version * Fix sqlstore test * Add Get Dashboard store test * Add dashver service test * Remove useless comments
This commit is contained in:
@@ -8,28 +8,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
// GetDashboardVersion gets the dashboard version for the given dashboard ID and version number.
|
||||
func (ss *SQLStore) GetDashboardVersion(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
return ss.WithDbSession(ctx, func(sess *DBSession) error {
|
||||
version := models.DashboardVersion{}
|
||||
has, err := sess.Where("dashboard_version.dashboard_id=? AND dashboard_version.version=? AND dashboard.org_id=?", query.DashboardId, query.Version, query.OrgId).
|
||||
Join("LEFT", "dashboard", `dashboard.id = dashboard_version.dashboard_id`).
|
||||
Get(&version)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !has {
|
||||
return models.ErrDashboardVersionNotFound
|
||||
}
|
||||
|
||||
version.Data.Set("id", version.DashboardId)
|
||||
query.Result = &version
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// GetDashboardVersions gets all dashboard versions for the given dashboard ID.
|
||||
func (ss *SQLStore) GetDashboardVersions(ctx context.Context, query *models.GetDashboardVersionsQuery) error {
|
||||
return ss.WithDbSession(ctx, func(sess *DBSession) error {
|
||||
|
||||
@@ -5,7 +5,6 @@ package sqlstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -78,46 +77,6 @@ func updateTestDashboard(t *testing.T, sqlStore *SQLStore, dashboard *models.Das
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestIntegrationGetDashboardVersion(t *testing.T) {
|
||||
sqlStore := InitTestDB(t)
|
||||
|
||||
t.Run("Get a Dashboard ID and version ID", func(t *testing.T) {
|
||||
savedDash := insertTestDashboard(t, sqlStore, "test dash 26", 1, 0, false, "diff")
|
||||
|
||||
query := models.GetDashboardVersionQuery{
|
||||
DashboardId: savedDash.Id,
|
||||
Version: savedDash.Version,
|
||||
OrgId: 1,
|
||||
}
|
||||
|
||||
err := sqlStore.GetDashboardVersion(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, query.DashboardId, savedDash.Id)
|
||||
require.Equal(t, query.Version, savedDash.Version)
|
||||
|
||||
dashCmd := &models.Dashboard{
|
||||
Uid: savedDash.Uid,
|
||||
OrgId: savedDash.OrgId,
|
||||
}
|
||||
err = getDashboard(t, sqlStore, dashCmd)
|
||||
require.Nil(t, err)
|
||||
eq := reflect.DeepEqual(dashCmd.Data, query.Result.Data)
|
||||
require.Equal(t, true, eq)
|
||||
})
|
||||
|
||||
t.Run("Attempt to get a version that doesn't exist", func(t *testing.T) {
|
||||
query := models.GetDashboardVersionQuery{
|
||||
DashboardId: int64(999),
|
||||
Version: 123,
|
||||
OrgId: 1,
|
||||
}
|
||||
|
||||
err := sqlStore.GetDashboardVersion(context.Background(), &query)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, models.ErrDashboardVersionNotFound, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestIntegrationGetDashboardVersions(t *testing.T) {
|
||||
sqlStore := InitTestDB(t)
|
||||
savedDash := insertTestDashboard(t, sqlStore, "test dash 43", 1, 0, false, "diff-all")
|
||||
|
||||
@@ -344,16 +344,6 @@ func (m *SQLStoreMock) InTransaction(ctx context.Context, fn func(ctx context.Co
|
||||
return m.ExpectedError
|
||||
}
|
||||
|
||||
func (m *SQLStoreMock) GetDashboardVersion(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
query.Result = &models.DashboardVersion{}
|
||||
for _, dashboardversion := range m.ExpectedDashboardVersions {
|
||||
if dashboardversion.DashboardId == query.DashboardId && dashboardversion.Version == query.Version {
|
||||
query.Result = dashboardversion
|
||||
}
|
||||
}
|
||||
return m.ExpectedError
|
||||
}
|
||||
|
||||
func (m *SQLStoreMock) GetDashboardVersions(ctx context.Context, query *models.GetDashboardVersionsQuery) error {
|
||||
return m.ExpectedError
|
||||
}
|
||||
|
||||
@@ -74,7 +74,6 @@ type Store interface {
|
||||
GetGlobalQuotaByTarget(ctx context.Context, query *models.GetGlobalQuotaByTargetQuery) error
|
||||
WithTransactionalDbSession(ctx context.Context, callback DBTransactionFunc) error
|
||||
InTransaction(ctx context.Context, fn func(ctx context.Context) error) error
|
||||
GetDashboardVersion(ctx context.Context, query *models.GetDashboardVersionQuery) error
|
||||
GetDashboardVersions(ctx context.Context, query *models.GetDashboardVersionsQuery) error
|
||||
DeleteExpiredVersions(ctx context.Context, cmd *models.DeleteExpiredVersionsCommand) error
|
||||
GetDashboardAclInfoList(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error
|
||||
|
||||
Reference in New Issue
Block a user