mirror of
https://github.com/golang/go
synced 2024-11-26 05:37:57 -07:00
os: simplify TestRemoveAllLongPath
Simplify the test logic by using t.TempDir, t.Chdir, and Chdir to startPath parent. Change-Id: Ibe71a8c26b8e54c22eb93510037605b69c67bc7a Reviewed-on: https://go-review.googlesource.com/c/go/+/606896 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
f432b5f756
commit
5164f61697
@ -159,40 +159,25 @@ func TestRemoveAllLongPath(t *testing.T) {
|
|||||||
t.Skip("skipping for not implemented platforms")
|
t.Skip("skipping for not implemented platforms")
|
||||||
}
|
}
|
||||||
|
|
||||||
prevDir, err := Getwd()
|
startPath := t.TempDir()
|
||||||
if err != nil {
|
t.Chdir(startPath)
|
||||||
t.Fatalf("Could not get wd: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
startPath, err := MkdirTemp("", "TestRemoveAllLongPath-")
|
// Removing paths with over 4096 chars commonly fails.
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Could not create TempDir: %s", err)
|
|
||||||
}
|
|
||||||
defer RemoveAll(startPath)
|
|
||||||
|
|
||||||
err = Chdir(startPath)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Could not chdir %s: %s", startPath, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removing paths with over 4096 chars commonly fails
|
|
||||||
for i := 0; i < 41; i++ {
|
|
||||||
name := strings.Repeat("a", 100)
|
name := strings.Repeat("a", 100)
|
||||||
|
for i := 0; i < 41; i++ {
|
||||||
err = Mkdir(name, 0755)
|
if err := Mkdir(name, 0755); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Could not mkdir %s: %s", name, err)
|
t.Fatalf("Could not mkdir %s: %s", name, err)
|
||||||
}
|
}
|
||||||
|
if err := Chdir(name); err != nil {
|
||||||
err = Chdir(name)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Could not chdir %s: %s", name, err)
|
t.Fatalf("Could not chdir %s: %s", name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = Chdir(prevDir)
|
// Chdir out of startPath before attempting to remove it,
|
||||||
|
// otherwise RemoveAll fails on aix, illumos and solaris.
|
||||||
|
err := Chdir(filepath.Join(startPath, ".."))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Could not chdir %s: %s", prevDir, err)
|
t.Fatalf("Could not chdir: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = RemoveAll(startPath)
|
err = RemoveAll(startPath)
|
||||||
|
Loading…
Reference in New Issue
Block a user