blob: be8983fdb86c6d00400578371bac674d80796077 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package helpers_test
import (
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/config/testconfig"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"github.com/spf13/afero"
)
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 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 newTestPathSpecFromCfgAndLang(cfg, "")
}
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)
}
return spec
}
|