hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 31fb29fb3f306678f3697e05bbccefb2078d7f78
parent d392893cd73dc00c927f342778f6dca9628d328e
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Wed, 16 Jun 2021 18:58:40 +0200

Do not read config from os.Environ when running tests

Fixes #8655

Diffstat:
Mcommands/commandeer.go | 1-
Mcommon/hugo/hugo.go | 10++++++++++
Mhugolib/config.go | 2+-
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/commands/commandeer.go b/commands/commandeer.go
@@ -303,7 +303,6 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error {
 			WorkingDir:   dir,
 			Filename:     c.h.cfgFile,
 			AbsConfigDir: c.h.getConfigDir(dir),
-			Environ:      os.Environ(),
 			Environment:  environment,
 		},
 		cfgSetAndInit,
diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go
@@ -141,3 +141,13 @@ func GetDependencyList() []string {
 
 	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
+}
diff --git a/hugolib/config.go b/hugolib/config.go
@@ -55,7 +55,7 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
 		d.Environment = hugo.EnvironmentProduction
 	}
 
-	if len(d.Environ) == 0 {
+	if len(d.Environ) == 0 && !hugo.IsRunningAsTest() {
 		d.Environ = os.Environ()
 	}