~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to .pc/014-dont_fail_test_with_missing_homedir.patch/src/pkg/os/user/user_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2011 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
 
package user
6
 
 
7
 
import (
8
 
        "os"
9
 
        "runtime"
10
 
        "testing"
11
 
)
12
 
 
13
 
func skip(t *testing.T) bool {
14
 
        if !implemented {
15
 
                t.Logf("user: not implemented; skipping tests")
16
 
                return true
17
 
        }
18
 
 
19
 
        switch runtime.GOOS {
20
 
        case "linux", "freebsd", "darwin", "windows":
21
 
                return false
22
 
        }
23
 
 
24
 
        t.Logf("user: Lookup not implemented on %s; skipping test", runtime.GOOS)
25
 
        return true
26
 
}
27
 
 
28
 
func TestCurrent(t *testing.T) {
29
 
        if skip(t) {
30
 
                return
31
 
        }
32
 
 
33
 
        u, err := Current()
34
 
        if err != nil {
35
 
                t.Fatalf("Current: %v", err)
36
 
        }
37
 
        fi, err := os.Stat(u.HomeDir)
38
 
        if err != nil || !fi.IsDir() {
39
 
                t.Errorf("expected a valid HomeDir; stat(%q): err=%v", u.HomeDir, err)
40
 
        }
41
 
        if u.Username == "" {
42
 
                t.Fatalf("didn't get a username")
43
 
        }
44
 
}
45
 
 
46
 
func compare(t *testing.T, want, got *User) {
47
 
        if want.Uid != got.Uid {
48
 
                t.Errorf("got Uid=%q; want %q", got.Uid, want.Uid)
49
 
        }
50
 
        if want.Username != got.Username {
51
 
                t.Errorf("got Username=%q; want %q", got.Username, want.Username)
52
 
        }
53
 
        if want.Name != got.Name {
54
 
                t.Errorf("got Name=%q; want %q", got.Name, want.Name)
55
 
        }
56
 
        // TODO(brainman): fix it once we know how.
57
 
        if runtime.GOOS == "windows" {
58
 
                t.Log("skipping Gid and HomeDir comparisons")
59
 
                return
60
 
        }
61
 
        if want.Gid != got.Gid {
62
 
                t.Errorf("got Gid=%q; want %q", got.Gid, want.Gid)
63
 
        }
64
 
        if want.HomeDir != got.HomeDir {
65
 
                t.Errorf("got HomeDir=%q; want %q", got.HomeDir, want.HomeDir)
66
 
        }
67
 
}
68
 
 
69
 
func TestLookup(t *testing.T) {
70
 
        if skip(t) {
71
 
                return
72
 
        }
73
 
 
74
 
        want, err := Current()
75
 
        if err != nil {
76
 
                t.Fatalf("Current: %v", err)
77
 
        }
78
 
        got, err := Lookup(want.Username)
79
 
        if err != nil {
80
 
                t.Fatalf("Lookup: %v", err)
81
 
        }
82
 
        compare(t, want, got)
83
 
}
84
 
 
85
 
func TestLookupId(t *testing.T) {
86
 
        if skip(t) {
87
 
                return
88
 
        }
89
 
 
90
 
        want, err := Current()
91
 
        if err != nil {
92
 
                t.Fatalf("Current: %v", err)
93
 
        }
94
 
        got, err := LookupId(want.Uid)
95
 
        if err != nil {
96
 
                t.Fatalf("LookupId: %v", err)
97
 
        }
98
 
        compare(t, want, got)
99
 
}