Skip to content

Commit

Permalink
[CLI Config Parity] Migrate enableHNS and create empty file usage to …
Browse files Browse the repository at this point in the history
…new config (#2350)

* migrate enable hns and create empty file usage

* migrate enable hns and create empty file usage to new config
  • Loading branch information
ashmeenkaur committed Aug 19, 2024
1 parent 397d9b1 commit 6a87ccb
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 9 deletions.
34 changes: 34 additions & 0 deletions cmd/config_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,37 @@ func TestValidateConfigFile_ListConfigSuccessful(t *testing.T) {
})
}
}

func TestValidateConfigFile_EnableHNSConfigSuccessful(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{
EnableHns: false,
},
},
{
name: "valid_config_file",
configFile: "testdata/valid_config.yaml",
expectedConfig: &cfg.Config{
EnableHns: 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.EnableHns, gotConfig.EnableHns)
}
})
}
}
37 changes: 37 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,40 @@ func TestArgsParsing_ListFlags(t *testing.T) {
})
}
}

func TestArgsParsing_EnableHNSFlags(t *testing.T) {
tests := []struct {
name string
args []string
expectedEnableHNS bool
}{
{
name: "normal",
args: []string{"gcsfuse", "--enable-hns", "abc", "pqr"},
expectedEnableHNS: true,
},
{
name: "default",
args: []string{"gcsfuse", "abc", "pqr"},
expectedEnableHNS: false,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var gotEnableHNS bool
cmd, err := NewRootCmd(func(cfg *cfg.Config, _, _ string) error {
gotEnableHNS = cfg.EnableHns
return nil
})
require.Nil(t, err)
cmd.SetArgs(tc.args)

err = cmd.Execute()

if assert.NoError(t, err) {
assert.Equal(t, tc.expectedEnableHNS, gotEnableHNS)
}
})
}
}
1 change: 1 addition & 0 deletions cmd/testdata/valid_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ file-system:
temp-dir: ~/temp
list:
enable-empty-managed-folders: true
enable-hns: true
8 changes: 4 additions & 4 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func makeRootForBucket(
fs.mtimeClock,
fs.cacheClock,
fs.mountConfig.MetadataCacheConfig.TypeCacheMaxSizeMB,
fs.mountConfig.EnableHNS,
fs.newConfig.EnableHns,
)
}

Expand Down Expand Up @@ -731,7 +731,7 @@ func (fs *fileSystem) createExplicitDirInode(inodeID fuseops.InodeID, ic inode.C
fs.mtimeClock,
fs.cacheClock,
fs.mountConfig.MetadataCacheConfig.TypeCacheMaxSizeMB,
fs.mountConfig.EnableHNS)
fs.newConfig.EnableHns)

return in
}
Expand Down Expand Up @@ -774,7 +774,7 @@ func (fs *fileSystem) mintInode(ic inode.Core) (in inode.Inode) {
fs.mtimeClock,
fs.cacheClock,
fs.mountConfig.MetadataCacheConfig.TypeCacheMaxSizeMB,
fs.mountConfig.EnableHNS,
fs.newConfig.EnableHns,
)

case inode.IsSymlink(ic.MinObject):
Expand Down Expand Up @@ -1709,7 +1709,7 @@ func (fs *fileSystem) CreateFile(
}
// Create the child.
var child inode.Inode
if fs.mountConfig.CreateEmptyFile {
if fs.newConfig.Write.CreateEmptyFile {
child, err = fs.createFile(ctx, op.Parent, op.Name, op.Mode)
} else {
child, err = fs.createLocalFile(op.Parent, op.Name)
Expand Down
4 changes: 2 additions & 2 deletions internal/fs/hns_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"path"
"testing"

"github.com/googlecloudplatform/gcsfuse/v2/internal/config"
"github.com/googlecloudplatform/gcsfuse/v2/cfg"
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage/gcs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -34,7 +34,7 @@ type HNSBucketTests struct {
func TestHNSBucketTests(t *testing.T) { suite.Run(t, new(HNSBucketTests)) }

func (t *HNSBucketTests) SetupSuite() {
t.serverCfg.MountConfig = &config.MountConfig{EnableHNS: true}
t.serverCfg.NewConfig = &cfg.Config{EnableHns: true}
t.serverCfg.ImplicitDirectories = false
bucketType = gcs.Hierarchical
t.fsTest.SetUpTestSuite()
Expand Down
5 changes: 2 additions & 3 deletions internal/fs/local_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"time"

"github.com/googlecloudplatform/gcsfuse/v2/cfg"
"github.com/googlecloudplatform/gcsfuse/v2/internal/config"
"github.com/googlecloudplatform/gcsfuse/v2/internal/fs/inode"
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage/gcs"
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage/storageutil"
Expand Down Expand Up @@ -61,8 +60,8 @@ func init() {

func (t *LocalFileTest) SetUpTestSuite() {
t.serverCfg.ImplicitDirectories = true
t.serverCfg.MountConfig = &config.MountConfig{
WriteConfig: cfg.WriteConfig{
t.serverCfg.NewConfig = &cfg.Config{
Write: cfg.WriteConfig{
CreateEmptyFile: false,
}}
t.fsTest.SetUpTestSuite()
Expand Down

0 comments on commit 6a87ccb

Please sign in to comment.