Debian Codegraph @

helpers/testhelpers_test.go

raw
1 package helpers_test
2
3 import (
4 "github.com/gohugoio/hugo/common/loggers"
5 "github.com/gohugoio/hugo/config"
6 "github.com/gohugoio/hugo/config/testconfig"
7 "github.com/gohugoio/hugo/helpers"
8 "github.com/gohugoio/hugo/hugofs"
9 "github.com/spf13/afero"
10 )
11
12 func newTestPathSpecFromCfgAndLang(cfg config.Provider, lang string) *helpers.PathSpec {
13 mfs := afero.NewMemMapFs()
14
15 configs := testconfig.GetTestConfigs(mfs, cfg)
16 var conf config.AllProvider
17 if lang == "" {
18 conf = configs.GetFirstLanguageConfig()
19 } else {
20 conf = configs.GetByLang(lang)
21 if conf == nil {
22 panic("no config for lang " + lang)
23 }
24 }
25 fs := hugofs.NewFrom(mfs, conf.BaseConfig())
26 ps, err := helpers.NewPathSpec(fs, conf, loggers.NewDefault(), nil)
27 if err != nil {
28 panic(err)
29 }
30 return ps
31 }
32
33 func newTestPathSpec(configKeyValues ...any) *helpers.PathSpec {
34 cfg := config.New()
35 for i := 0; i < len(configKeyValues); i += 2 {
36 cfg.Set(configKeyValues[i].(string), configKeyValues[i+1])
37 }
38 return newTestPathSpecFromCfgAndLang(cfg, "")
39 }
40
41 func newTestContentSpec(cfg config.Provider) *helpers.ContentSpec {
42 fs := afero.NewMemMapFs()
43 conf := testconfig.GetTestConfig(fs, cfg)
44 spec, err := helpers.NewContentSpec(conf, loggers.NewDefault(), fs, nil)
45 if err != nil {
46 panic(err)
47 }
48 return spec
49 }