os: simplify TestRemoveAllDot

Use t.Chdir and t.TempDir to simplify test case code.

Change-Id: If4de06d2373100ce53a5b8f6702d5f4866e3b23d
Reviewed-on: https://go-review.googlesource.com/c/go/+/606897
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Kir Kolyshkin 2024-08-19 14:28:41 -07:00 committed by Gopher Robot
parent 5164f61697
commit 4b767cf6fd
1 changed files with 2 additions and 21 deletions

View File

@ -187,30 +187,11 @@ func TestRemoveAllLongPath(t *testing.T) {
}
func TestRemoveAllDot(t *testing.T) {
prevDir, err := Getwd()
if err != nil {
t.Fatalf("Could not get wd: %s", err)
}
tempDir, err := MkdirTemp("", "TestRemoveAllDot-")
if err != nil {
t.Fatalf("Could not create TempDir: %s", err)
}
defer RemoveAll(tempDir)
t.Chdir(t.TempDir())
err = Chdir(tempDir)
if err != nil {
t.Fatalf("Could not chdir to tempdir: %s", err)
}
err = RemoveAll(".")
if err == nil {
if err := RemoveAll("."); err == nil {
t.Errorf("RemoveAll succeed to remove .")
}
err = Chdir(prevDir)
if err != nil {
t.Fatalf("Could not chdir %s: %s", prevDir, err)
}
}
func TestRemoveAllDotDot(t *testing.T) {