aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/integrationtest_builder.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-01-04 18:24:36 +0100
committerBjørn Erik Pedersen <[email protected]>2023-05-16 18:01:29 +0200
commit241b21b0fd34d91fccb2ce69874110dceae6f926 (patch)
treed4e0118eac7e9c42f065815447a70805f8d6ad3e /hugolib/integrationtest_builder.go
parent6aededf6b42011c3039f5f66487a89a8dd65e0e7 (diff)
downloadhugo-241b21b0fd34d91fccb2ce69874110dceae6f926.tar.gz
hugo-241b21b0fd34d91fccb2ce69874110dceae6f926.zip
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
Diffstat (limited to 'hugolib/integrationtest_builder.go')
-rw-r--r--hugolib/integrationtest_builder.go67
1 files changed, 48 insertions, 19 deletions
diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go
index 9be3f7c2e..02add495c 100644
--- a/hugolib/integrationtest_builder.go
+++ b/hugolib/integrationtest_builder.go
@@ -3,6 +3,7 @@ package hugolib
import (
"bytes"
"encoding/base64"
+ "errors"
"fmt"
"io"
"os"
@@ -19,7 +20,9 @@ import (
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/hexec"
"github.com/gohugoio/hugo/common/loggers"
+ "github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config"
+ "github.com/gohugoio/hugo/config/allconfig"
"github.com/gohugoio/hugo/config/security"
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/helpers"
@@ -194,10 +197,11 @@ func (s *IntegrationTestBuilder) Build() *IntegrationTestBuilder {
if s.Cfg.Verbose || err != nil {
fmt.Println(s.logBuff.String())
}
+ s.Assert(err, qt.IsNil)
if s.Cfg.RunGC {
s.GCCount, err = s.H.GC()
}
- s.Assert(err, qt.IsNil)
+
return s
}
@@ -308,38 +312,57 @@ func (s *IntegrationTestBuilder) initBuilder() error {
s.Assert(afero.WriteFile(afs, filename, data, 0666), qt.IsNil)
}
- configDirFilename := filepath.Join(s.Cfg.WorkingDir, "config")
- if _, err := afs.Stat(configDirFilename); err != nil {
- configDirFilename = ""
+ configDir := "config"
+ if _, err := afs.Stat(filepath.Join(s.Cfg.WorkingDir, "config")); err != nil {
+ configDir = ""
}
- cfg, _, err := LoadConfig(
- ConfigSourceDescriptor{
- WorkingDir: s.Cfg.WorkingDir,
- AbsConfigDir: configDirFilename,
- Fs: afs,
- Logger: logger,
- Environ: []string{},
- },
- func(cfg config.Provider) error {
- return nil
+ var flags config.Provider
+ if s.Cfg.BaseCfg != nil {
+ flags = s.Cfg.BaseCfg
+ } else {
+ flags = config.New()
+ }
+
+ if s.Cfg.Running {
+ flags.Set("internal", maps.Params{
+ "running": s.Cfg.Running,
+ })
+ }
+
+ if s.Cfg.WorkingDir != "" {
+ flags.Set("workingDir", s.Cfg.WorkingDir)
+ }
+
+ res, err := allconfig.LoadConfig(
+ allconfig.ConfigSourceDescriptor{
+ Flags: flags,
+ ConfigDir: configDir,
+ Fs: afs,
+ Logger: logger,
+ Environ: s.Cfg.Environ,
},
)
- s.Assert(err, qt.IsNil)
-
- cfg.Set("workingDir", s.Cfg.WorkingDir)
+ if err != nil {
+ initErr = err
+ return
+ }
- fs := hugofs.NewFrom(afs, cfg)
+ fs := hugofs.NewFrom(afs, res.LoadingInfo.BaseConfig)
s.Assert(err, qt.IsNil)
- depsCfg := deps.DepsCfg{Cfg: cfg, Fs: fs, Running: s.Cfg.Running, Logger: logger}
+ depsCfg := deps.DepsCfg{Configs: res, Fs: fs, Logger: logger}
sites, err := NewHugoSites(depsCfg)
if err != nil {
initErr = err
return
}
+ if sites == nil {
+ initErr = errors.New("no sites")
+ return
+ }
s.H = sites
s.fs = fs
@@ -482,6 +505,12 @@ type IntegrationTestConfig struct {
// https://pkg.go.dev/golang.org/x/exp/cmd/txtar
TxtarString string
+ // COnfig to use as the base. We will also read the config from the txtar.
+ BaseCfg config.Provider
+
+ // Environment variables passed to the config loader.
+ Environ []string
+
// Whether to simulate server mode.
Running bool