diff --git a/.gitignore b/.gitignore index 62019b2741..edff43a717 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,3 @@ __pycache__ # TODO: Update this test to be from a temp directory with a hard-coded impl: # https://github.com/knative/func/issues/3196 /pkg/builders/testdata/go-fn-with-private-deps/.s2i - -# TODO: update the test which creates this to run in a temp directory: -# https://github.com/knative/func/issues/3158 -/pkg/creds/auth.json diff --git a/pkg/creds/credentials_test.go b/pkg/creds/credentials_test.go index 2e8a88099a..68e5b549d7 100644 --- a/pkg/creds/credentials_test.go +++ b/pkg/creds/credentials_test.go @@ -1024,12 +1024,13 @@ func testHomeEnvName() string { func testConfigPath(t *testing.T) string { t.Helper() home := os.Getenv(testHomeEnvName()) - var configPath string - if home != "" { // if HOME is not set, don't create config dir - configPath = filepath.Join(home, ".config", "func") - if err := os.MkdirAll(configPath, os.ModePerm); err != nil { - t.Fatal(err) - } + // using a temp directory to avoid polluting the source tree with auth.json + if home == "" { + home = t.TempDir() + } + configPath := filepath.Join(home, ".config", "func") + if err := os.MkdirAll(configPath, os.ModePerm); err != nil { + t.Fatal(err) } return configPath } @@ -1039,6 +1040,9 @@ func testConfigPath(t *testing.T) string { func testConfigPathError(t *testing.T) (string, error) { t.Helper() home := os.Getenv(testHomeEnvName()) + if home == "" { + home = t.TempDir() + } configPath := filepath.Join(home, ".config", "func") return configPath, os.MkdirAll(configPath, os.ModePerm) }