From 3bcc66c5f4de390471ffd81d6277b9f926d1358d Mon Sep 17 00:00:00 2001 From: Luke Kingland Date: Sat, 22 Oct 2022 01:12:48 +0900 Subject: [PATCH] fix: config dir default empty --- config/config.go | 10 +++------- docker/creds/credentials_test.go | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/config/config.go b/config/config.go index 5dab55693e..249d92d58f 100644 --- a/config/config.go +++ b/config/config.go @@ -70,17 +70,13 @@ func (c Config) Write(path string) (err error) { // Dir is derived in the following order, from lowest // to highest precedence. -// 1. The static default is DefaultConfigPath (./.config/func) +// 1. The default path is the zero value, indicating "no config path available", +// and users of this package should act accordingly. // 2. ~/.config/func if it exists (can be expanded: user has a home dir) // 3. The value of $XDG_CONFIG_PATH/func if the environment variable exists. // The path is created if it does not already exist. func Dir() (path string) { - // default path is a relative path used in the unlikely event that - // the user has no home directory (no ~), there is no - // XDG_CONFIG_HOME set - path = filepath.Join(".config", "func") - - // ~/.config/func is the default if ~ can be expanded + // Use home if available if home, err := os.UserHomeDir(); err == nil { path = filepath.Join(home, ".config", "func") } diff --git a/docker/creds/credentials_test.go b/docker/creds/credentials_test.go index 08eb72708f..114c79ae59 100644 --- a/docker/creds/credentials_test.go +++ b/docker/creds/credentials_test.go @@ -432,6 +432,7 @@ func TestNewCredentialsProvider(t *testing.T) { } func TestNewCredentialsProviderEmptyCreds(t *testing.T) { + withCleanHome(t) credentialsProvider := creds.NewCredentialsProvider(testConfigPath(t), creds.WithVerifyCredentials(func(ctx context.Context, image string, credentials docker.Credentials) error { if image == "localhost:5555/someorg/someimage:sometag" && credentials == (docker.Credentials{}) { return nil