testhelpers_test.go (1133B)
1 package helpers
2
3 import (
4 "github.com/gohugoio/hugo/common/loggers"
5 "github.com/gohugoio/hugo/config"
6 "github.com/spf13/afero"
7
8 "github.com/gohugoio/hugo/hugofs"
9 "github.com/gohugoio/hugo/langs"
10 "github.com/gohugoio/hugo/modules"
11 )
12
13 func newTestPathSpec(fs *hugofs.Fs, v config.Provider) *PathSpec {
14 l := langs.NewDefaultLanguage(v)
15 ps, _ := NewPathSpec(fs, l, nil)
16 return ps
17 }
18
19 func newTestDefaultPathSpec(configKeyValues ...any) *PathSpec {
20 cfg := newTestCfg()
21 fs := hugofs.NewMem(cfg)
22
23 for i := 0; i < len(configKeyValues); i += 2 {
24 cfg.Set(configKeyValues[i].(string), configKeyValues[i+1])
25 }
26 return newTestPathSpec(fs, cfg)
27 }
28
29 func newTestCfg() config.Provider {
30 v := config.NewWithTestDefaults()
31 langs.LoadLanguageSettings(v, nil)
32 langs.LoadLanguageSettings(v, nil)
33 mod, err := modules.CreateProjectModule(v)
34 if err != nil {
35 panic(err)
36 }
37 v.Set("allModules", modules.Modules{mod})
38
39 return v
40 }
41
42 func newTestContentSpec() *ContentSpec {
43 v := config.NewWithTestDefaults()
44 spec, err := NewContentSpec(v, loggers.NewErrorLogger(), afero.NewMemMapFs(), nil)
45 if err != nil {
46 panic(err)
47 }
48 return spec
49 }