backend/services: Move GetDashboard from sqlstore to dashboard service (#48971)
* rename folder to match package name * backend/sqlstore: move GetDashboard into DashboardService This is a stepping-stone commit which copies the GetDashboard function - which lets us remove the sqlstore from the interfaces in dashboards - without changing any other callers. * checkpoint: moving GetDashboard calls into dashboard service * finish refactoring api tests for dashboardService.GetDashboard
This commit is contained in:
@@ -9,11 +9,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func updateTestDashboard(t *testing.T, sqlStore *SQLStore, dashboard *models.Dashboard, data map[string]interface{}) {
|
||||
@@ -94,14 +95,13 @@ func TestGetDashboardVersion(t *testing.T) {
|
||||
require.Equal(t, query.DashboardId, savedDash.Id)
|
||||
require.Equal(t, query.Version, savedDash.Version)
|
||||
|
||||
dashCmd := models.GetDashboardQuery{
|
||||
OrgId: savedDash.OrgId,
|
||||
dashCmd := &models.Dashboard{
|
||||
Uid: savedDash.Uid,
|
||||
OrgId: savedDash.OrgId,
|
||||
}
|
||||
|
||||
err = sqlStore.GetDashboard(context.Background(), &dashCmd)
|
||||
err = getDashboard(t, sqlStore, dashCmd)
|
||||
require.Nil(t, err)
|
||||
eq := reflect.DeepEqual(dashCmd.Result.Data, query.Result.Data)
|
||||
eq := reflect.DeepEqual(dashCmd.Data, query.Result.Data)
|
||||
require.Equal(t, true, eq)
|
||||
})
|
||||
|
||||
@@ -222,3 +222,20 @@ func TestDeleteExpiredVersions(t *testing.T) {
|
||||
require.LessOrEqual(t, versionsToWriteBigNumber-len(query.Result), perBatch*maxBatches)
|
||||
})
|
||||
}
|
||||
|
||||
func getDashboard(t *testing.T, sqlStore *SQLStore, dashboard *models.Dashboard) error {
|
||||
t.Helper()
|
||||
return sqlStore.WithDbSession(context.Background(), func(sess *DBSession) error {
|
||||
has, err := sess.Get(dashboard)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !has {
|
||||
return models.ErrDashboardNotFound
|
||||
}
|
||||
|
||||
dashboard.SetId(dashboard.Id)
|
||||
dashboard.SetUid(dashboard.Uid)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user