diff --git a/pkg/registry/apis/folders/conversions.go b/pkg/registry/apis/folders/conversions.go index bf743893816..e0f748fa54b 100644 --- a/pkg/registry/apis/folders/conversions.go +++ b/pkg/registry/apis/folders/conversions.go @@ -57,7 +57,7 @@ func convertToK8sResource(v *folder.Folder, namespacer request.NamespaceMapper) }, Spec: folders.FolderSpec{ Title: v.Title, - Description: descr(v.Description), + Description: &v.Description, }, } @@ -94,10 +94,3 @@ func convertToK8sResource(v *folder.Folder, namespacer request.NamespaceMapper) f.UID = gapiutil.CalculateClusterWideUID(f) return f, nil } - -func descr(str string) *string { - if str == "" { - return nil - } - return &str -} diff --git a/pkg/tests/apis/folder/folders_test.go b/pkg/tests/apis/folder/folders_test.go index 03f8038ebdf..29a5a6f1814 100644 --- a/pkg/tests/apis/folder/folders_test.go +++ b/pkg/tests/apis/folder/folders_test.go @@ -124,71 +124,94 @@ func TestIntegrationFoldersApp(t *testing.T) { }`, string(v1Disco)) }) - t.Run("with dual write (unified storage, mode 0)", func(t *testing.T) { - doFolderTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ - AppModeProduction: true, - DisableAnonymous: true, - APIServerStorageType: "unified", - UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ - folders.RESOURCEGROUP: { - DualWriterMode: grafanarest.Mode0, + // test on all dualwriter modes + for mode := 0; mode <= 4; mode++ { + modeDw := grafanarest.DualWriterMode(mode) + + t.Run(fmt.Sprintf("with dual write (unified storage, mode %v)", modeDw), func(t *testing.T) { + doFolderTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ + AppModeProduction: true, + DisableAnonymous: true, + APIServerStorageType: "unified", + UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ + folders.RESOURCEGROUP: { + DualWriterMode: modeDw, + }, }, - }, - EnableFeatureToggles: []string{ - featuremgmt.FlagKubernetesClientDashboardsFolders, - }, - })) - }) + EnableFeatureToggles: []string{ + featuremgmt.FlagKubernetesClientDashboardsFolders, + }, + })) + }) - t.Run("with dual write (unified storage, mode 1)", func(t *testing.T) { - doFolderTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ - AppModeProduction: true, - DisableAnonymous: true, - APIServerStorageType: "unified", - UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ - folders.RESOURCEGROUP: { - DualWriterMode: grafanarest.Mode1, + t.Run(fmt.Sprintf("with dual write (unified storage, mode %v, create nested folders)", modeDw), func(t *testing.T) { + doNestedCreateTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ + AppModeProduction: true, + DisableAnonymous: true, + APIServerStorageType: "unified", + UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ + folders.RESOURCEGROUP: { + DualWriterMode: modeDw, + }, }, - }, - EnableFeatureToggles: []string{ - featuremgmt.FlagKubernetesClientDashboardsFolders, - }, - })) - }) + EnableFeatureToggles: []string{ + featuremgmt.FlagKubernetesClientDashboardsFolders, + featuremgmt.FlagNestedFolders, + }, + })) + }) - t.Run("with dual write (unified storage, mode 1, create nested folders)", func(t *testing.T) { - doNestedCreateTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ - AppModeProduction: true, - DisableAnonymous: true, - APIServerStorageType: "unified", - UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ - folders.RESOURCEGROUP: { - DualWriterMode: grafanarest.Mode1, + t.Run(fmt.Sprintf("with dual write (unified storage, mode %v, create existing folder)", modeDw), func(t *testing.T) { + doCreateDuplicateFolderTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ + AppModeProduction: true, + DisableAnonymous: true, + APIServerStorageType: "unified", + UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ + folders.RESOURCEGROUP: { + DualWriterMode: modeDw, + }, }, - }, - EnableFeatureToggles: []string{ - featuremgmt.FlagKubernetesClientDashboardsFolders, - featuremgmt.FlagNestedFolders, - }, - })) - }) + EnableFeatureToggles: []string{ + featuremgmt.FlagKubernetesClientDashboardsFolders, + featuremgmt.FlagNestedFolders, + }, + })) + }) - t.Run("with dual write (unified storage, mode 1, create existing folder)", func(t *testing.T) { - doCreateDuplicateFolderTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ - AppModeProduction: true, - DisableAnonymous: true, - APIServerStorageType: "unified", - UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ - folders.RESOURCEGROUP: { - DualWriterMode: grafanarest.Mode1, + t.Run(fmt.Sprintf("when creating a folder, mode %v, it should trim leading and trailing spaces", modeDw), func(t *testing.T) { + doCreateEnsureTitleIsTrimmedTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ + AppModeProduction: true, + DisableAnonymous: true, + APIServerStorageType: "unified", + UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ + folders.RESOURCEGROUP: { + DualWriterMode: modeDw, + }, }, - }, - EnableFeatureToggles: []string{ - featuremgmt.FlagKubernetesClientDashboardsFolders, - featuremgmt.FlagNestedFolders, - }, - })) - }) + EnableFeatureToggles: []string{ + featuremgmt.FlagKubernetesClientDashboardsFolders, + featuremgmt.FlagNestedFolders, + }, + })) + }) + + t.Run(fmt.Sprintf("with dual write (unified storage, mode %v, create circular reference folder)", modeDw), func(t *testing.T) { + doCreateCircularReferenceFolderTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ + AppModeProduction: true, + DisableAnonymous: true, + APIServerStorageType: "unified", + UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ + folders.RESOURCEGROUP: { + DualWriterMode: modeDw, + }, + }, + EnableFeatureToggles: []string{ + featuremgmt.FlagKubernetesClientDashboardsFolders, + featuremgmt.FlagNestedFolders, + }, + })) + }) + } // This is a general test for the unified storage list operation. We don't have a common test // directory for now, so we (search and storage) keep it here as we own this part of the tests. @@ -221,40 +244,6 @@ 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{ - folders.RESOURCEGROUP: { - DualWriterMode: grafanarest.Mode1, - }, - }, - EnableFeatureToggles: []string{ - featuremgmt.FlagKubernetesClientDashboardsFolders, - featuremgmt.FlagNestedFolders, - }, - })) - }) - - t.Run("with dual write (unified storage, mode 1, create circular reference folder)", func(t *testing.T) { - doCreateCircularReferenceFolderTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ - AppModeProduction: true, - DisableAnonymous: true, - APIServerStorageType: "unified", - UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ - folders.RESOURCEGROUP: { - DualWriterMode: grafanarest.Mode1, - }, - }, - EnableFeatureToggles: []string{ - featuremgmt.FlagKubernetesClientDashboardsFolders, - featuremgmt.FlagNestedFolders, - }, - })) - }) } func doFolderTests(t *testing.T, helper *apis.K8sTestHelper) *apis.K8sTestHelper { @@ -280,20 +269,25 @@ func doFolderTests(t *testing.T, helper *apis.K8sTestHelper) *apis.K8sTestHelper require.NotNil(t, legacyCreate.Result) uid := legacyCreate.Result.UID require.NotEmpty(t, uid) + //nolint:staticcheck + id := legacyCreate.Result.ID + require.NotEmpty(t, id) + idStr := fmt.Sprintf("%d", id) expectedResult := `{ "apiVersion": "folder.grafana.app/v1beta1", "kind": "Folder", "metadata": { "creationTimestamp": "${creationTimestamp}", - "labels": {"grafana.app/deprecatedInternalID":"1"}, + "labels": {"grafana.app/deprecatedInternalID":"` + idStr + `"}, "name": "` + uid + `", "namespace": "default", "resourceVersion": "${resourceVersion}", "uid": "${uid}" }, "spec": { - "title": "Test" + "title": "Test", + "description": "" }, "status": {} }`