From 0f183acb0bdddb5188e66c305eef736368ff647d Mon Sep 17 00:00:00 2001 From: Javad Date: Wed, 18 Jan 2023 10:06:13 +0330 Subject: [PATCH] os: update test use cache dir error UserCacheDir skipped and empty string cache dir got fatal. for test write permission in cache dir add mkdir temp. Fixes #57638 #57630 --- src/os/os_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/os/os_test.go b/src/os/os_test.go index a7b0a8792ea..f8c4af066e7 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -2550,12 +2550,19 @@ func TestDoubleCloseError(t *testing.T) { func TestUserCacheDir(t *testing.T) { cacheDir, err := UserCacheDir() - if len(cacheDir) == 0 && err == nil { - t.Fatal("UserCacheDir return empty string without error") + if err != nil { + t.Skipf("skipping: %v", err) + } + if cacheDir == "" { + t.Fatalf("UserCacheDir returned %q; want non-empty path or error", cacheDir) } - if err != nil && IsNotExist(err) { - t.Skipf("UserCacheDir failed: %v", err) + d, err := os.MkdirTemp(cacheDir, "TestUserCacheDir") + if err != nil { + t.Fatalf("could not write to UserCacheDir %q: %v", cacheDir, err) + } + if err := os.Remove(d); err != nil { + t.Error(err) } }