[v9.4.x] Dashboards: Evaluate provisioned dashboard titles in a backwards compatible way (#65440)

Backport from #65184 using github.com/xorcare/pointer instead of the newer util.Pointer.

(cherry picked from commit b210a39cb7)

---------

Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2023-03-29 11:25:44 +02:00
committed by GitHub
co-authored by Emil Tullstedt
parent 90db06d65b
commit 266a7407f6
5 changed files with 72 additions and 16 deletions
@@ -8,11 +8,12 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/expr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/xorcare/pointer"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/expr"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/dashboards"
@@ -91,11 +92,12 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
require.False(t, queryResult.IsFolder)
})
t.Run("Should be able to get dashboard by slug", func(t *testing.T) {
t.Run("Should be able to get dashboard by title and folderID", func(t *testing.T) {
setup()
query := dashboards.GetDashboardQuery{
Slug: "test-dash-23",
OrgID: 1,
Title: pointer.String("test dash 23"),
FolderID: &savedFolder.ID,
OrgID: 1,
}
queryResult, err := dashboardStore.GetDashboard(context.Background(), &query)
@@ -108,6 +110,29 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
require.False(t, queryResult.IsFolder)
})
t.Run("Should not be able to get dashboard by title alone", func(t *testing.T) {
setup()
query := dashboards.GetDashboardQuery{
Title: pointer.String("test dash 23"),
OrgID: 1,
}
_, err := dashboardStore.GetDashboard(context.Background(), &query)
require.ErrorIs(t, err, dashboards.ErrDashboardIdentifierNotSet)
})
t.Run("Folder=0 should not be able to get a dashboard in a folder", func(t *testing.T) {
setup()
query := dashboards.GetDashboardQuery{
Title: pointer.String("test dash 23"),
FolderID: pointer.Int64(0),
OrgID: 1,
}
_, err := dashboardStore.GetDashboard(context.Background(), &query)
require.ErrorIs(t, err, dashboards.ErrDashboardNotFound)
})
t.Run("Should be able to get dashboard by uid", func(t *testing.T) {
setup()
query := dashboards.GetDashboardQuery{