Skip to content

Commit

Permalink
os: use testenv.MustHaveSymlink to simplify symlink tests
Browse files Browse the repository at this point in the history
Cleanup test code for symbolic links.

Change-Id: I7a116e4d5c0e955578eca53c1af559e9092f60cd
Reviewed-on: https://go-review.googlesource.com/27572
Reviewed-by: Brad Fitzpatrick <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
hirochachacha authored and bradfitz committed Aug 23, 2016
1 parent 25d1895 commit e893c72
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 42 deletions.
22 changes: 4 additions & 18 deletions src/os/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"time"
)

var supportsSymlinks = true

var dot = []string{
"dir_unix.go",
"env.go",
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 0 additions & 16 deletions src/os/os_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions src/os/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package os_test

import (
"internal/testenv"
"io/ioutil"
. "os"
"path/filepath"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e893c72

Please sign in to comment.