mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-13 05:11:34 +00:00
fixed error on invalid config path (#250)
This commit is contained in:
@@ -71,7 +71,6 @@ func TestTapAndFetch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries := requestResult.([]interface{})
|
entries := requestResult.([]interface{})
|
||||||
|
|
||||||
if len(entries) == 0 {
|
if len(entries) == 0 {
|
||||||
return fmt.Errorf("unexpected entries result - Expected more than 0 entries")
|
return fmt.Errorf("unexpected entries result - Expected more than 0 entries")
|
||||||
}
|
}
|
||||||
@@ -523,6 +522,10 @@ func TestTapRedact(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries := requestResult.([]interface{})
|
entries := requestResult.([]interface{})
|
||||||
|
if len(entries) == 0 {
|
||||||
|
return fmt.Errorf("unexpected entries result - Expected more than 0 entries")
|
||||||
|
}
|
||||||
|
|
||||||
firstEntry := entries[0].(map[string]interface{})
|
firstEntry := entries[0].(map[string]interface{})
|
||||||
|
|
||||||
entryUrl := fmt.Sprintf("%v/api/entries/%v", apiServerUrl, firstEntry["id"])
|
entryUrl := fmt.Sprintf("%v/api/entries/%v", apiServerUrl, firstEntry["id"])
|
||||||
@@ -625,6 +628,10 @@ func TestTapNoRedact(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries := requestResult.([]interface{})
|
entries := requestResult.([]interface{})
|
||||||
|
if len(entries) == 0 {
|
||||||
|
return fmt.Errorf("unexpected entries result - Expected more than 0 entries")
|
||||||
|
}
|
||||||
|
|
||||||
firstEntry := entries[0].(map[string]interface{})
|
firstEntry := entries[0].(map[string]interface{})
|
||||||
|
|
||||||
entryUrl := fmt.Sprintf("%v/api/entries/%v", apiServerUrl, firstEntry["id"])
|
entryUrl := fmt.Sprintf("%v/api/entries/%v", apiServerUrl, firstEntry["id"])
|
||||||
@@ -727,6 +734,10 @@ func TestTapRegexMasking(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries := requestResult.([]interface{})
|
entries := requestResult.([]interface{})
|
||||||
|
if len(entries) == 0 {
|
||||||
|
return fmt.Errorf("unexpected entries result - Expected more than 0 entries")
|
||||||
|
}
|
||||||
|
|
||||||
firstEntry := entries[0].(map[string]interface{})
|
firstEntry := entries[0].(map[string]interface{})
|
||||||
|
|
||||||
entryUrl := fmt.Sprintf("%v/api/entries/%v", apiServerUrl, firstEntry["id"])
|
entryUrl := fmt.Sprintf("%v/api/entries/%v", apiServerUrl, firstEntry["id"])
|
||||||
|
@@ -37,11 +37,14 @@ func InitConfig(cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
configFilePath := cmd.Flags().Lookup(ConfigFilePathCommandName).Value.String()
|
configFilePathFlag := cmd.Flags().Lookup(ConfigFilePathCommandName)
|
||||||
|
configFilePath := configFilePathFlag.Value.String()
|
||||||
if err := mergeConfigFile(configFilePath); err != nil {
|
if err := mergeConfigFile(configFilePath); err != nil {
|
||||||
return fmt.Errorf("invalid config, %w\n"+
|
_, isPathError := err.(*os.PathError)
|
||||||
"you can regenerate the file by removing it (%v) and using `mizu config -r`", err, configFilePath)
|
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)
|
cmd.Flags().Visit(initFlag)
|
||||||
@@ -67,7 +70,7 @@ func GetConfigWithDefaults() (string, error) {
|
|||||||
func mergeConfigFile(configFilePath string) error {
|
func mergeConfigFile(configFilePath string) error {
|
||||||
reader, openErr := os.Open(configFilePath)
|
reader, openErr := os.Open(configFilePath)
|
||||||
if openErr != nil {
|
if openErr != nil {
|
||||||
return nil
|
return openErr
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, readErr := ioutil.ReadAll(reader)
|
buf, readErr := ioutil.ReadAll(reader)
|
||||||
|
Reference in New Issue
Block a user