From a27bbb7f746a44eafae924a0333fa371ca0626c3 Mon Sep 17 00:00:00 2001 From: Rahul Chaudhry Date: Thu, 3 Dec 2015 13:19:48 -0800 Subject: [PATCH] os: make TestLchown actually test Lchown. TestLchown was creating a hard-link instead of a symlink. It would have passed if you replaced all Lchown() calls in it with Chown(). Change-Id: I3a108948ec25fcbac8ea890a6eaf5bac094f0800 Reviewed-on: https://go-review.googlesource.com/17397 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/os/os_unix_test.go | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/os/os_unix_test.go b/src/os/os_unix_test.go index 2adc3b50e7..d02e07b478 100644 --- a/src/os/os_unix_test.go +++ b/src/os/os_unix_test.go @@ -18,16 +18,16 @@ func init() { } func checkUidGid(t *testing.T, path string, uid, gid int) { - dir, err := Stat(path) + dir, err := Lstat(path) if err != nil { - t.Fatalf("Stat %q (looking for uid/gid %d/%d): %s", path, uid, gid, err) + t.Fatalf("Lstat %q (looking for uid/gid %d/%d): %s", path, uid, gid, err) } sys := dir.Sys().(*syscall.Stat_t) if int(sys.Uid) != uid { - t.Errorf("Stat %q: uid %d want %d", path, sys.Uid, uid) + t.Errorf("Lstat %q: uid %d want %d", path, sys.Uid, uid) } if int(sys.Gid) != gid { - t.Errorf("Stat %q: gid %d want %d", path, sys.Gid, gid) + t.Errorf("Lstat %q: gid %d want %d", path, sys.Gid, gid) } } @@ -144,17 +144,11 @@ func TestLchown(t *testing.T) { } linkname := f.Name() + "2" - if err := Link(f.Name(), linkname); err != nil { + if err := Symlink(f.Name(), linkname); err != nil { t.Fatalf("link %s -> %s: %v", f.Name(), linkname, err) } defer Remove(linkname) - f2, err := Open(linkname) - if err != nil { - t.Fatalf("open %s: %v", linkname, err) - } - defer f2.Close() - // Can't change uid unless root, but can try // changing the group id. First try our current group. gid := Getgid() @@ -177,10 +171,7 @@ func TestLchown(t *testing.T) { } checkUidGid(t, linkname, int(sys.Uid), g) - // change back to gid to test fd.Chown - if err = f2.Chown(-1, gid); err != nil { - t.Fatalf("fchown %s -1 %d: %s", linkname, gid, err) - } - checkUidGid(t, linkname, int(sys.Uid), gid) + // Check that link target's gid is unchanged. + checkUidGid(t, f.Name(), int(sys.Uid), int(sys.Gid)) } }