@ -124,14 +124,18 @@ func TestIntegrationFoldersApp(t *testing.T) {
} ` , string ( v1Disco ) )
} )
t . Run ( "with dual write (unified storage, mode 0)" , func ( t * testing . T ) {
// 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 : grafanarest . Mode0 ,
DualWriterMode : modeDw ,
} ,
} ,
EnableFeatureToggles : [ ] string {
@ -140,30 +144,31 @@ func TestIntegrationFoldersApp(t *testing.T) {
} ) )
} )
t . Run ( "with dual write (unified storage, mode 1)" , func ( t * testing . T ) {
doFolderTests ( t , apis . NewK8sTestHelper ( t , testinfra . GrafanaOpts {
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 : grafanarest . Mode1 ,
DualWriterMode : modeDw ,
} ,
} ,
EnableFeatureToggles : [ ] string {
featuremgmt . FlagKubernetesClientDashboardsFolders ,
featuremgmt . FlagNestedFolders ,
} ,
} ) )
} )
t . Run ( "with dual write (unified storage, mode 1, create nested folders)" , func ( t * testing . T ) {
doNested CreateTest ( t , apis . NewK8sTestHelper ( t , testinfra . GrafanaOpts {
t . Run ( fmt . Sprintf ( "with dual write (unified storage, mode %v, create existing folder)" , modeDw ) , func ( t * testing . T ) {
doCreateDuplicateFolder Test ( t , apis . NewK8sTestHelper ( t , testinfra . GrafanaOpts {
AppModeProduction : true ,
DisableAnonymous : true ,
APIServerStorageType : "unified" ,
UnifiedStorageConfig : map [ string ] setting . UnifiedStorageConfig {
folders . RESOURCEGROUP : {
DualWriterMode : grafanarest . Mode1 ,
DualWriterMode : modeDw ,
} ,
} ,
EnableFeatureToggles : [ ] string {
@ -173,14 +178,31 @@ func TestIntegrationFoldersApp(t *testing.T) {
} ) )
} )
t . Run ( "with dual write (unified storage, mode 1, create existing folder)" , func ( t * testing . T ) {
doCreateDuplicateFolder Test( t , apis . NewK8sTestHelper ( t , testinfra . GrafanaOpts {
t . Run ( fmt . Sprintf ( "when creating a folder, mode %v, it should trim leading and trailing spaces" , modeDw ) , func ( t * testing . T ) {
doCreateEnsureTitleIsTrimmed Test ( t , apis . NewK8sTestHelper ( t , testinfra . GrafanaOpts {
AppModeProduction : true ,
DisableAnonymous : true ,
APIServerStorageType : "unified" ,
UnifiedStorageConfig : map [ string ] setting . UnifiedStorageConfig {
folders . RESOURCEGROUP : {
DualWriterMode : grafanarest . Mode1 ,
DualWriterMode : modeDw ,
} ,
} ,
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 {
@ -189,6 +211,7 @@ func TestIntegrationFoldersApp(t *testing.T) {
} ,
} ) )
} )
}
// 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" : { }
} `