2012-03-27 23:13:14 +00:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-09-21 17:33:12 +00:00
|
|
|
func check(t *testing.T) {
|
2012-03-27 23:13:14 +00:00
|
|
|
if !implemented {
|
2014-09-21 17:33:12 +00:00
|
|
|
t.Skip("user: not implemented; skipping tests")
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCurrent(t *testing.T) {
|
2014-09-21 17:33:12 +00:00
|
|
|
check(t)
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
u, err := Current()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Current: %v", err)
|
|
|
|
}
|
2014-09-21 17:33:12 +00:00
|
|
|
if u.HomeDir == "" {
|
|
|
|
t.Errorf("didn't get a HomeDir")
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|
|
|
|
if u.Username == "" {
|
2014-09-21 17:33:12 +00:00
|
|
|
t.Errorf("didn't get a username")
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func compare(t *testing.T, want, got *User) {
|
|
|
|
if want.Uid != got.Uid {
|
|
|
|
t.Errorf("got Uid=%q; want %q", got.Uid, want.Uid)
|
|
|
|
}
|
|
|
|
if want.Username != got.Username {
|
|
|
|
t.Errorf("got Username=%q; want %q", got.Username, want.Username)
|
|
|
|
}
|
|
|
|
if want.Name != got.Name {
|
|
|
|
t.Errorf("got Name=%q; want %q", got.Name, want.Name)
|
|
|
|
}
|
|
|
|
// TODO(brainman): fix it once we know how.
|
|
|
|
if runtime.GOOS == "windows" {
|
2014-09-21 17:33:12 +00:00
|
|
|
t.Skip("skipping Gid and HomeDir comparisons")
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|
|
|
|
if want.Gid != got.Gid {
|
|
|
|
t.Errorf("got Gid=%q; want %q", got.Gid, want.Gid)
|
|
|
|
}
|
|
|
|
if want.HomeDir != got.HomeDir {
|
|
|
|
t.Errorf("got HomeDir=%q; want %q", got.HomeDir, want.HomeDir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLookup(t *testing.T) {
|
2014-09-21 17:33:12 +00:00
|
|
|
check(t)
|
|
|
|
|
|
|
|
if runtime.GOOS == "plan9" {
|
|
|
|
t.Skipf("Lookup not implemented on %q", runtime.GOOS)
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
want, err := Current()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Current: %v", err)
|
|
|
|
}
|
|
|
|
got, err := Lookup(want.Username)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Lookup: %v", err)
|
|
|
|
}
|
|
|
|
compare(t, want, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLookupId(t *testing.T) {
|
2014-09-21 17:33:12 +00:00
|
|
|
check(t)
|
|
|
|
|
|
|
|
if runtime.GOOS == "plan9" {
|
|
|
|
t.Skipf("LookupId not implemented on %q", runtime.GOOS)
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
want, err := Current()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Current: %v", err)
|
|
|
|
}
|
|
|
|
got, err := LookupId(want.Uid)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("LookupId: %v", err)
|
|
|
|
}
|
|
|
|
compare(t, want, got)
|
|
|
|
}
|