fix(commands): storage cmd fail when implicit config absent (#5213)
This fixes an issue where if the implicit config location of configuration.yml does not exist that an error is returned. This does not affect the behavior when the method was either implicit or environment. Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>pull/5204/head^2
parent
0312defcd7
commit
569af0fef0
|
@ -215,13 +215,14 @@ const (
|
||||||
func loadXEnvCLIConfigValues(cmd *cobra.Command) (configs []string, filters []configuration.FileFilter, err error) {
|
func loadXEnvCLIConfigValues(cmd *cobra.Command) (configs []string, filters []configuration.FileFilter, err error) {
|
||||||
var (
|
var (
|
||||||
filterNames []string
|
filterNames []string
|
||||||
|
result XEnvCLIResult
|
||||||
)
|
)
|
||||||
|
|
||||||
if configs, _, err = loadXEnvCLIStringSliceValue(cmd, cmdFlagEnvNameConfig, cmdFlagNameConfig); err != nil {
|
if configs, result, err = loadXEnvCLIStringSliceValue(cmd, cmdFlagEnvNameConfig, cmdFlagNameConfig); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if configs, err = loadXNormalizedPaths(configs); err != nil {
|
if configs, err = loadXNormalizedPaths(configs, result); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +237,7 @@ func loadXEnvCLIConfigValues(cmd *cobra.Command) (configs []string, filters []co
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadXNormalizedPaths(paths []string) ([]string, error) {
|
func loadXNormalizedPaths(paths []string, result XEnvCLIResult) ([]string, error) {
|
||||||
var (
|
var (
|
||||||
configs, files, dirs []string
|
configs, files, dirs []string
|
||||||
err error
|
err error
|
||||||
|
@ -258,11 +259,16 @@ func loadXNormalizedPaths(paths []string) ([]string, error) {
|
||||||
files = append(files, path)
|
files = append(files, path)
|
||||||
default:
|
default:
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
switch result {
|
||||||
|
case XEnvCLIResultCLIImplicit:
|
||||||
|
continue
|
||||||
|
default:
|
||||||
configs = append(configs, path)
|
configs = append(configs, path)
|
||||||
files = append(files, path)
|
files = append(files, path)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("error occurred stating file at path '%s': %w", path, err)
|
return nil, fmt.Errorf("error occurred stating file at path '%s': %w", path, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ func TestLoadXNormalizedPaths(t *testing.T) {
|
||||||
ayml := filepath.Join(configdir, "a.yml")
|
ayml := filepath.Join(configdir, "a.yml")
|
||||||
byml := filepath.Join(configdir, "b.yml")
|
byml := filepath.Join(configdir, "b.yml")
|
||||||
cyml := filepath.Join(otherdir, "c.yml")
|
cyml := filepath.Join(otherdir, "c.yml")
|
||||||
|
dyml := filepath.Join(otherdir, "d.yml")
|
||||||
|
|
||||||
file, err = os.Create(ayml)
|
file, err = os.Create(ayml)
|
||||||
|
|
||||||
|
@ -142,30 +143,44 @@ func TestLoadXNormalizedPaths(t *testing.T) {
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
haveX XEnvCLIResult
|
||||||
have, expected []string
|
have, expected []string
|
||||||
expectedErr string
|
expectedErr string
|
||||||
}{
|
}{
|
||||||
{"ShouldAllowFiles",
|
{"ShouldAllowFiles",
|
||||||
|
XEnvCLIResultCLIImplicit, []string{ayml},
|
||||||
[]string{ayml},
|
[]string{ayml},
|
||||||
[]string{ayml}, "",
|
"",
|
||||||
|
},
|
||||||
|
{"ShouldSkipFilesNotExistImplicit",
|
||||||
|
XEnvCLIResultCLIImplicit, []string{dyml},
|
||||||
|
[]string(nil),
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{"ShouldNotErrFilesNotExistExplicit",
|
||||||
|
XEnvCLIResultCLIExplicit, []string{dyml},
|
||||||
|
[]string{dyml},
|
||||||
|
"",
|
||||||
},
|
},
|
||||||
{"ShouldAllowDirectories",
|
{"ShouldAllowDirectories",
|
||||||
|
XEnvCLIResultCLIImplicit, []string{configdir},
|
||||||
[]string{configdir},
|
[]string{configdir},
|
||||||
[]string{configdir}, "",
|
"",
|
||||||
},
|
},
|
||||||
{"ShouldAllowFilesDirectories",
|
{"ShouldAllowFilesDirectories",
|
||||||
|
XEnvCLIResultCLIImplicit, []string{ayml, otherdir},
|
||||||
[]string{ayml, otherdir},
|
[]string{ayml, otherdir},
|
||||||
[]string{ayml, otherdir}, "",
|
"",
|
||||||
},
|
},
|
||||||
{"ShouldRaiseErrOnOverlappingFilesDirectories",
|
{"ShouldRaiseErrOnOverlappingFilesDirectories",
|
||||||
[]string{ayml, configdir},
|
XEnvCLIResultCLIImplicit, []string{ayml, configdir},
|
||||||
nil, fmt.Sprintf("failed to load config directory '%s': the config file '%s' is in that directory which is not supported", configdir, ayml),
|
nil, fmt.Sprintf("failed to load config directory '%s': the config file '%s' is in that directory which is not supported", configdir, ayml),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
actual, actualErr := loadXNormalizedPaths(tc.have)
|
actual, actualErr := loadXNormalizedPaths(tc.have, tc.haveX)
|
||||||
|
|
||||||
assert.Equal(t, tc.expected, actual)
|
assert.Equal(t, tc.expected, actual)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue