diff options
Diffstat (limited to 'helpers/testhelpers_test.go')
-rw-r--r-- | helpers/testhelpers_test.go | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/helpers/testhelpers_test.go b/helpers/testhelpers_test.go index 00be3db25..be8983fdb 100644 --- a/helpers/testhelpers_test.go +++ b/helpers/testhelpers_test.go @@ -1,47 +1,47 @@ -package helpers +package helpers_test import ( "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/config" - "github.com/spf13/afero" - + "github.com/gohugoio/hugo/config/testconfig" + "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/hugofs" - "github.com/gohugoio/hugo/langs" - "github.com/gohugoio/hugo/modules" + "github.com/spf13/afero" ) -func newTestPathSpec(fs *hugofs.Fs, v config.Provider) *PathSpec { - l := langs.NewDefaultLanguage(v) - ps, _ := NewPathSpec(fs, l, nil) +func newTestPathSpecFromCfgAndLang(cfg config.Provider, lang string) *helpers.PathSpec { + mfs := afero.NewMemMapFs() + + configs := testconfig.GetTestConfigs(mfs, cfg) + var conf config.AllProvider + if lang == "" { + conf = configs.GetFirstLanguageConfig() + } else { + conf = configs.GetByLang(lang) + if conf == nil { + panic("no config for lang " + lang) + } + } + fs := hugofs.NewFrom(mfs, conf.BaseConfig()) + ps, err := helpers.NewPathSpec(fs, conf, loggers.NewErrorLogger()) + if err != nil { + panic(err) + } return ps } -func newTestDefaultPathSpec(configKeyValues ...any) *PathSpec { - cfg := newTestCfg() - fs := hugofs.NewMem(cfg) - +func newTestPathSpec(configKeyValues ...any) *helpers.PathSpec { + cfg := config.New() for i := 0; i < len(configKeyValues); i += 2 { cfg.Set(configKeyValues[i].(string), configKeyValues[i+1]) } - return newTestPathSpec(fs, cfg) -} - -func newTestCfg() config.Provider { - v := config.NewWithTestDefaults() - langs.LoadLanguageSettings(v, nil) - langs.LoadLanguageSettings(v, nil) - mod, err := modules.CreateProjectModule(v) - if err != nil { - panic(err) - } - v.Set("allModules", modules.Modules{mod}) - - return v + return newTestPathSpecFromCfgAndLang(cfg, "") } -func newTestContentSpec() *ContentSpec { - v := config.NewWithTestDefaults() - spec, err := NewContentSpec(v, loggers.NewErrorLogger(), afero.NewMemMapFs(), nil) +func newTestContentSpec(cfg config.Provider) *helpers.ContentSpec { + fs := afero.NewMemMapFs() + conf := testconfig.GetTestConfig(fs, cfg) + spec, err := helpers.NewContentSpec(conf, loggers.NewErrorLogger(), fs, nil) if err != nil { panic(err) } |