Do not read config from os.Environ when running tests

Fixes #8655
This commit is contained in:
Bjørn Erik Pedersen 2021-06-16 18:58:40 +02:00
parent d392893cd7
commit 31fb29fb3f
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
3 changed files with 11 additions and 2 deletions

View file

@ -303,7 +303,6 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error {
WorkingDir: dir, WorkingDir: dir,
Filename: c.h.cfgFile, Filename: c.h.cfgFile,
AbsConfigDir: c.h.getConfigDir(dir), AbsConfigDir: c.h.getConfigDir(dir),
Environ: os.Environ(),
Environment: environment, Environment: environment,
}, },
cfgSetAndInit, cfgSetAndInit,

View file

@ -141,3 +141,13 @@ func GetDependencyList() []string {
return deps return deps
} }
// IsRunningAsTest reports whether we are running as a test.
func IsRunningAsTest() bool {
for _, arg := range os.Args {
if strings.HasPrefix(arg, "-test") {
return true
}
}
return false
}

View file

@ -55,7 +55,7 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
d.Environment = hugo.EnvironmentProduction d.Environment = hugo.EnvironmentProduction
} }
if len(d.Environ) == 0 { if len(d.Environ) == 0 && !hugo.IsRunningAsTest() {
d.Environ = os.Environ() d.Environ = os.Environ()
} }