]> Cypherpunks repositories - gostls13.git/commitdiff
os: use testenv.MustHaveSymlink to simplify symlink tests
authorHiroshi Ioka <hirochachacha@gmail.com>
Tue, 23 Aug 2016 13:21:49 +0000 (22:21 +0900)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 23 Aug 2016 14:46:46 +0000 (14:46 +0000)
Cleanup test code for symbolic links.

Change-Id: I7a116e4d5c0e955578eca53c1af559e9092f60cd
Reviewed-on: https://go-review.googlesource.com/27572
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/os/os_test.go
src/os/os_windows_test.go
src/os/path_test.go

index baa2f07fd2b0f322bb4cc025af6fd8206b85eabb..0c4042a4bf3b8ff04c462ee7629388823c0cab9c 100644 (file)
@@ -25,8 +25,6 @@ import (
        "time"
 )
 
-var supportsSymlinks = true
-
 var dot = []string{
        "dir_unix.go",
        "env.go",
@@ -652,14 +650,8 @@ func chtmpdir(t *testing.T) func() {
 }
 
 func TestSymlink(t *testing.T) {
-       switch runtime.GOOS {
-       case "android", "nacl", "plan9":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "windows":
-               if !supportsSymlinks {
-                       t.Skipf("skipping on %s", runtime.GOOS)
-               }
-       }
+       testenv.MustHaveSymlink(t)
+
        defer chtmpdir(t)()
        from, to := "symlinktestfrom", "symlinktestto"
        Remove(from) // Just in case.
@@ -719,14 +711,8 @@ func TestSymlink(t *testing.T) {
 }
 
 func TestLongSymlink(t *testing.T) {
-       switch runtime.GOOS {
-       case "android", "plan9", "nacl":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "windows":
-               if !supportsSymlinks {
-                       t.Skipf("skipping on %s", runtime.GOOS)
-               }
-       }
+       testenv.MustHaveSymlink(t)
+
        defer chtmpdir(t)()
        s := "0123456789abcdef"
        // Long, but not too long: a common limit is 255.
index 05d7a8f34e9a9f4f721087ff57774d270ea461da..59f89fcae32052b6e17cde8101c5b0698f1cbdd3 100644 (file)
@@ -18,22 +18,6 @@ import (
 var supportJunctionLinks = true
 
 func init() {
-       tmpdir, err := ioutil.TempDir("", "symtest")
-       if err != nil {
-               panic("failed to create temp directory: " + err.Error())
-       }
-       defer os.RemoveAll(tmpdir)
-
-       err = os.Symlink("target", filepath.Join(tmpdir, "symlink"))
-       if err != nil {
-               err = err.(*os.LinkError).Err
-               switch err {
-               case syscall.EWINDOWS, syscall.ERROR_PRIVILEGE_NOT_HELD:
-                       supportsSymlinks = false
-               }
-       }
-       defer os.Remove("target")
-
        b, _ := osexec.Command("cmd", "/c", "mklink", "/?").Output()
        if !strings.Contains(string(b), " /J ") {
                supportJunctionLinks = false
index 51dc25bb23072f6eaa7022ab389086120456b2e5..6f5bfa54f8f77c1b080a5ad03c1abf84e5459c80 100644 (file)
@@ -5,6 +5,7 @@
 package os_test
 
 import (
+       "internal/testenv"
        "io/ioutil"
        . "os"
        "path/filepath"
@@ -169,14 +170,7 @@ func TestRemoveAll(t *testing.T) {
 }
 
 func TestMkdirAllWithSymlink(t *testing.T) {
-       switch runtime.GOOS {
-       case "android", "nacl", "plan9":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "windows":
-               if !supportsSymlinks {
-                       t.Skipf("skipping on %s", runtime.GOOS)
-               }
-       }
+       testenv.MustHaveSymlink(t)
 
        tmpDir, err := ioutil.TempDir("", "TestMkdirAllWithSymlink-")
        if err != nil {