fixed error on invalid config path (#250)

This commit is contained in:
RoyUP9
2021-08-30 11:43:44 +03:00
committed by GitHub
parent a310953f05
commit 80237c8090
2 changed files with 20 additions and 6 deletions

View File

@@ -71,7 +71,6 @@ func TestTapAndFetch(t *testing.T) {
}
entries := requestResult.([]interface{})
if len(entries) == 0 {
return fmt.Errorf("unexpected entries result - Expected more than 0 entries")
}
@@ -523,6 +522,10 @@ func TestTapRedact(t *testing.T) {
}
entries := requestResult.([]interface{})
if len(entries) == 0 {
return fmt.Errorf("unexpected entries result - Expected more than 0 entries")
}
firstEntry := entries[0].(map[string]interface{})
entryUrl := fmt.Sprintf("%v/api/entries/%v", apiServerUrl, firstEntry["id"])
@@ -625,6 +628,10 @@ func TestTapNoRedact(t *testing.T) {
}
entries := requestResult.([]interface{})
if len(entries) == 0 {
return fmt.Errorf("unexpected entries result - Expected more than 0 entries")
}
firstEntry := entries[0].(map[string]interface{})
entryUrl := fmt.Sprintf("%v/api/entries/%v", apiServerUrl, firstEntry["id"])
@@ -727,6 +734,10 @@ func TestTapRegexMasking(t *testing.T) {
}
entries := requestResult.([]interface{})
if len(entries) == 0 {
return fmt.Errorf("unexpected entries result - Expected more than 0 entries")
}
firstEntry := entries[0].(map[string]interface{})
entryUrl := fmt.Sprintf("%v/api/entries/%v", apiServerUrl, firstEntry["id"])

View File

@@ -37,12 +37,15 @@ func InitConfig(cmd *cobra.Command) error {
return err
}
configFilePath := cmd.Flags().Lookup(ConfigFilePathCommandName).Value.String()
configFilePathFlag := cmd.Flags().Lookup(ConfigFilePathCommandName)
configFilePath := configFilePathFlag.Value.String()
if err := mergeConfigFile(configFilePath); err != nil {
_, isPathError := err.(*os.PathError)
if configFilePathFlag.Changed || !isPathError {
return fmt.Errorf("invalid config, %w\n"+
"you can regenerate the file by removing it (%v) and using `mizu config -r`", err, configFilePath)
}
}
cmd.Flags().Visit(initFlag)
@@ -67,7 +70,7 @@ func GetConfigWithDefaults() (string, error) {
func mergeConfigFile(configFilePath string) error {
reader, openErr := os.Open(configFilePath)
if openErr != nil {
return nil
return openErr
}
buf, readErr := ioutil.ReadAll(reader)