mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
Alerting: Fix store's GetNamespaceByUID (#75976)
This commit is contained in:
parent
55781b486c
commit
5be52dfe21
@ -476,7 +476,7 @@ func (st DBstore) GetNamespaceByTitle(ctx context.Context, namespace string, org
|
||||
|
||||
// GetNamespaceByUID is a handler for retrieving a namespace by its UID. Alerting rules follow a Grafana folder-like structure which we call namespaces.
|
||||
func (st DBstore) GetNamespaceByUID(ctx context.Context, uid string, orgID int64, user *user.SignedInUser) (*folder.Folder, error) {
|
||||
folder, err := st.FolderService.Get(ctx, &folder.GetFolderQuery{OrgID: orgID, Title: &uid, SignedInUser: user})
|
||||
folder, err := st.FolderService.Get(ctx, &folder.GetFolderQuery{OrgID: orgID, UID: &uid, SignedInUser: user})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/log/logtest"
|
||||
@ -482,6 +484,36 @@ func TestIntegration_DeleteInFolder(t *testing.T) {
|
||||
require.Equal(t, int64(0), c)
|
||||
}
|
||||
|
||||
func TestIntegration_GetNamespaceByUID(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
sqlStore := db.InitTestDB(t)
|
||||
cfg := setting.NewCfg()
|
||||
store := &DBstore{
|
||||
SQLStore: sqlStore,
|
||||
FolderService: setupFolderService(t, sqlStore, cfg),
|
||||
Logger: log.New("test-dbstore"),
|
||||
}
|
||||
|
||||
u := &user.SignedInUser{
|
||||
UserID: 1,
|
||||
OrgID: 1,
|
||||
OrgRole: org.RoleAdmin,
|
||||
IsGrafanaAdmin: true,
|
||||
}
|
||||
|
||||
uid := uuid.NewString()
|
||||
title := "folder-title"
|
||||
createFolder(t, store, uid, title, 1)
|
||||
|
||||
actual, err := store.GetNamespaceByUID(context.Background(), uid, 1, u)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, title, actual.Title)
|
||||
require.Equal(t, uid, actual.UID)
|
||||
}
|
||||
|
||||
func createRule(t *testing.T, store *DBstore, generate func() *models.AlertRule) *models.AlertRule {
|
||||
t.Helper()
|
||||
if generate == nil {
|
||||
@ -512,7 +544,7 @@ func createRule(t *testing.T, store *DBstore, generate func() *models.AlertRule)
|
||||
return rule
|
||||
}
|
||||
|
||||
func createFolder(t *testing.T, store *DBstore, namespace, title string, orgID int64) {
|
||||
func createFolder(t *testing.T, store *DBstore, uid, title string, orgID int64) {
|
||||
t.Helper()
|
||||
u := &user.SignedInUser{
|
||||
UserID: 1,
|
||||
@ -522,7 +554,7 @@ func createFolder(t *testing.T, store *DBstore, namespace, title string, orgID i
|
||||
}
|
||||
|
||||
_, err := store.FolderService.Create(context.Background(), &folder.CreateFolderCommand{
|
||||
UID: namespace,
|
||||
UID: uid,
|
||||
OrgID: orgID,
|
||||
Title: title,
|
||||
Description: "",
|
||||
|
Loading…
Reference in New Issue
Block a user