Add some cagegories to the site collections benchmarks

This commit is contained in:
Bjørn Erik Pedersen 2020-02-18 18:52:35 +01:00
parent d73e37387c
commit 36983e6189
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -35,7 +35,7 @@ type siteBenchmarkTestcase struct {
func getBenchmarkSiteDeepContent(b testing.TB) *sitesBuilder { func getBenchmarkSiteDeepContent(b testing.TB) *sitesBuilder {
pageContent := func(size int) string { pageContent := func(size int) string {
return getBenchmarkTestDataPageContentForMarkdown(size, benchmarkMarkdownSnippets) return getBenchmarkTestDataPageContentForMarkdown(size, "", benchmarkMarkdownSnippets)
} }
sb := newTestSitesBuilder(b).WithConfigFile("toml", ` sb := newTestSitesBuilder(b).WithConfigFile("toml", `
@ -85,14 +85,22 @@ contentDir="content/sv"
return sb return sb
} }
func getBenchmarkTestDataPageContentForMarkdown(size int, markdown string) string { func getBenchmarkTestDataPageContentForMarkdown(size int, category, markdown string) string {
return `--- base := `---
title: "My Page" title: "My Page"
%s
--- ---
My page content. My page content.
`
` + strings.Repeat(markdown, size) var categoryKey string
if category != "" {
categoryKey = fmt.Sprintf("categories: [%s]", category)
}
base = fmt.Sprintf(base, categoryKey)
return base + strings.Repeat(markdown, size)
} }
const benchmarkMarkdownSnippets = ` const benchmarkMarkdownSnippets = `
@ -111,8 +119,12 @@ See my [About](/about/) page for details.
func getBenchmarkSiteNewTestCases() []siteBenchmarkTestcase { func getBenchmarkSiteNewTestCases() []siteBenchmarkTestcase {
pageContentWithCategory := func(size int, category string) string {
return getBenchmarkTestDataPageContentForMarkdown(size, category, benchmarkMarkdownSnippets)
}
pageContent := func(size int) string { pageContent := func(size int) string {
return getBenchmarkTestDataPageContentForMarkdown(size, benchmarkMarkdownSnippets) return getBenchmarkTestDataPageContentForMarkdown(size, "", benchmarkMarkdownSnippets)
} }
config := ` config := `
@ -315,12 +327,22 @@ contentDir="content/sv"
`) `)
sb.WithTemplatesAdded("index.html", pageTemplateTemplate) sb.WithTemplates("index.html", pageTemplateTemplate)
sb.WithTemplatesAdded("_default/single.html", pageTemplateTemplate) sb.WithTemplates("_default/single.html", pageTemplateTemplate)
sb.WithTemplatesAdded("_default/list.html", pageTemplateTemplate) sb.WithTemplates("_default/list.html", pageTemplateTemplate)
r := rand.New(rand.NewSource(99))
createContent := func(dir, name string) { createContent := func(dir, name string) {
sb.WithContent(filepath.Join("content", dir, name), pageContent(1)) var content string
if strings.Contains(name, "_index") {
content = pageContent(1)
} else {
content = pageContentWithCategory(1, fmt.Sprintf("category%d", r.Intn(5)+1))
}
sb.WithContent(filepath.Join("content", dir, name), content)
} }
createBundledFiles := func(dir string) { createBundledFiles := func(dir string) {
@ -330,8 +352,6 @@ contentDir="content/sv"
} }
} }
r := rand.New(rand.NewSource(99))
for _, lang := range []string{"en", "fr", "no", "sv"} { for _, lang := range []string{"en", "fr", "no", "sv"} {
for level := 1; level <= r.Intn(5)+1; level++ { for level := 1; level <= r.Intn(5)+1; level++ {
sectionDir := path.Join(lang, strings.Repeat("section/", level)) sectionDir := path.Join(lang, strings.Repeat("section/", level))