mirror of
https://github.com/golang/go
synced 2024-11-26 17:07:09 -07:00
path/filepath: add test cases for walking a symlink-to-symlink-to-dir
The "double link with slash" test is skipped on darwin due to an apparent kernel / libc bug. If the bug is present on other platforms too, I'd like to know about it. For #59586. Change-Id: I4bdd6a80a3ed7b0960ea6da30f91a655f317d512 Reviewed-on: https://go-review.googlesource.com/c/go/+/484395 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
b5a7f2eef7
commit
74c296b69f
@ -13,6 +13,7 @@ import (
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"syscall"
|
||||
@ -842,6 +843,16 @@ func TestWalkSymlinkRoot(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
abslink := filepath.Join(td, "abslink")
|
||||
if err := os.Symlink(dir, abslink); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
linklink := filepath.Join(td, "linklink")
|
||||
if err := os.Symlink("link", linklink); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Per https://pubs.opengroup.org/onlinepubs/9699919799.2013edition/basedefs/V1_chap04.html#tag_04_12:
|
||||
// “A pathname that contains at least one non- <slash> character and that ends
|
||||
// with one or more trailing <slash> characters shall not be resolved
|
||||
@ -854,9 +865,10 @@ func TestWalkSymlinkRoot(t *testing.T) {
|
||||
// but if it does end in a slash, Walk should walk the directory to which the symlink
|
||||
// refers (since it must be fully resolved before walking).
|
||||
for _, tt := range []struct {
|
||||
desc string
|
||||
root string
|
||||
want []string
|
||||
desc string
|
||||
root string
|
||||
want []string
|
||||
buggyGOOS []string
|
||||
}{
|
||||
{
|
||||
desc: "no slash",
|
||||
@ -868,6 +880,27 @@ func TestWalkSymlinkRoot(t *testing.T) {
|
||||
root: link + string(filepath.Separator),
|
||||
want: []string{link, filepath.Join(link, "foo")},
|
||||
},
|
||||
{
|
||||
desc: "abs no slash",
|
||||
root: abslink,
|
||||
want: []string{abslink},
|
||||
},
|
||||
{
|
||||
desc: "abs with slash",
|
||||
root: abslink + string(filepath.Separator),
|
||||
want: []string{abslink, filepath.Join(abslink, "foo")},
|
||||
},
|
||||
{
|
||||
desc: "double link no slash",
|
||||
root: linklink,
|
||||
want: []string{linklink},
|
||||
},
|
||||
{
|
||||
desc: "double link with slash",
|
||||
root: linklink + string(filepath.Separator),
|
||||
want: []string{linklink, filepath.Join(linklink, "foo")},
|
||||
buggyGOOS: []string{"darwin"}, // https://go.dev/issue/59586
|
||||
},
|
||||
} {
|
||||
tt := tt
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
@ -885,7 +918,12 @@ func TestWalkSymlinkRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(walked, tt.want) {
|
||||
t.Errorf("Walk(%#q) visited %#q; want %#q", tt.root, walked, tt.want)
|
||||
t.Logf("Walk(%#q) visited %#q; want %#q", tt.root, walked, tt.want)
|
||||
if slices.Contains(tt.buggyGOOS, runtime.GOOS) {
|
||||
t.Logf("(ignoring known bug on %v)", runtime.GOOS)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user