LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package user | 5 package user |
6 | 6 |
7 import ( | 7 import ( |
8 "os" | 8 "os" |
9 "reflect" | 9 "reflect" |
10 "runtime" | 10 "runtime" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // Test LookupId on the current user | 34 // Test LookupId on the current user |
35 uid := syscall.Getuid() | 35 uid := syscall.Getuid() |
36 u, err := LookupId(uid) | 36 u, err := LookupId(uid) |
37 if err != nil { | 37 if err != nil { |
38 t.Fatalf("LookupId: %v", err) | 38 t.Fatalf("LookupId: %v", err) |
39 } | 39 } |
40 if e, g := uid, u.Uid; e != g { | 40 if e, g := uid, u.Uid; e != g { |
41 t.Errorf("expected Uid of %d; got %d", e, g) | 41 t.Errorf("expected Uid of %d; got %d", e, g) |
42 } | 42 } |
43 fi, err := os.Stat(u.HomeDir) | 43 fi, err := os.Stat(u.HomeDir) |
44 » if err != nil || !fi.IsDirectory() { | 44 » if err != nil || !fi.IsDir() { |
45 » » t.Errorf("expected a valid HomeDir; stat(%q): err=%v, IsDirector
y=%v", u.HomeDir, err, fi.IsDirectory()) | 45 » » t.Errorf("expected a valid HomeDir; stat(%q): err=%v, IsDir=%v",
u.HomeDir, err, fi.IsDir()) |
46 } | 46 } |
47 if u.Username == "" { | 47 if u.Username == "" { |
48 t.Fatalf("didn't get a username") | 48 t.Fatalf("didn't get a username") |
49 } | 49 } |
50 | 50 |
51 // Test Lookup by username, using the username from LookupId | 51 // Test Lookup by username, using the username from LookupId |
52 un, err := Lookup(u.Username) | 52 un, err := Lookup(u.Username) |
53 if err != nil { | 53 if err != nil { |
54 t.Fatalf("Lookup: %v", err) | 54 t.Fatalf("Lookup: %v", err) |
55 } | 55 } |
56 if !reflect.DeepEqual(u, un) { | 56 if !reflect.DeepEqual(u, un) { |
57 t.Errorf("Lookup by userid vs. name didn't match\n"+ | 57 t.Errorf("Lookup by userid vs. name didn't match\n"+ |
58 "LookupId(%d): %#v\n"+ | 58 "LookupId(%d): %#v\n"+ |
59 "Lookup(%q): %#v\n", uid, u, u.Username, un) | 59 "Lookup(%q): %#v\n", uid, u, u.Username, un) |
60 } | 60 } |
61 } | 61 } |
LEFT | RIGHT |