From cc07611b7cd71c6c6cfe046b9a4b5b15b0f07bf3 Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Wed, 11 Oct 2017 12:09:38 +0200 Subject: [PATCH] Fix CI :boom: due to testing handicap --- docker/config/config.go | 14 ++++++-------- docker/config/config_test.go | 10 +++++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/docker/config/config.go b/docker/config/config.go index 162af8b..028c63c 100644 --- a/docker/config/config.go +++ b/docker/config/config.go @@ -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"` @@ -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) diff --git a/docker/config/config_test.go b/docker/config/config_test.go index fbef4c1..db8b864 100644 --- a/docker/config/config_test.go +++ b/docker/config/config_test.go @@ -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") + } }