Chore: Move dashboard models to dashboard pkg (#61458)
* Copy dashboard models to dashboard pkg * Use some models from current pkg instead of models * Adjust api pkg * Adjust pkg services * Fix lint
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
)
|
||||
@@ -23,9 +24,9 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
dashboardStore, err := ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg), quotaService)
|
||||
require.NoError(t, err)
|
||||
|
||||
folderCmd := models.SaveDashboardCommand{
|
||||
OrgId: 1,
|
||||
FolderId: 0,
|
||||
folderCmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: 1,
|
||||
FolderID: 0,
|
||||
IsFolder: true,
|
||||
Dashboard: simplejson.NewFromAny(map[string]interface{}{
|
||||
"id": nil,
|
||||
@@ -36,10 +37,10 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
dash, err := dashboardStore.SaveDashboard(context.Background(), folderCmd)
|
||||
require.Nil(t, err)
|
||||
|
||||
saveDashboardCmd := models.SaveDashboardCommand{
|
||||
OrgId: 1,
|
||||
saveDashboardCmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: 1,
|
||||
IsFolder: false,
|
||||
FolderId: dash.Id,
|
||||
FolderID: dash.ID,
|
||||
Dashboard: simplejson.NewFromAny(map[string]interface{}{
|
||||
"id": nil,
|
||||
"title": "test dashboard",
|
||||
@@ -49,38 +50,38 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
t.Run("Saving dashboards with provisioning meta data", func(t *testing.T) {
|
||||
now := time.Now()
|
||||
|
||||
provisioning := &models.DashboardProvisioning{
|
||||
provisioning := &dashboards.DashboardProvisioning{
|
||||
Name: "default",
|
||||
ExternalId: "/var/grafana.json",
|
||||
ExternalID: "/var/grafana.json",
|
||||
Updated: now.Unix(),
|
||||
}
|
||||
|
||||
dash, err := dashboardStore.SaveProvisionedDashboard(context.Background(), saveDashboardCmd, provisioning)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, dash)
|
||||
require.NotEqual(t, 0, dash.Id)
|
||||
dashId := dash.Id
|
||||
require.NotEqual(t, 0, dash.ID)
|
||||
dashId := dash.ID
|
||||
|
||||
t.Run("Deleting orphaned provisioned dashboards", func(t *testing.T) {
|
||||
saveCmd := models.SaveDashboardCommand{
|
||||
OrgId: 1,
|
||||
saveCmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: 1,
|
||||
IsFolder: false,
|
||||
FolderId: dash.Id,
|
||||
FolderID: dash.ID,
|
||||
Dashboard: simplejson.NewFromAny(map[string]interface{}{
|
||||
"id": nil,
|
||||
"title": "another_dashboard",
|
||||
}),
|
||||
}
|
||||
provisioning := &models.DashboardProvisioning{
|
||||
provisioning := &dashboards.DashboardProvisioning{
|
||||
Name: "another_reader",
|
||||
ExternalId: "/var/grafana.json",
|
||||
ExternalID: "/var/grafana.json",
|
||||
Updated: now.Unix(),
|
||||
}
|
||||
|
||||
anotherDash, err := dashboardStore.SaveProvisionedDashboard(context.Background(), saveCmd, provisioning)
|
||||
require.Nil(t, err)
|
||||
|
||||
query := &models.GetDashboardsQuery{DashboardIds: []int64{anotherDash.Id}}
|
||||
query := &dashboards.GetDashboardsQuery{DashboardIDs: []int64{anotherDash.ID}}
|
||||
err = dashboardStore.GetDashboards(context.Background(), query)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, query.Result)
|
||||
@@ -88,12 +89,12 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
deleteCmd := &models.DeleteOrphanedProvisionedDashboardsCommand{ReaderNames: []string{"default"}}
|
||||
require.Nil(t, dashboardStore.DeleteOrphanedProvisionedDashboards(context.Background(), deleteCmd))
|
||||
|
||||
query = &models.GetDashboardsQuery{DashboardIds: []int64{dash.Id, anotherDash.Id}}
|
||||
query = &dashboards.GetDashboardsQuery{DashboardIDs: []int64{dash.ID, anotherDash.ID}}
|
||||
err = dashboardStore.GetDashboards(context.Background(), query)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, 1, len(query.Result))
|
||||
require.Equal(t, dashId, query.Result[0].Id)
|
||||
require.Equal(t, dashId, query.Result[0].ID)
|
||||
})
|
||||
|
||||
t.Run("Can query for provisioned dashboards", func(t *testing.T) {
|
||||
@@ -106,7 +107,7 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Can query for one provisioned dashboard", func(t *testing.T) {
|
||||
data, err := dashboardStore.GetProvisionedDataByDashboardID(context.Background(), dash.Id)
|
||||
data, err := dashboardStore.GetProvisionedDataByDashboardID(context.Background(), dash.ID)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, data)
|
||||
})
|
||||
@@ -119,13 +120,13 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
|
||||
t.Run("Deleting folder should delete provision meta data", func(t *testing.T) {
|
||||
deleteCmd := &models.DeleteDashboardCommand{
|
||||
Id: dash.Id,
|
||||
Id: dash.ID,
|
||||
OrgId: 1,
|
||||
}
|
||||
|
||||
require.Nil(t, dashboardStore.DeleteDashboard(context.Background(), deleteCmd))
|
||||
|
||||
data, err := dashboardStore.GetProvisionedDataByDashboardID(context.Background(), dash.Id)
|
||||
data, err := dashboardStore.GetProvisionedDataByDashboardID(context.Background(), dash.ID)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, data)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user