diff --git a/cmd/config_validation_test.go b/cmd/config_validation_test.go index ff38625ca9..cbf4f721ea 100644 --- a/cmd/config_validation_test.go +++ b/cmd/config_validation_test.go @@ -496,3 +496,37 @@ func TestValidateConfigFile_FileSystemConfigSuccessful(t *testing.T) { }) } } + +func TestValidateConfigFile_ListConfigSuccessful(t *testing.T) { + testCases := []struct { + name string + configFile string + expectedConfig *cfg.Config + }{ + { + // Test default values. + name: "empty_config_file", + configFile: "testdata/empty_file.yaml", + expectedConfig: &cfg.Config{ + List: cfg.ListConfig{EnableEmptyManagedFolders: false}, + }, + }, + { + name: "valid_config_file", + configFile: "testdata/valid_config.yaml", + expectedConfig: &cfg.Config{ + List: cfg.ListConfig{EnableEmptyManagedFolders: true}, + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + gotConfig, err := getConfigObjectWithConfigFile(t, tc.configFile) + + if assert.NoError(t, err) { + assert.EqualValues(t, tc.expectedConfig.List, gotConfig.List) + } + }) + } +} diff --git a/cmd/root_test.go b/cmd/root_test.go index 49d14aabcc..e6b1f50fe3 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -645,6 +645,7 @@ func TestArgsParsing_FileSystemFlags(t *testing.T) { }) } } + func TestArgsParsing_FileSystemFlagsThrowsError(t *testing.T) { tests := []struct { name string @@ -684,3 +685,44 @@ func TestArgsParsing_FileSystemFlagsThrowsError(t *testing.T) { }) } } + +func TestArgsParsing_ListFlags(t *testing.T) { + tests := []struct { + name string + args []string + expectedConfig *cfg.Config + }{ + { + name: "normal", + args: []string{"gcsfuse", "--enable-empty-managed-folders", "abc", "pqr"}, + expectedConfig: &cfg.Config{ + List: cfg.ListConfig{EnableEmptyManagedFolders: true}, + }, + }, + { + name: "default", + args: []string{"gcsfuse", "abc", "pqr"}, + expectedConfig: &cfg.Config{ + List: cfg.ListConfig{EnableEmptyManagedFolders: false}, + }, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + var gotConfig *cfg.Config + cmd, err := NewRootCmd(func(cfg *cfg.Config, _, _ string) error { + gotConfig = cfg + return nil + }) + require.Nil(t, err) + cmd.SetArgs(tc.args) + + err = cmd.Execute() + + if assert.NoError(t, err) { + assert.Equal(t, tc.expectedConfig.List, gotConfig.List) + } + }) + } +} diff --git a/cmd/testdata/valid_config.yaml b/cmd/testdata/valid_config.yaml index a3e5893fc4..cd5ca004da 100644 --- a/cmd/testdata/valid_config.yaml +++ b/cmd/testdata/valid_config.yaml @@ -38,3 +38,5 @@ file-system: kernel-list-cache-ttl-secs: 300 rename-dir-limit: 10 temp-dir: ~/temp +list: + enable-empty-managed-folders: true diff --git a/internal/fs/fs.go b/internal/fs/fs.go index aa09de77f2..c960aa2e49 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -268,7 +268,7 @@ func makeRootForBucket( Mtime: fs.mtimeClock.Now(), }, fs.implicitDirs, - fs.mountConfig.ListConfig.EnableEmptyManagedFolders, + fs.newConfig.List.EnableEmptyManagedFolders, fs.enableNonexistentTypeCache, fs.dirTypeCacheTTL, &syncerBucket, @@ -724,7 +724,7 @@ func (fs *fileSystem) createExplicitDirInode(inodeID fuseops.InodeID, ic inode.C Mtime: fs.mtimeClock.Now(), }, fs.implicitDirs, - fs.mountConfig.ListConfig.EnableEmptyManagedFolders, + fs.newConfig.List.EnableEmptyManagedFolders, fs.enableNonexistentTypeCache, fs.dirTypeCacheTTL, ic.Bucket, @@ -767,7 +767,7 @@ func (fs *fileSystem) mintInode(ic inode.Core) (in inode.Inode) { Mtime: fs.mtimeClock.Now(), }, fs.implicitDirs, - fs.mountConfig.ListConfig.EnableEmptyManagedFolders, + fs.newConfig.List.EnableEmptyManagedFolders, fs.enableNonexistentTypeCache, fs.dirTypeCacheTTL, ic.Bucket,