Skip to content

Commit

Permalink
Add missing unit tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Nephin <[email protected]>
  • Loading branch information
dnephin committed Jun 29, 2017
1 parent d26df21 commit 0ac9ce1
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 189 deletions.
30 changes: 12 additions & 18 deletions cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,48 +68,42 @@ func Load(configDir string) (*configfile.ConfigFile, error) {
configDir = Dir()
}

configFile := configfile.ConfigFile{
AuthConfigs: make(map[string]types.AuthConfig),
Filename: filepath.Join(configDir, ConfigFileName),
}
filename := filepath.Join(configDir, ConfigFileName)
configFile := configfile.NewConfigFile(filename)

// Try happy path first - latest config file
if _, err := os.Stat(configFile.Filename); err == nil {
file, err := os.Open(configFile.Filename)
if _, err := os.Stat(filename); err == nil {
file, err := os.Open(filename)
if err != nil {
return &configFile, errors.Errorf("%s - %v", configFile.Filename, err)
return configFile, errors.Errorf("%s - %v", filename, err)
}
defer file.Close()
err = configFile.LoadFromReader(file)
if err != nil {
err = errors.Errorf("%s - %v", configFile.Filename, err)
err = errors.Errorf("%s - %v", filename, err)
}
return &configFile, err
return configFile, err
} else if !os.IsNotExist(err) {
// if file is there but we can't stat it for any reason other
// than it doesn't exist then stop
return &configFile, errors.Errorf("%s - %v", configFile.Filename, err)
return configFile, errors.Errorf("%s - %v", filename, err)
}

// Can't find latest config file so check for the old one
confFile := filepath.Join(homedir.Get(), oldConfigfile)
if _, err := os.Stat(confFile); err != nil {
return &configFile, nil //missing file is not an error
return configFile, nil //missing file is not an error
}
file, err := os.Open(confFile)
if err != nil {
return &configFile, errors.Errorf("%s - %v", confFile, err)
return configFile, errors.Errorf("%s - %v", confFile, err)
}
defer file.Close()
err = configFile.LegacyLoadFromReader(file)
if err != nil {
return &configFile, errors.Errorf("%s - %v", confFile, err)
}

if configFile.HTTPHeaders == nil {
configFile.HTTPHeaders = map[string]string{}
return configFile, errors.Errorf("%s - %v", confFile, err)
}
return &configFile, nil
return configFile, nil
}

// LoadDefaultConfigFile attempts to load the default config file and returns
Expand Down
Loading

0 comments on commit 0ac9ce1

Please sign in to comment.