Dashboards: Remove unique name constraints (#90687)
This commit is contained in:
@@ -2,12 +2,9 @@ package folders
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/grafana/grafana-openapi-client-go/client/folders"
|
||||
"github.com/grafana/grafana-openapi-client-go/models"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
@@ -92,14 +89,12 @@ func TestIntegrationCreateFolder(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.Code())
|
||||
|
||||
t.Run("create folder with same name under root should fail", func(t *testing.T) {
|
||||
t.Run("create folder with same name under root should succeed", func(t *testing.T) {
|
||||
_, err := adminClient.Folders.CreateFolder(&models.CreateFolderCommand{
|
||||
Title: "folder",
|
||||
})
|
||||
require.Error(t, err)
|
||||
var conflict *folders.CreateFolderConflict
|
||||
assert.True(t, errors.As(err, &conflict))
|
||||
assert.Equal(t, http.StatusConflict, conflict.Code())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.Code())
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -133,14 +128,12 @@ func TestIntegrationNestedFoldersOn(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.Code())
|
||||
|
||||
t.Run("create folder with same name under root should fail", func(t *testing.T) {
|
||||
t.Run("create folder with same name under root should succeed", func(t *testing.T) {
|
||||
_, err := adminClient.Folders.CreateFolder(&models.CreateFolderCommand{
|
||||
Title: "folder",
|
||||
})
|
||||
require.Error(t, err)
|
||||
var conflict *folders.CreateFolderConflict
|
||||
assert.True(t, errors.As(err, &conflict))
|
||||
assert.Equal(t, http.StatusConflict, conflict.Code())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.Code())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -159,15 +152,13 @@ func TestIntegrationNestedFoldersOn(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.Code())
|
||||
|
||||
t.Run("create subfolder with same name should fail", func(t *testing.T) {
|
||||
t.Run("create subfolder with same name should succeed", func(t *testing.T) {
|
||||
resp, err = adminClient.Folders.CreateFolder(&models.CreateFolderCommand{
|
||||
Title: "subfolder",
|
||||
ParentUID: parentUID,
|
||||
})
|
||||
require.Error(t, err)
|
||||
var conflict *folders.CreateFolderConflict
|
||||
assert.True(t, errors.As(err, &conflict))
|
||||
assert.Equal(t, http.StatusConflict, conflict.Code())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.Code())
|
||||
})
|
||||
|
||||
t.Run("create subfolder with same name under other folder should succeed", func(t *testing.T) {
|
||||
@@ -187,14 +178,13 @@ func TestIntegrationNestedFoldersOn(t *testing.T) {
|
||||
assert.Equal(t, other, resp.Payload.ParentUID)
|
||||
subfolderUnderOther := resp.Payload.UID
|
||||
|
||||
t.Run("move subfolder to other folder containing folder with that name should fail", func(t *testing.T) {
|
||||
_, err := adminClient.Folders.MoveFolder(subfolderUnderOther, &models.MoveFolderCommand{
|
||||
t.Run("move subfolder to other folder containing folder with the same name should be ok", func(t *testing.T) {
|
||||
resp, err := adminClient.Folders.MoveFolder(subfolderUnderOther, &models.MoveFolderCommand{
|
||||
ParentUID: parentUID,
|
||||
})
|
||||
require.Error(t, err)
|
||||
var apiError *runtime.APIError
|
||||
assert.True(t, errors.As(err, &apiError))
|
||||
assert.Equal(t, http.StatusConflict, apiError.Code)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, resp.Code())
|
||||
assert.Equal(t, parentUID, resp.Payload.ParentUID)
|
||||
})
|
||||
|
||||
t.Run("move subfolder to root should succeed", func(t *testing.T) {
|
||||
|
||||
@@ -564,7 +564,7 @@ func doCreateDuplicateFolderTest(t *testing.T, helper *apis.K8sTestHelper) {
|
||||
Body: []byte(payload),
|
||||
}, &folder.Folder{})
|
||||
require.NotEmpty(t, create2.Response)
|
||||
require.Equal(t, 409, create2.Response.StatusCode)
|
||||
require.Equal(t, 200, create2.Response.StatusCode) // it is OK
|
||||
}
|
||||
|
||||
func doCreateEnsureTitleIsTrimmedTest(t *testing.T, helper *apis.K8sTestHelper) {
|
||||
@@ -699,7 +699,6 @@ func TestFoldersCreateAPIEndpointK8S(t *testing.T) {
|
||||
folderWithTitleEmpty := "{ \"title\": \"\"}"
|
||||
folderWithInvalidUid := "{ \"uid\": \"::::::::::::\", \"title\": \"Another folder\"}"
|
||||
folderWithUIDTooLong := "{ \"uid\": \"asdfghjklqwertyuiopzxcvbnmasdfghjklqwertyuiopzxcvbnmasdfghjklqwertyuiopzxcvbnm\", \"title\": \"Third folder\"}"
|
||||
folderWithSameName := "{\"title\": \"same name\"}"
|
||||
|
||||
type testCase struct {
|
||||
description string
|
||||
@@ -770,15 +769,6 @@ func TestFoldersCreateAPIEndpointK8S(t *testing.T) {
|
||||
expectedFolderSvcError: dashboards.ErrDashboardUidTooLong,
|
||||
permissions: folderCreatePermission,
|
||||
},
|
||||
{
|
||||
description: "folder creation fails given folder service error %s",
|
||||
input: folderWithSameName,
|
||||
expectedCode: http.StatusConflict,
|
||||
expectedMessage: dashboards.ErrFolderSameNameExists.Error(),
|
||||
expectedFolderSvcError: dashboards.ErrFolderSameNameExists,
|
||||
createSecondRecord: true,
|
||||
permissions: folderCreatePermission,
|
||||
},
|
||||
{
|
||||
description: "folder creation fails given folder service error %s",
|
||||
input: folderWithoutParentInput,
|
||||
|
||||
Reference in New Issue
Block a user