Skip to content

Commit 18b5a9e

Browse files
Run TestIntegrationFoldersApp for all dualwriter modes on sqlite only (#107818)
* Run TestIntegrationFoldersApp for all dualwriter modes on sqlite only Signed-off-by: Maicon Costa <[email protected]> --------- Signed-off-by: Maicon Costa <[email protected]>
1 parent 86aa703 commit 18b5a9e

File tree

2 files changed

+89
-102
lines changed

2 files changed

+89
-102
lines changed

pkg/registry/apis/folders/conversions.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func convertToK8sResource(v *folder.Folder, namespacer request.NamespaceMapper)
5757
},
5858
Spec: folders.FolderSpec{
5959
Title: v.Title,
60-
Description: descr(v.Description),
60+
Description: &v.Description,
6161
},
6262
}
6363

@@ -94,10 +94,3 @@ func convertToK8sResource(v *folder.Folder, namespacer request.NamespaceMapper)
9494
f.UID = gapiutil.CalculateClusterWideUID(f)
9595
return f, nil
9696
}
97-
98-
func descr(str string) *string {
99-
if str == "" {
100-
return nil
101-
}
102-
return &str
103-
}

pkg/tests/apis/folder/folders_test.go

Lines changed: 88 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -124,71 +124,94 @@ func TestIntegrationFoldersApp(t *testing.T) {
124124
}`, string(v1Disco))
125125
})
126126

127-
t.Run("with dual write (unified storage, mode 0)", func(t *testing.T) {
128-
doFolderTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
129-
AppModeProduction: true,
130-
DisableAnonymous: true,
131-
APIServerStorageType: "unified",
132-
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
133-
folders.RESOURCEGROUP: {
134-
DualWriterMode: grafanarest.Mode0,
127+
// test on all dualwriter modes
128+
for mode := 0; mode <= 4; mode++ {
129+
modeDw := grafanarest.DualWriterMode(mode)
130+
131+
t.Run(fmt.Sprintf("with dual write (unified storage, mode %v)", modeDw), func(t *testing.T) {
132+
doFolderTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
133+
AppModeProduction: true,
134+
DisableAnonymous: true,
135+
APIServerStorageType: "unified",
136+
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
137+
folders.RESOURCEGROUP: {
138+
DualWriterMode: modeDw,
139+
},
135140
},
136-
},
137-
EnableFeatureToggles: []string{
138-
featuremgmt.FlagKubernetesClientDashboardsFolders,
139-
},
140-
}))
141-
})
141+
EnableFeatureToggles: []string{
142+
featuremgmt.FlagKubernetesClientDashboardsFolders,
143+
},
144+
}))
145+
})
142146

143-
t.Run("with dual write (unified storage, mode 1)", func(t *testing.T) {
144-
doFolderTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
145-
AppModeProduction: true,
146-
DisableAnonymous: true,
147-
APIServerStorageType: "unified",
148-
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
149-
folders.RESOURCEGROUP: {
150-
DualWriterMode: grafanarest.Mode1,
147+
t.Run(fmt.Sprintf("with dual write (unified storage, mode %v, create nested folders)", modeDw), func(t *testing.T) {
148+
doNestedCreateTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
149+
AppModeProduction: true,
150+
DisableAnonymous: true,
151+
APIServerStorageType: "unified",
152+
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
153+
folders.RESOURCEGROUP: {
154+
DualWriterMode: modeDw,
155+
},
151156
},
152-
},
153-
EnableFeatureToggles: []string{
154-
featuremgmt.FlagKubernetesClientDashboardsFolders,
155-
},
156-
}))
157-
})
157+
EnableFeatureToggles: []string{
158+
featuremgmt.FlagKubernetesClientDashboardsFolders,
159+
featuremgmt.FlagNestedFolders,
160+
},
161+
}))
162+
})
158163

159-
t.Run("with dual write (unified storage, mode 1, create nested folders)", func(t *testing.T) {
160-
doNestedCreateTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
161-
AppModeProduction: true,
162-
DisableAnonymous: true,
163-
APIServerStorageType: "unified",
164-
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
165-
folders.RESOURCEGROUP: {
166-
DualWriterMode: grafanarest.Mode1,
164+
t.Run(fmt.Sprintf("with dual write (unified storage, mode %v, create existing folder)", modeDw), func(t *testing.T) {
165+
doCreateDuplicateFolderTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
166+
AppModeProduction: true,
167+
DisableAnonymous: true,
168+
APIServerStorageType: "unified",
169+
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
170+
folders.RESOURCEGROUP: {
171+
DualWriterMode: modeDw,
172+
},
167173
},
168-
},
169-
EnableFeatureToggles: []string{
170-
featuremgmt.FlagKubernetesClientDashboardsFolders,
171-
featuremgmt.FlagNestedFolders,
172-
},
173-
}))
174-
})
174+
EnableFeatureToggles: []string{
175+
featuremgmt.FlagKubernetesClientDashboardsFolders,
176+
featuremgmt.FlagNestedFolders,
177+
},
178+
}))
179+
})
175180

176-
t.Run("with dual write (unified storage, mode 1, create existing folder)", func(t *testing.T) {
177-
doCreateDuplicateFolderTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
178-
AppModeProduction: true,
179-
DisableAnonymous: true,
180-
APIServerStorageType: "unified",
181-
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
182-
folders.RESOURCEGROUP: {
183-
DualWriterMode: grafanarest.Mode1,
181+
t.Run(fmt.Sprintf("when creating a folder, mode %v, it should trim leading and trailing spaces", modeDw), func(t *testing.T) {
182+
doCreateEnsureTitleIsTrimmedTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
183+
AppModeProduction: true,
184+
DisableAnonymous: true,
185+
APIServerStorageType: "unified",
186+
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
187+
folders.RESOURCEGROUP: {
188+
DualWriterMode: modeDw,
189+
},
184190
},
185-
},
186-
EnableFeatureToggles: []string{
187-
featuremgmt.FlagKubernetesClientDashboardsFolders,
188-
featuremgmt.FlagNestedFolders,
189-
},
190-
}))
191-
})
191+
EnableFeatureToggles: []string{
192+
featuremgmt.FlagKubernetesClientDashboardsFolders,
193+
featuremgmt.FlagNestedFolders,
194+
},
195+
}))
196+
})
197+
198+
t.Run(fmt.Sprintf("with dual write (unified storage, mode %v, create circular reference folder)", modeDw), func(t *testing.T) {
199+
doCreateCircularReferenceFolderTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
200+
AppModeProduction: true,
201+
DisableAnonymous: true,
202+
APIServerStorageType: "unified",
203+
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
204+
folders.RESOURCEGROUP: {
205+
DualWriterMode: modeDw,
206+
},
207+
},
208+
EnableFeatureToggles: []string{
209+
featuremgmt.FlagKubernetesClientDashboardsFolders,
210+
featuremgmt.FlagNestedFolders,
211+
},
212+
}))
213+
})
214+
}
192215

193216
// This is a general test for the unified storage list operation. We don't have a common test
194217
// 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) {
221244
})
222245
}
223246
})
224-
225-
t.Run("when creating a folder it should trim leading and trailing spaces", func(t *testing.T) {
226-
doCreateEnsureTitleIsTrimmedTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
227-
AppModeProduction: true,
228-
DisableAnonymous: true,
229-
APIServerStorageType: "unified",
230-
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
231-
folders.RESOURCEGROUP: {
232-
DualWriterMode: grafanarest.Mode1,
233-
},
234-
},
235-
EnableFeatureToggles: []string{
236-
featuremgmt.FlagKubernetesClientDashboardsFolders,
237-
featuremgmt.FlagNestedFolders,
238-
},
239-
}))
240-
})
241-
242-
t.Run("with dual write (unified storage, mode 1, create circular reference folder)", func(t *testing.T) {
243-
doCreateCircularReferenceFolderTest(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
244-
AppModeProduction: true,
245-
DisableAnonymous: true,
246-
APIServerStorageType: "unified",
247-
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
248-
folders.RESOURCEGROUP: {
249-
DualWriterMode: grafanarest.Mode1,
250-
},
251-
},
252-
EnableFeatureToggles: []string{
253-
featuremgmt.FlagKubernetesClientDashboardsFolders,
254-
featuremgmt.FlagNestedFolders,
255-
},
256-
}))
257-
})
258247
}
259248

260249
func doFolderTests(t *testing.T, helper *apis.K8sTestHelper) *apis.K8sTestHelper {
@@ -280,20 +269,25 @@ func doFolderTests(t *testing.T, helper *apis.K8sTestHelper) *apis.K8sTestHelper
280269
require.NotNil(t, legacyCreate.Result)
281270
uid := legacyCreate.Result.UID
282271
require.NotEmpty(t, uid)
272+
//nolint:staticcheck
273+
id := legacyCreate.Result.ID
274+
require.NotEmpty(t, id)
275+
idStr := fmt.Sprintf("%d", id)
283276

284277
expectedResult := `{
285278
"apiVersion": "folder.grafana.app/v1beta1",
286279
"kind": "Folder",
287280
"metadata": {
288281
"creationTimestamp": "${creationTimestamp}",
289-
"labels": {"grafana.app/deprecatedInternalID":"1"},
282+
"labels": {"grafana.app/deprecatedInternalID":"` + idStr + `"},
290283
"name": "` + uid + `",
291284
"namespace": "default",
292285
"resourceVersion": "${resourceVersion}",
293286
"uid": "${uid}"
294287
},
295288
"spec": {
296-
"title": "Test"
289+
"title": "Test",
290+
"description": ""
297291
},
298292
"status": {}
299293
}`

0 commit comments

Comments
 (0)