mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
os, syscall: skip tests when environment doesn't permit testing
Fixes #14693 Change-Id: Id0a6a80b4c37c0b0f1c2755667b7233ed8964e40 Reviewed-on: https://go-review.googlesource.com/20342 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
2b19b6e3f1
commit
40e60e7c13
2 changed files with 11 additions and 4 deletions
|
|
@ -1275,15 +1275,19 @@ func TestOpenNoName(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(t *testing.T, cmd []string) string {
|
func runBinHostname(t *testing.T) string {
|
||||||
// Run /bin/hostname and collect output.
|
// Run /bin/hostname and collect output.
|
||||||
r, w, err := Pipe()
|
r, w, err := Pipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
p, err := StartProcess("/bin/hostname", []string{"hostname"}, &ProcAttr{Files: []*File{nil, w, Stderr}})
|
const path = "/bin/hostname"
|
||||||
|
p, err := StartProcess(path, []string{"hostname"}, &ProcAttr{Files: []*File{nil, w, Stderr}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if _, err := Stat(path); IsNotExist(err) {
|
||||||
|
t.Skipf("skipping test; test requires %s but it does not exist", path)
|
||||||
|
}
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
w.Close()
|
w.Close()
|
||||||
|
|
@ -1303,7 +1307,7 @@ func run(t *testing.T, cmd []string) string {
|
||||||
output = output[0 : n-1]
|
output = output[0 : n-1]
|
||||||
}
|
}
|
||||||
if output == "" {
|
if output == "" {
|
||||||
t.Fatalf("%v produced no output", cmd)
|
t.Fatalf("/bin/hostname produced no output")
|
||||||
}
|
}
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
@ -1345,7 +1349,7 @@ func TestHostname(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%v", err)
|
t.Fatalf("%v", err)
|
||||||
}
|
}
|
||||||
want := run(t, []string{"/bin/hostname"})
|
want := runBinHostname(t)
|
||||||
if hostname != want {
|
if hostname != want {
|
||||||
i := strings.Index(hostname, ".")
|
i := strings.Index(hostname, ".")
|
||||||
if i < 0 || hostname[0:i] != want {
|
if i < 0 || hostname[0:i] != want {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,9 @@ func whoamiCmd(t *testing.T, uid, gid int, setgroups bool) *exec.Cmd {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
t.Skip("kernel doesn't support user namespaces")
|
t.Skip("kernel doesn't support user namespaces")
|
||||||
}
|
}
|
||||||
|
if os.IsPermission(err) {
|
||||||
|
t.Skip("unable to test user namespaces due to permissions")
|
||||||
|
}
|
||||||
t.Fatalf("Failed to stat /proc/self/ns/user: %v", err)
|
t.Fatalf("Failed to stat /proc/self/ns/user: %v", err)
|
||||||
}
|
}
|
||||||
if isChrooted(t) {
|
if isChrooted(t) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue