aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-06-30 08:22:27 -0700
committerIan Lance Taylor <iant@golang.org>2016-06-30 15:49:01 +0000
commit6c136493012b8a1f96f3edc9fa56aed70d34291a (patch)
tree8c2478dff87506cca395d6d5bca30c7b1330e25c
parente0c8af090ea1ccc32d06ae75b653446d2a9d6f87 (diff)
downloadgo-6c136493012b8a1f96f3edc9fa56aed70d34291a.tar.gz
go-6c136493012b8a1f96f3edc9fa56aed70d34291a.zip
syscall: accept more variants of id output when testing as root
This should fix the report at #16224, and also fixes running the test as root on my Ubuntu Trusty system. Fixes #16224. Change-Id: I4e3b5527aa63366afb33a7e30efab088d34fb302 Reviewed-on: https://go-review.googlesource.com/24670 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/syscall/exec_linux_test.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/syscall/exec_linux_test.go b/src/syscall/exec_linux_test.go
index fbbce6de5a..cb24c590f9 100644
--- a/src/syscall/exec_linux_test.go
+++ b/src/syscall/exec_linux_test.go
@@ -200,8 +200,10 @@ func TestGroupCleanup(t *testing.T) {
}
strOut := strings.TrimSpace(string(out))
expected := "uid=0(root) gid=0(root) groups=0(root)"
- if strOut != expected {
- t.Fatalf("id command output: %s, expected: %s", strOut, expected)
+ // Just check prefix because some distros reportedly output a
+ // context parameter; see https://golang.org/issue/16224.
+ if !strings.HasPrefix(strOut, expected) {
+ t.Errorf("id command output: %q, expected prefix: %q", strOut, expected)
}
}
@@ -230,10 +232,17 @@ func TestGroupCleanupUserNamespace(t *testing.T) {
t.Fatalf("Cmd failed with err %v, output: %s", err, out)
}
strOut := strings.TrimSpace(string(out))
- // there are two possible outs
- expected1 := "uid=0(root) gid=0(root) groups=0(root)"
- expected2 := "uid=0(root) gid=0(root) groups=0(root),65534(nobody)"
- if strOut != expected1 && strOut != expected2 {
- t.Fatalf("id command output: %s, expected: %s or %s", strOut, expected1, expected2)
+
+ // Strings we've seen in the wild.
+ expected := []string{
+ "uid=0(root) gid=0(root) groups=0(root)",
+ "uid=0(root) gid=0(root) groups=0(root),65534(nobody)",
+ "uid=0(root) gid=0(root) groups=0(root),65534(nogroup)",
+ }
+ for _, e := range expected {
+ if strOut == e {
+ return
+ }
}
+ t.Errorf("id command output: %q, expected one of %q", strOut, expected)
}