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
Labels
Comments
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 == "" { |
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. |
> 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.) |
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 |
This issue was closed by revision 90aa56f. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: