Skip to content

Commit

Permalink
Restrict visibility (#2724)
Browse files Browse the repository at this point in the history
Make NewRootCmd package-private.
  • Loading branch information
kislaykishore authored Nov 29, 2024
1 parent 7d6e7a3 commit 6ea65a7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cmd/config_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
func getConfigObject(t *testing.T, args []string) (*cfg.Config, error) {
t.Helper()
var c *cfg.Config
cmd, err := NewRootCmd(func(config *cfg.Config, _, _ string) error {
cmd, err := newRootCmd(func(config *cfg.Config, _, _ string) error {
c = config
return nil
})
Expand Down
6 changes: 3 additions & 3 deletions cmd/datatypes_parsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func TestCLIFlagPassing(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
var c *cfg.Config
command, err := NewRootCmd(func(config *cfg.Config, _, _ string) error {
command, err := newRootCmd(func(config *cfg.Config, _, _ string) error {
c = config
return nil
})
Expand Down Expand Up @@ -747,7 +747,7 @@ func TestConfigPassing(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
var c *cfg.Config
command, err := NewRootCmd(func(config *cfg.Config, _, _ string) error {
command, err := newRootCmd(func(config *cfg.Config, _, _ string) error {
c = config
return nil
})
Expand Down Expand Up @@ -802,7 +802,7 @@ func TestPredefinedFlagThrowNoError(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
command, err := NewRootCmd(func(config *cfg.Config, _, _ string) error {
command, err := newRootCmd(func(config *cfg.Config, _, _ string) error {
return nil
})
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (

type mountFn func(c *cfg.Config, bucketName, mountPoint string) error

// NewRootCmd accepts the mountFn that it executes with the parsed configuration
func NewRootCmd(m mountFn) (*cobra.Command, error) {
// newRootCmd accepts the mountFn that it executes with the parsed configuration
func newRootCmd(m mountFn) (*cobra.Command, error) {
var (
configObj cfg.Config
cfgFile string
Expand Down Expand Up @@ -147,7 +147,7 @@ func convertToPosixArgs(args []string, c *cobra.Command) []string {
}

var ExecuteMountCmd = func() {
rootCmd, err := NewRootCmd(Mount)
rootCmd, err := newRootCmd(Mount)
if err != nil {
log.Fatalf("Error occurred while creating the root command: %v", err)
}
Expand Down
38 changes: 19 additions & 19 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func TestDefaultMaxParallelDownloads(t *testing.T) {
var actual *cfg.Config
cmd, err := NewRootCmd(func(c *cfg.Config, _, _ string) error {
cmd, err := newRootCmd(func(c *cfg.Config, _, _ string) error {
actual = c
return nil
})
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestCobraArgsNumInRange(t *testing.T) {

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

Expand Down Expand Up @@ -127,7 +127,7 @@ func TestArgsParsing_MountPoint(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var bucketName, mountPoint string
cmd, err := NewRootCmd(func(_ *cfg.Config, b string, m string) error {
cmd, err := newRootCmd(func(_ *cfg.Config, b string, m string) error {
bucketName = b
mountPoint = m
return nil
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestArgsParsing_MountOptions(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var mountOptions []string
cmd, err := NewRootCmd(func(cfg *cfg.Config, _, _ string) error {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
mountOptions = cfg.FileSystem.FuseOptions
return nil
})
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestArgsParsing_WriteConfigFlags(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var wc cfg.WriteConfig
cmd, err := NewRootCmd(func(cfg *cfg.Config, _, _ string) error {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
wc = cfg.Write
return nil
})
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestArgsParsing_FileCacheFlags(t *testing.T) {
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 {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
gotConfig = cfg
return nil
})
Expand Down Expand Up @@ -395,7 +395,7 @@ func TestArgParsing_ExperimentalMetadataPrefetchFlag(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var experimentalMetadataPrefetch string
cmd, err := NewRootCmd(func(cfg *cfg.Config, _, _ string) error {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
experimentalMetadataPrefetch = cfg.MetadataCache.ExperimentalMetadataPrefetchOnMount
return nil
})
Expand Down Expand Up @@ -428,7 +428,7 @@ func TestArgParsing_ExperimentalMetadataPrefetchFlag_Failed(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cmd, err := NewRootCmd(func(cfg *cfg.Config, _, _ string) error {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
return nil
})
require.Nil(t, err)
Expand Down Expand Up @@ -478,7 +478,7 @@ func TestArgsParsing_GCSAuthFlags(t *testing.T) {
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 {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
gotConfig = cfg
return nil
})
Expand Down Expand Up @@ -516,7 +516,7 @@ func TestArgsParsing_GCSAuthFlagsThrowsError(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cmd, err := NewRootCmd(func(cfg *cfg.Config, _, _ string) error {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
return nil
})
require.Nil(t, err)
Expand Down Expand Up @@ -576,7 +576,7 @@ func TestArgsParsing_GCSConnectionFlags(t *testing.T) {
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 {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
gotConfig = cfg
return nil
})
Expand Down Expand Up @@ -620,7 +620,7 @@ func TestArgsParsing_GCSConnectionFlagsThrowsError(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cmd, err := NewRootCmd(func(cfg *cfg.Config, _, _ string) error {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
return nil
})
require.Nil(t, err)
Expand Down Expand Up @@ -704,7 +704,7 @@ func TestArgsParsing_FileSystemFlags(t *testing.T) {
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 {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
gotConfig = cfg
return nil
})
Expand Down Expand Up @@ -749,7 +749,7 @@ func TestArgsParsing_FileSystemFlagsThrowsError(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cmd, err := NewRootCmd(func(cfg *cfg.Config, _, _ string) error {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
return nil
})
require.Nil(t, err)
Expand Down Expand Up @@ -785,7 +785,7 @@ func TestArgsParsing_ListFlags(t *testing.T) {
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 {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
gotConfig = cfg
return nil
})
Expand Down Expand Up @@ -822,7 +822,7 @@ func TestArgsParsing_EnableHNSFlags(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var gotEnableHNS bool
cmd, err := NewRootCmd(func(cfg *cfg.Config, _, _ string) error {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
gotEnableHNS = cfg.EnableHns
return nil
})
Expand Down Expand Up @@ -886,7 +886,7 @@ func TestArgsParsing_MetricsFlags(t *testing.T) {
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 {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
gotConfig = cfg
return nil
})
Expand Down Expand Up @@ -943,7 +943,7 @@ func TestArgsParsing_MetricsViewConfig(t *testing.T) {
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 {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
gotConfig = cfg
return nil
})
Expand Down Expand Up @@ -1002,7 +1002,7 @@ func TestArgsParsing_MetadataCacheFlags(t *testing.T) {
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 {
cmd, err := newRootCmd(func(cfg *cfg.Config, _, _ string) error {
gotConfig = cfg
return nil
})
Expand Down

0 comments on commit 6ea65a7

Please sign in to comment.