K8s: Folders: Fix get command (#99690)

pull/99712/head
Stephanie Hingtgen 11 months ago committed by GitHub
parent 3ba0d8d4b5
commit 516bd0fd1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      pkg/services/folder/folderimpl/folder_unifiedstorage.go
  2. 9
      pkg/services/folder/folderimpl/folder_unifiedstorage_test.go

@ -106,27 +106,24 @@ func (s *Service) getFromApiServer(ctx context.Context, q *folder.GetFolderQuery
var dashFolder *folder.Folder
var err error
switch {
case q.UID != nil:
if *q.UID == "" {
return &folder.GeneralFolder, nil
}
case q.UID != nil && *q.UID != "":
dashFolder, err = s.unifiedStore.Get(ctx, *q)
if err != nil {
return nil, toFolderError(err)
}
// nolint:staticcheck
case q.ID != nil:
case q.ID != nil && *q.ID != 0:
dashFolder, err = s.getFolderByIDFromApiServer(ctx, *q.ID, q.OrgID)
if err != nil {
return nil, toFolderError(err)
}
case q.Title != nil:
case q.Title != nil && *q.Title != "":
dashFolder, err = s.getFolderByTitleFromApiServer(ctx, q.OrgID, *q.Title, q.ParentUID)
if err != nil {
return nil, toFolderError(err)
}
default:
return nil, folder.ErrBadRequest.Errorf("either on of UID, ID, Title fields must be present")
return &folder.GeneralFolder, nil
}
if dashFolder.IsGeneral() {

@ -424,9 +424,11 @@ func TestIntegrationFolderServiceViaUnifiedStorage(t *testing.T) {
require.NoError(t, err)
})
t.Run("When get folder by ID should return folder", func(t *testing.T) {
t.Run("When get folder by ID and uid is an empty string should return folder by id", func(t *testing.T) {
id := int64(123)
emptyString := ""
query := &folder.GetFolderQuery{
UID: &emptyString,
ID: &id,
OrgID: 1,
SignedInUser: usr,
@ -482,10 +484,13 @@ func TestIntegrationFolderServiceViaUnifiedStorage(t *testing.T) {
})
t.Run("Returns root folder", func(t *testing.T) {
t.Run("When the folder UID is blank should return the root folder", func(t *testing.T) {
t.Run("When the folder UID and title are blank, and id is 0, should return the root folder", func(t *testing.T) {
emptyString := ""
idZero := int64(0)
actual, err := folderService.Get(ctx, &folder.GetFolderQuery{
UID: &emptyString,
ID: &idZero,
Title: &emptyString,
OrgID: 1,
SignedInUser: usr,
})

Loading…
Cancel
Save