diff options
| author | Alex Brainman <alex.brainman@gmail.com> | 2015-09-09 10:54:25 +1000 |
|---|---|---|
| committer | Alex Brainman <alex.brainman@gmail.com> | 2015-10-22 04:35:50 +0000 |
| commit | 72193c98248d26c92ced56e0855eac8722269aad (patch) | |
| tree | fddbf4aaedc5ff2bd5391da8e189095ff93dd230 /src/path/filepath/path_windows_test.go | |
| parent | 5a68eb9f25a2a6290800278df972e04a4085cee3 (diff) | |
| download | go-72193c98248d26c92ced56e0855eac8722269aad.tar.xz | |
path/filepath: test EvalSymlinks returns canonical path on windows
When you create C:\A.TXT file on windows, you can open it as c:\a.txt.
EvalSymlinks("c:\a.txt") returns C:\A.TXT. This is all EvalSymlinks
did in the past, but recently symlinks functionality been implemented on
some Windows version (where symlinks are supported). So now EvalSymlinks
handles both: searching for file canonical name and resolving symlinks.
Unfortunately TestEvalSymlinks has not been adjusted properly. The test
tests either canonical paths or symlinks, but not both. This CL separates
canonical paths tests into new TestEvalSymlinksCanonicalNames, so all
functionality is covered. Tests are simplified somewhat too.
Also remove EvalSymlinksAbsWindowsTests - it seems not used anywhere.
Change-Id: Id12e9f1441c1e30f15c523b250469978e4511a84
Reviewed-on: https://go-review.googlesource.com/14412
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/path/filepath/path_windows_test.go')
| -rw-r--r-- | src/path/filepath/path_windows_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/path/filepath/path_windows_test.go b/src/path/filepath/path_windows_test.go index 100cf30a45..255c894852 100644 --- a/src/path/filepath/path_windows_test.go +++ b/src/path/filepath/path_windows_test.go @@ -10,6 +10,7 @@ import ( "os/exec" "path/filepath" "reflect" + "strings" "syscall" "testing" ) @@ -111,3 +112,65 @@ func testWinSplitListTestIsValid(t *testing.T, ti int, tt SplitListTest, } } } + +// TestEvalSymlinksCanonicalNames verify that EvalSymlinks +// returns "canonical" path names on windows. +func TestEvalSymlinksCanonicalNames(t *testing.T) { + tmp, err := ioutil.TempDir("", "evalsymlinkcanonical") + if err != nil { + t.Fatal("creating temp dir:", err) + } + defer os.RemoveAll(tmp) + + // ioutil.TempDir might return "non-canonical" name. + cTmpName, err := filepath.EvalSymlinks(tmp) + if err != nil { + t.Errorf("EvalSymlinks(%q) error: %v", tmp, err) + } + + dirs := []string{ + "test", + "test/dir", + "testing_long_dir", + "TEST2", + } + + for _, d := range dirs { + dir := filepath.Join(cTmpName, d) + err := os.Mkdir(dir, 0755) + if err != nil { + t.Fatal(err) + } + cname, err := filepath.EvalSymlinks(dir) + if err != nil { + t.Errorf("EvalSymlinks(%q) error: %v", dir, err) + continue + } + if dir != cname { + t.Errorf("EvalSymlinks(%q) returns %q, but should return %q", dir, cname, dir) + continue + } + // test non-canonical names + test := strings.ToUpper(dir) + p, err := filepath.EvalSymlinks(test) + if err != nil { + t.Errorf("EvalSymlinks(%q) error: %v", test, err) + continue + } + if p != cname { + t.Errorf("EvalSymlinks(%q) returns %q, but should return %q", test, p, cname) + continue + } + // another test + test = strings.ToLower(dir) + p, err = filepath.EvalSymlinks(test) + if err != nil { + t.Errorf("EvalSymlinks(%q) error: %v", test, err) + continue + } + if p != cname { + t.Errorf("EvalSymlinks(%q) returns %q, but should return %q", test, p, cname) + continue + } + } +} |
