1
0
mirror of https://github.com/golang/go synced 2024-11-25 18:17:56 -07:00

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
This commit is contained in:
Javad 2023-01-18 10:06:13 +03:30
parent 8cb19f0e99
commit 0f183acb0b

View File

@ -2550,12 +2550,19 @@ func TestDoubleCloseError(t *testing.T) {
func TestUserCacheDir(t *testing.T) { func TestUserCacheDir(t *testing.T) {
cacheDir, err := UserCacheDir() cacheDir, err := UserCacheDir()
if len(cacheDir) == 0 && err == nil { if err != nil {
t.Fatal("UserCacheDir return empty string without error") t.Skipf("skipping: %v", err)
}
if cacheDir == "" {
t.Fatalf("UserCacheDir returned %q; want non-empty path or error", cacheDir)
} }
if err != nil && IsNotExist(err) { d, err := os.MkdirTemp(cacheDir, "TestUserCacheDir")
t.Skipf("UserCacheDir failed: %v", err) if err != nil {
t.Fatalf("could not write to UserCacheDir %q: %v", cacheDir, err)
}
if err := os.Remove(d); err != nil {
t.Error(err)
} }
} }