From 61bf0d1c4033ef2cc6905c2ca6e03046cf54d2bc Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Sun, 12 Feb 2017 18:23:34 +1100 Subject: [PATCH] path/filepath: add test for directory junction walk For #10424. Change-Id: Ie4e87503b0ed04f65d2444652bd1db647d3529f4 Reviewed-on: https://go-review.googlesource.com/36851 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/path/filepath/path_windows_test.go | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/path/filepath/path_windows_test.go b/src/path/filepath/path_windows_test.go index c9a0255efd..795b1f1bb8 100644 --- a/src/path/filepath/path_windows_test.go +++ b/src/path/filepath/path_windows_test.go @@ -433,3 +433,45 @@ func TestUNC(t *testing.T) { defer debug.SetMaxStack(debug.SetMaxStack(1e6)) filepath.Glob(`\\?\c:\*`) } + +func TestWalkDirectoryJunction(t *testing.T) { + t.Skip("skipping broken test: see issue 10424") + + output, _ := exec.Command("cmd", "/c", "mklink", "/?").Output() + if !strings.Contains(string(output), " /J ") { + t.Skip(`skipping test; mklink does not supports directory junctions`) + } + + tmpdir, err := ioutil.TempDir("", "TestWalkDirectoryJunction") + 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) + } + + output, err = exec.Command("cmd", "/c", "mklink", "/J", "link", tmpdir).CombinedOutput() + if err != nil { + t.Errorf(`"mklink link %v" command failed: %v\n%v`, tmpdir, err, string(output)) + } + + walkfunc := func(path string, info os.FileInfo, err error) error { + if err != nil { + t.Log(err) + } + return nil + } + err = filepath.Walk(tmpdir, walkfunc) + if err != nil { + t.Fatal(err) + } +}