Skip to content

Commit

Permalink
Fix CI 💥 due to testing handicap
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Oct 11, 2017
1 parent cc09165 commit cc07611
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 6 additions & 8 deletions docker/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ var DefaultUsername string
// DefaultPassword is the password we use if none is defined in config
var DefaultPassword string

// DefaultDockerJSON is the defalt path for Docker JSON config file
var DefaultDockerJSON = "~/.docker/config.json"

// Config encapsulates configuration loaded from Docker 'config.json' file
type Config struct {
Auths map[string]Auth `json:"auths"`
Expand Down Expand Up @@ -57,18 +60,13 @@ func (c *Config) GetRegistryAuth(registry string) (string, bool) {

// Load loads a Config object from Docker JSON configuration file specified
func Load(fileName string) (*Config, error) {
defaultFileNameUsed := fileName == "~/.docker/config.json"

fileName = fixPath(fileName)

f, err := os.Open(fileName)
f, err := os.Open(fixPath(fileName))
defer f.Close()
if err != nil {
if !defaultFileNameUsed {
return nil, err
} else {
if fileName == DefaultDockerJSON {
return &Config{}, nil
}
return nil, err
}

c, err := parseConfig(f)
Expand Down
10 changes: 9 additions & 1 deletion docker/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,17 @@ func TestLoadWithInvalidConfigFile(t *testing.T) {
}

func TestLoadWithAbsentConfigFile(t *testing.T) {
_, err := Load("i/exist/only/in/your/magination")
var err error

_, err = Load("i/exist/only/in/your/magination")
if err == nil {
t.Fatalf("Expected to fail while trying to load absent config file")
}

DefaultDockerJSON = "i/exist/only/in/your/magination"

_, err = Load("i/exist/only/in/your/magination")
if err != nil {
t.Fatalf("Expected NOT to fail while trying to load absent config file from a default path")
}
}

0 comments on commit cc07611

Please sign in to comment.