]> Cypherpunks repositories - gostls13.git/commitdiff
os: make TestLchown actually test Lchown.
authorRahul Chaudhry <rahulchaudhry@chromium.org>
Thu, 3 Dec 2015 21:19:48 +0000 (13:19 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 14 Dec 2015 22:42:55 +0000 (22:42 +0000)
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 <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/os/os_unix_test.go

index 2adc3b50e727cdb5952d5c39c3cb009cb971390f..d02e07b478a5ccfcba237484c686c18ab59a92f0 100644 (file)
@@ -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))
        }
 }