OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [os/] [user/] [user_test.go] - Blame information for rev 774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.