aboutsummaryrefslogtreecommitdiffhomepage
path: root/config/allconfig/load_test.go
blob: 3c16e71e9502f735b914d3518e256d94a0c88549 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package allconfig

import (
	"os"
	"path/filepath"
	"testing"

	"github.com/spf13/afero"
)

func BenchmarkLoad(b *testing.B) {
	tempDir := b.TempDir()
	configFilename := filepath.Join(tempDir, "hugo.toml")
	config := `
baseURL = "https://example.com"
defaultContentLanguage = 'en'

[module]
[[module.mounts]]
source = 'content/en'
target = 'content/en'
lang = 'en'
[[module.mounts]]
source = 'content/nn'
target = 'content/nn'
lang = 'nn'
[[module.mounts]]
source = 'content/no'
target = 'content/no'
lang = 'no'
[[module.mounts]]
source = 'content/sv'
target = 'content/sv'
lang = 'sv'
[[module.mounts]]
source = 'layouts'
target = 'layouts'

[languages]
[languages.en]
title = "English"
weight = 1
[languages.nn]
title = "Nynorsk"
weight = 2
[languages.no]
title = "Norsk"
weight = 3
[languages.sv]
title = "Svenska"
weight = 4
`
	if err := os.WriteFile(configFilename, []byte(config), 0o666); err != nil {
		b.Fatal(err)
	}
	d := ConfigSourceDescriptor{
		Fs:       afero.NewOsFs(),
		Filename: configFilename,
	}

	for i := 0; i < b.N; i++ {
		_, err := LoadConfig(d)
		if err != nil {
			b.Fatal(err)
		}
	}
}