mirror of https://github.com/golang/go.git
os: use testenv.MustHaveSymlink to simplify symlink tests
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>
This commit is contained in:
parent
25d18954f6
commit
e893c72f2a
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue