Debian Codegraph @

config/allconfig/load_test.go

raw
1 package allconfig
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7
8 "github.com/spf13/afero"
9 )
10
11 func BenchmarkLoad(b *testing.B) {
12 tempDir := b.TempDir()
13 configFilename := filepath.Join(tempDir, "hugo.toml")
14 config := `
15 baseURL = "https://example.com"
16 defaultContentLanguage = 'en'
17
18 [module]
19 [[module.mounts]]
20 source = 'content/en'
21 target = 'content/en'
22 [module.mounts.sites.matrix]
23 languages = 'en'
24 [[module.mounts]]
25 source = 'content/nn'
26 target = 'content/nn'
27 [module.mounts.sites.matrix]
28 languages = 'nn'
29 [[module.mounts]]
30 source = 'content/no'
31 target = 'content/no'
32 [module.mounts.sites.matrix]
33 languages = 'no'
34 [[module.mounts]]
35 source = 'content/sv'
36 target = 'content/sv'
37 [module.mounts.sites.matrix]
38 languages = 'sv'
39 [[module.mounts]]
40 source = 'layouts'
41 target = 'layouts'
42
43 [languages]
44 [languages.en]
45 title = "English"
46 weight = 1
47 [languages.nn]
48 title = "Nynorsk"
49 weight = 2
50 [languages.no]
51 title = "Norsk"
52 weight = 3
53 [languages.sv]
54 title = "Svenska"
55 weight = 4
56 `
57 if err := os.WriteFile(configFilename, []byte(config), 0o666); err != nil {
58 b.Fatal(err)
59 }
60 d := ConfigSourceDescriptor{
61 Fs: afero.NewOsFs(),
62 Filename: configFilename,
63 }
64
65 for b.Loop() {
66 _, err := LoadConfig(d)
67 if err != nil {
68 b.Fatal(err)
69 }
70 }
71 }