Alerting: fix sqlstore.GetFolderByTitle to search for folder (#42898) (#43059)

* a test to reproduce the bug

(cherry picked from commit b63595b47f)

Co-authored-by: Yuriy Tseretyan <tceretian@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2021-12-13 15:49:58 -05:00
committed by GitHub
co-authored by Yuriy Tseretyan
parent 3ac0aaae80
commit e76d898f22
2 changed files with 24 additions and 10 deletions
+19 -1
View File
@@ -7,10 +7,11 @@ import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/search"
"github.com/stretchr/testify/require"
)
func TestDashboardFolderDataAccess(t *testing.T) {
@@ -507,6 +508,23 @@ func TestDashboardFolderDataAccess(t *testing.T) {
})
})
})
t.Run("Given dashboard and folder with the same title", func(t *testing.T) {
var orgId int64 = 1
title := "Very Unique Name"
var sqlStore *SQLStore
var folder1, folder2 *models.Dashboard
sqlStore = InitTestDB(t)
folder2 = insertTestDashboard(t, sqlStore, "TEST", orgId, 0, true, "prod")
_ = insertTestDashboard(t, sqlStore, title, orgId, folder2.Id, false, "prod")
folder1 = insertTestDashboard(t, sqlStore, title, orgId, 0, true, "prod")
t.Run("GetFolderByTitle should find the folder", func(t *testing.T) {
result, err := sqlStore.GetFolderByTitle(orgId, title)
require.NoError(t, err)
require.Equal(t, folder1.Id, result.Id)
})
})
})
}