Skip to content

Commit

Permalink
migrate list config (#2343)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur authored Aug 13, 2024
1 parent 9d8afd9 commit 9da7d8d
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
34 changes: 34 additions & 0 deletions cmd/config_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}
42 changes: 42 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ func TestArgsParsing_FileSystemFlags(t *testing.T) {
})
}
}

func TestArgsParsing_FileSystemFlagsThrowsError(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -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)
}
})
}
}
2 changes: 2 additions & 0 deletions cmd/testdata/valid_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9da7d8d

Please sign in to comment.