Skip to content

Commit

Permalink
dcrutil: Use os.UserHomedir for base home directory in tests
Browse files Browse the repository at this point in the history
The home directory associated with a user (e.g. their passwd entry on Unix)
may not match the HOME environment variable that the non-test code will use
for the home directory.  There's no reason to fail the test if these differ,
so use os.UserHomeDir across the board.

Observed in a sandboxed nix build environment where the user's passwd entry
used /build for the home directory, but $HOME was set to /homeless-shelter.
  • Loading branch information
jrick authored and davecgh committed Apr 3, 2024
1 parent 9711c57 commit bd3fe2f
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions dcrutil/appdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package dcrutil

import (
"os"
"os/user"
"path/filepath"
"runtime"
"testing"
Expand Down Expand Up @@ -39,13 +38,11 @@ func TestAppDataDir(t *testing.T) {
}

// Get the home directory to use for testing expected results.
var homeDir string
usr, err := user.Current()
homeDir, err := os.UserHomeDir()
if err != nil {
t.Errorf("user.Current: %v", err)
t.Errorf("os.UserHomeDir: %v", err)
return
}
homeDir = usr.HomeDir

// Mac app data directory.
macAppData := filepath.Join(homeDir, "Library", "Application Support")
Expand Down

0 comments on commit bd3fe2f

Please sign in to comment.