From f6a5e03bfb0c9f464ddd253ba8d7406d7ff5007c Mon Sep 17 00:00:00 2001 From: maicon Date: Mon, 28 Oct 2024 10:24:28 -0300 Subject: [PATCH] UniStore: Add testcase for trimming folder title (#95405) Signed-off-by: Maicon Costa --- pkg/tests/apis/folder/folders_test.go | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pkg/tests/apis/folder/folders_test.go b/pkg/tests/apis/folder/folders_test.go index 0c5d3248bf8..a5704b179fc 100644 --- a/pkg/tests/apis/folder/folders_test.go +++ b/pkg/tests/apis/folder/folders_test.go @@ -329,6 +329,24 @@ func TestIntegrationFoldersApp(t *testing.T) { }, })) }) + + t.Run("when creating a folder it should trim leading and trailing spaces", func(t *testing.T) { + doCreateEnsureTitleIsTrimmedTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ + AppModeProduction: true, + DisableAnonymous: true, + APIServerStorageType: "unified", + UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ + folderv0alpha1.RESOURCEGROUP: { + DualWriterMode: grafanarest.Mode1, + }, + }, + EnableFeatureToggles: []string{ + featuremgmt.FlagGrafanaAPIServerTestingWithExperimentalAPIs, + featuremgmt.FlagNestedFolders, + featuremgmt.FlagKubernetesFolders, + }, + })) + }) } func doFolderTests(t *testing.T, helper *apis.K8sTestHelper) *apis.K8sTestHelper { @@ -549,6 +567,28 @@ func doCreateDuplicateFolderTest(t *testing.T, helper *apis.K8sTestHelper) { require.Equal(t, 409, create2.Response.StatusCode) } +func doCreateEnsureTitleIsTrimmedTest(t *testing.T, helper *apis.K8sTestHelper) { + client := helper.GetResourceClient(apis.ResourceClientArgs{ + User: helper.Org1.Admin, + GVR: gvr, + }) + + payload := `{ + "title": " my folder ", + "uid": "" + }` + + // When creating a folder it should trim leading and trailing spaces in both dashboard and folder tables + create := apis.DoRequest(helper, apis.RequestParams{ + User: client.Args.User, + Method: http.MethodPost, + Path: "/api/folders", + Body: []byte(payload), + }, &folder.Folder{}) + require.NotNil(t, create.Result) + require.Equal(t, "my folder", create.Result.Title) +} + func TestIntegrationFolderCreatePermissions(t *testing.T) { if testing.Short() { t.Skip("skipping integration test")