Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1401)

Side by Side Diff: src/pkg/os/os_unix_test.go

Issue 5416060: code review 5416060: io: new FileInfo, FileMode types + update tree (Closed)
Patch Set: diff -r d917a203b389 https://go.googlecode.com/hg/ Created 13 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/os/os_test.go ('k') | src/pkg/os/path.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // +build darwin freebsd linux openbsd
6
7 package os_test
8
9 import (
10 . "os"
11 "syscall"
12 "testing"
13 )
14
15 func checkUidGid(t *testing.T, path string, uid, gid int) {
16 dir, err := Stat(path)
17 if err != nil {
18 t.Fatalf("Stat %q (looking for uid/gid %d/%d): %s", path, uid, g id, err)
19 }
20 sys := dir.(*FileStat).Sys.(*syscall.Stat_t)
21 if int(sys.Uid) != uid {
22 t.Errorf("Stat %q: uid %d want %d", path, sys.Uid, uid)
23 }
24 if int(sys.Gid) != gid {
25 t.Errorf("Stat %q: gid %d want %d", path, sys.Gid, gid)
26 }
27 }
28
29 func TestChown(t *testing.T) {
30 // Chown is not supported under windows or Plan 9.
31 // Plan9 provides a native ChownPlan9 version instead.
32 if syscall.OS == "windows" || syscall.OS == "plan9" {
33 return
34 }
35 // Use TempDir() to make sure we're on a local file system,
36 // so that the group ids returned by Getgroups will be allowed
37 // on the file. On NFS, the Getgroups groups are
38 // basically useless.
39 f := newFile("TestChown", t)
40 defer Remove(f.Name())
41 defer f.Close()
42 dir, err := f.Stat()
43 if err != nil {
44 t.Fatalf("stat %s: %s", f.Name(), err)
45 }
46
47 // Can't change uid unless root, but can try
48 // changing the group id. First try our current group.
49 gid := Getgid()
50 t.Log("gid:", gid)
51 if err = Chown(f.Name(), -1, gid); err != nil {
52 t.Fatalf("chown %s -1 %d: %s", f.Name(), gid, err)
53 }
54 sys := dir.(*FileStat).Sys.(*syscall.Stat_t)
55 checkUidGid(t, f.Name(), int(sys.Uid), gid)
56
57 // Then try all the auxiliary groups.
58 groups, err := Getgroups()
59 if err != nil {
60 t.Fatalf("getgroups: %s", err)
61 }
62 t.Log("groups: ", groups)
63 for _, g := range groups {
64 if err = Chown(f.Name(), -1, g); err != nil {
65 t.Fatalf("chown %s -1 %d: %s", f.Name(), g, err)
66 }
67 checkUidGid(t, f.Name(), int(sys.Uid), g)
68
69 // change back to gid to test fd.Chown
70 if err = f.Chown(-1, gid); err != nil {
71 t.Fatalf("fchown %s -1 %d: %s", f.Name(), gid, err)
72 }
73 checkUidGid(t, f.Name(), int(sys.Uid), gid)
74 }
75 }
OLDNEW
« no previous file with comments | « src/pkg/os/os_test.go ('k') | src/pkg/os/path.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b