Skip to content

Commit e893c72

Browse files
hirochachachabradfitz
authored andcommitted
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 <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 25d1895 commit e893c72

File tree

3 files changed

+6
-42
lines changed

3 files changed

+6
-42
lines changed

src/os/os_test.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
"time"
2626
)
2727

28-
var supportsSymlinks = true
29-
3028
var dot = []string{
3129
"dir_unix.go",
3230
"env.go",
@@ -652,14 +650,8 @@ func chtmpdir(t *testing.T) func() {
652650
}
653651

654652
func TestSymlink(t *testing.T) {
655-
switch runtime.GOOS {
656-
case "android", "nacl", "plan9":
657-
t.Skipf("skipping on %s", runtime.GOOS)
658-
case "windows":
659-
if !supportsSymlinks {
660-
t.Skipf("skipping on %s", runtime.GOOS)
661-
}
662-
}
653+
testenv.MustHaveSymlink(t)
654+
663655
defer chtmpdir(t)()
664656
from, to := "symlinktestfrom", "symlinktestto"
665657
Remove(from) // Just in case.
@@ -719,14 +711,8 @@ func TestSymlink(t *testing.T) {
719711
}
720712

721713
func TestLongSymlink(t *testing.T) {
722-
switch runtime.GOOS {
723-
case "android", "plan9", "nacl":
724-
t.Skipf("skipping on %s", runtime.GOOS)
725-
case "windows":
726-
if !supportsSymlinks {
727-
t.Skipf("skipping on %s", runtime.GOOS)
728-
}
729-
}
714+
testenv.MustHaveSymlink(t)
715+
730716
defer chtmpdir(t)()
731717
s := "0123456789abcdef"
732718
// Long, but not too long: a common limit is 255.

src/os/os_windows_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,6 @@ import (
1818
var supportJunctionLinks = true
1919

2020
func init() {
21-
tmpdir, err := ioutil.TempDir("", "symtest")
22-
if err != nil {
23-
panic("failed to create temp directory: " + err.Error())
24-
}
25-
defer os.RemoveAll(tmpdir)
26-
27-
err = os.Symlink("target", filepath.Join(tmpdir, "symlink"))
28-
if err != nil {
29-
err = err.(*os.LinkError).Err
30-
switch err {
31-
case syscall.EWINDOWS, syscall.ERROR_PRIVILEGE_NOT_HELD:
32-
supportsSymlinks = false
33-
}
34-
}
35-
defer os.Remove("target")
36-
3721
b, _ := osexec.Command("cmd", "/c", "mklink", "/?").Output()
3822
if !strings.Contains(string(b), " /J ") {
3923
supportJunctionLinks = false

src/os/path_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package os_test
66

77
import (
8+
"internal/testenv"
89
"io/ioutil"
910
. "os"
1011
"path/filepath"
@@ -169,14 +170,7 @@ func TestRemoveAll(t *testing.T) {
169170
}
170171

171172
func TestMkdirAllWithSymlink(t *testing.T) {
172-
switch runtime.GOOS {
173-
case "android", "nacl", "plan9":
174-
t.Skipf("skipping on %s", runtime.GOOS)
175-
case "windows":
176-
if !supportsSymlinks {
177-
t.Skipf("skipping on %s", runtime.GOOS)
178-
}
179-
}
173+
testenv.MustHaveSymlink(t)
180174

181175
tmpDir, err := ioutil.TempDir("", "TestMkdirAllWithSymlink-")
182176
if err != nil {

0 commit comments

Comments
 (0)