mirror of
https://github.com/golang/go
synced 2024-11-25 09:27:57 -07:00
os: add tests for UserCacheDir and UserConfigDir
Adds basic test scenarios for UserCacheDir and UserConfigDir. Fixes #57638 Change-Id: Ieb86e95faff44287bfa13daa0cb26e7b5401373b Reviewed-on: https://go-review.googlesource.com/c/go/+/520262 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Bypass: Bryan Mills <bcmills@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
a7c3de7052
commit
e4a8fb0fa0
@ -204,6 +204,7 @@ func runMain() (int, error) {
|
||||
`; export GOPROXY=` + os.Getenv("GOPROXY") +
|
||||
`; export GOCACHE="` + deviceRoot + `/gocache"` +
|
||||
`; export PATH="` + deviceGoroot + `/bin":$PATH` +
|
||||
`; export HOME="` + deviceRoot + `/home"` +
|
||||
`; cd "` + deviceCwd + `"` +
|
||||
"; '" + deviceBin + "' " + strings.Join(os.Args[2:], " ")
|
||||
code, err := adbRun(cmd)
|
||||
|
@ -2823,6 +2823,53 @@ func TestDoubleCloseError(t *testing.T) {
|
||||
t.Run("dir", testDoubleCloseError(sfdir))
|
||||
}
|
||||
|
||||
func TestUserCacheDir(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dir, err := UserCacheDir()
|
||||
if err != nil {
|
||||
t.Skipf("skipping: %v", err)
|
||||
}
|
||||
if dir == "" {
|
||||
t.Fatalf("UserCacheDir returned %q; want non-empty path or error", dir)
|
||||
}
|
||||
|
||||
if err := MkdirAll(dir, 0777); err != nil {
|
||||
t.Fatalf("could not create UserCacheDir: %v", err)
|
||||
}
|
||||
d, err := MkdirTemp(dir, "TestUserCacheDir")
|
||||
if err != nil {
|
||||
t.Fatalf("could not create a directory in UserCacheDir: %v", err)
|
||||
}
|
||||
if err := Remove(d); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserConfigDir(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dir, err := UserConfigDir()
|
||||
if err != nil {
|
||||
t.Skipf("skipping: %v", err)
|
||||
}
|
||||
if dir == "" {
|
||||
t.Fatalf("UserConfigDir returned %q; want non-empty path or error", dir)
|
||||
}
|
||||
|
||||
if err := MkdirAll(dir, 0777); err != nil {
|
||||
t.Fatalf("could not create UserConfigDir: %v", err)
|
||||
}
|
||||
|
||||
d, err := MkdirTemp(dir, "TestUserConfigDir")
|
||||
if err != nil {
|
||||
t.Fatalf("could not create a directory in UserConfigDir: %v", err)
|
||||
}
|
||||
if err := Remove(d); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserHomeDir(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user