dcrd: Unable to override home directory
When building/testing in a containerized environment (such as Nix), the default home directory (/var/empty) is inaccessible. This prevents the unit tests from functioning:
dcrd> ++ go test -p 12 ./. -args --appdata /private/tmp/nix-build-dcrd-1.8.0.drv-1/tmp.G5ZHoVaIR3
dcrd> 2023-06-28 20:49:03.438 [INF] RPCS: Generating TLS certificates...
dcrd> 2023-06-28 20:49:03.457 [INF] RPCS: Done generating TLS certificates
dcrd> 2023-06-28 20:49:03.457 [INF] RPCS: Generating TLS certificates...
dcrd> 2023-06-28 20:49:03.464 [INF] RPCS: Done generating TLS certificates
dcrd> Error creating a default config file: mkdir /var/empty: file exists
dcrd> --- FAIL: TestLoadConfig (0.00s)
dcrd> config_test.go:30: Failed to load dcrd config: loadConfig: failed to create home directory: mkdir /var/empty: file exists
dcrd> Error creating a default config file: mkdir /var/empty: file exists
dcrd> --- FAIL: TestDefaultAltDNSNames (0.00s)
dcrd> config_test.go:41: Failed to load dcrd config: loadConfig: failed to create home directory: mkdir /var/empty: file exists
dcrd> Error creating a default config file: mkdir /var/empty: file exists
dcrd> --- FAIL: TestAltDNSNamesWithEnv (0.00s)
dcrd> config_test.go:56: Failed to load dcrd config: loadConfig: failed to create home directory: mkdir /var/empty: file exists
dcrd> Error creating a default config file: mkdir /var/empty: file exists
dcrd> --- FAIL: TestAltDNSNamesWithArg (0.00s)
dcrd> config_test.go:74: Failed to load dcrd config: loadConfig: failed to create home directory: mkdir /var/empty: file exists
dcrd> FAIL
dcrd> FAIL github.com/decred/dcrd 0.190s
dcrd> FAIL
The logic in appDataDir will only consult the HOME environment variable if the lookup from /etc/passwd fails. This prevents me from overriding the value at runtime. If the HOME environment variable was consulted first, running the unit tests in a sandbox would be much easier.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 19 (17 by maintainers)
Support for setting the directory via the
DCRD_APPDATAenvironment variable has been merged.