aboutsummaryrefslogtreecommitdiff
path: root/src/path/filepath/path_test.go
diff options
context:
space:
mode:
authorAlex Brainman <alex.brainman@gmail.com>2017-02-13 14:52:19 +1100
committerAlex Brainman <alex.brainman@gmail.com>2017-04-05 02:31:45 +0000
commitacc1f47299620bb558a21e4144b7535fd904f377 (patch)
tree4e7b62abadd35e397d468694d7137a1eb631a557 /src/path/filepath/path_test.go
parent4c1622082e493dea24a936930be8b324aae54505 (diff)
downloadgo-acc1f47299620bb558a21e4144b7535fd904f377.tar.xz
path/filepath: add test to walk symlink
For #17540. Change-Id: Ie01f39797526934fa553f4279cbde6c7cbf14154 Reviewed-on: https://go-review.googlesource.com/36854 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/path/filepath/path_test.go')
-rw-r--r--src/path/filepath/path_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go
index 70baa6112f..0c21d213f7 100644
--- a/src/path/filepath/path_test.go
+++ b/src/path/filepath/path_test.go
@@ -6,12 +6,14 @@ package filepath_test
import (
"errors"
+ "fmt"
"internal/testenv"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"runtime"
+ "sort"
"strings"
"testing"
)
@@ -1327,3 +1329,56 @@ func TestBug3486(t *testing.T) { // https://golang.org/issue/3486
t.Fatalf("%q not seen", ken)
}
}
+
+func testWalkSymlink(t *testing.T, mklink func(target, link string) error) {
+ tmpdir, err := ioutil.TempDir("", "testWalkSymlink")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.RemoveAll(tmpdir)
+
+ wd, err := os.Getwd()
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.Chdir(wd)
+
+ err = os.Chdir(tmpdir)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = mklink(tmpdir, "link")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ var visited []string
+ err = filepath.Walk(tmpdir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ t.Fatal(err)
+ }
+ rel, err := filepath.Rel(tmpdir, path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ visited = append(visited, rel)
+ return nil
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ sort.Strings(visited)
+ want := []string{".", "link"}
+ if fmt.Sprintf("%q", visited) != fmt.Sprintf("%q", want) {
+ t.Errorf("unexpected paths visited %q, want %q", visited, want)
+ }
+}
+
+func TestWalkSymlink(t *testing.T) {
+ testenv.MustHaveSymlink(t)
+ if runtime.GOOS == "windows" {
+ t.Skip("skipping broken test: see issue 17540")
+ }
+ testWalkSymlink(t, os.Symlink)
+}