Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/user: tests fail if there is no home directory for current user #3531

Closed
oerdnj opened this issue Apr 15, 2012 · 6 comments
Closed

os/user: tests fail if there is no home directory for current user #3531

oerdnj opened this issue Apr 15, 2012 · 6 comments

Comments

@oerdnj
Copy link

oerdnj commented Apr 15, 2012

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. Create fake (buildd) user without home directory
2. Run tests
3. os/user test fail

What is the expected output?
Tests don't fail

What do you see instead?
--- FAIL: TestCurrent (0.00 seconds)
    user_test.go:39: expected a valid HomeDir; stat("/home/buildd"): err=stat /home/buildd: no such file or directory
FAIL
FAIL    os/user 0.010s

Which compiler are you using (5g, 6g, 8g, gccgo)?
N/A

Which operating system are you using?
Linux, buildd architecture

Which version are you using?  (run 'go version')
Go1

Please provide any additional information below.
Full build log:
https://buildd.debian.org/status/fetch.php?pkg=golang&;arch=i386&ver=2%3A1-3&stamp=1334185838

While I can fix that pretty easily (at least I hope that you use $HOME and don't parse
/etc/passwd), I don't think that this test should hard FAIL is there is no homedirectory
for the user.

Anyway feel free to close this bug report if you disagree ;).
@oerdnj
Copy link
Author

oerdnj commented Apr 15, 2012

Comment 1:

Ok, so this is a (semi-)real issue. The os/user test doesn't honor $HOME variable :(, so
I had to patch the sources to remove isDir() check from the test.
I know this is a corner case, but do you really have to check for the existence of the
directory? What it does really test?
Here is the patch:
--- a/src/pkg/os/user/user_test.go
+++ b/src/pkg/os/user/user_test.go
@@ -35,7 +35,7 @@ func TestCurrent(t *testing.T) {
                t.Fatalf("Current: %v", err)
        }
        fi, err := os.Stat(u.HomeDir)
-       if err != nil || !fi.IsDir() {
+       if err != nil {
                t.Errorf("expected a valid HomeDir; stat(%q): err=%v", u.HomeDir, err)
        }
        if u.Username == "" {

@bradfitz
Copy link
Contributor

Comment 2:

That patch doesn't look right, but I can fix this some way or another if you help me
understand.
The test is doing that to make sure it got a value.  It's more likely that the code is
messed up and failing to get a home directory than the user not having a home directory.
It doesn't respect $HOME because the Lookup and LookupId functions look up any user (not
just the current one), so $HOME wouldn't be correct in the general sense.  Current() is
just a convenience wrapper around LookupId.
What is the home dir on Debian buildd accounts set to?

Owner changed to @bradfitz.

Status changed to Accepted.

@oerdnj
Copy link
Author

oerdnj commented Apr 17, 2012

Comment 3:

> What is the home dir on Debian buildd accounts set to?
--- FAIL: TestCurrent (0.00 seconds)
    user_test.go:39: expected a valid HomeDir; stat("/home/buildd"): err=stat /home/buildd: no such file or directory
FAIL
FAIL    os/user 0.010s
Couldn't you just ask for user with uid=0? (e.g. root will always exist on any unix
systems.)

@bradfitz
Copy link
Contributor

Comment 4:

Oh, you do have a home directory configured but it just doesn't exist.  I thought
/etc/passwd had a blank entry there.
This is enough then: http://golang.org/cl/6056045

@bradfitz
Copy link
Contributor

Comment 6:

This issue was closed by revision 90aa56f.

Status changed to Fixed.

@oerdnj
Copy link
Author

oerdnj commented Apr 18, 2012

Comment 7:

Thanks Brad!

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants