]> Cypherpunks repositories - gostls13.git/commitdiff
os: simplify TestRemoveAllDot
authorKir Kolyshkin <kolyshkin@gmail.com>
Mon, 19 Aug 2024 21:28:41 +0000 (14:28 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 20 Aug 2024 16:06:03 +0000 (16:06 +0000)
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>
src/os/removeall_test.go

index 454a6b5d0a3269b85e37afbf5babefdac347aa54..474db2cac83b6ef514f36b50540e51f77a42371f 100644 (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) {