testing: Simplify some integration tests

This commit is contained in:
Bjørn Erik Pedersen
2024-01-28 22:11:05 +01:00
parent 6dedb4efc7
commit 982d9513e7
32 changed files with 93 additions and 583 deletions

View File

@@ -48,15 +48,8 @@ title = "English Title"
[languages.en.params.comments]
title = "English Comments Title"
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
enSite := b.H.Sites[0]
b.Assert(enSite.Title(), qt.Equals, "English Title")
@@ -97,14 +90,8 @@ weight = 2
[languages.sv.params]
myparam = "svParamValue"
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
enSite := b.H.Sites[0]
svSite := b.H.Sites[1]
@@ -157,12 +144,7 @@ baseURL = "https://example.com"
[internal]
running = true
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.Assert(b.H.Conf.Running(), qt.Equals, false)
})
@@ -236,12 +218,7 @@ p1: {{ .Site.Params.p1 }}|
p2: {{ .Site.Params.p2 }}|
sub: {{ .Site.Params.sub }}|
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/en/index.html", `
title: English Title|
@@ -987,12 +964,7 @@ params:
mainSections: {{ site.Params.mainSections }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `
mainSections: []
@@ -1062,12 +1034,7 @@ Ein "Zitat" auf Deutsch.
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", "p1: p1base", "<p>A &ldquo;quote&rdquo; in English.</p>")
b.AssertFileContent("public/de/index.html", "p1: p1de", "<p>Ein &laquo;Zitat&raquo; auf Deutsch.</p>")
@@ -1129,12 +1096,7 @@ HTACCESS.
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/.htaccess", "HTACCESS")
}
@@ -1150,12 +1112,7 @@ LanguageCode: {{ .Site.LanguageCode }}|{{ site.Language.LanguageCode }}|
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", "LanguageCode: en-US|en-US|")
}
@@ -1181,12 +1138,7 @@ Home.
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", "Home.")
@@ -1214,12 +1166,7 @@ Foo: {{ site.Params.foo }}|
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", "Foo: |")
})
@@ -1295,12 +1242,7 @@ Home.
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.Assert(b.H.Configs.Base.Module.Mounts, qt.HasLen, 7)
b.Assert(b.H.Configs.LanguageConfigSlice[0].Module.Mounts, qt.HasLen, 7)
@@ -1321,12 +1263,7 @@ Foo.
-- layouts/index.html --
Home.
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/en/index.html", "Home.")
b.AssertFileContent("public/en/foo/bar.txt", "Foo.")
@@ -1354,12 +1291,7 @@ Foo.
-- layouts/index.html --
Home.
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/en/index.html", "Home.")
b.AssertFileContent("public/en/foo/bar.txt", "Foo.")
@@ -1387,12 +1319,7 @@ Foo.
-- layouts/index.html --
Home.
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", "Home.")
b.AssertFileContent("public/foo/bar.txt", "Foo.")
@@ -1417,12 +1344,7 @@ Home.
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.Assert(len(b.H.Sites), qt.Equals, 1)
}
@@ -1557,12 +1479,7 @@ List.
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileExists("public/index.html", true)
b.AssertFileExists("public/categories/c1/index.html", true)

View File

@@ -38,12 +38,7 @@ c = "c1"
-- layouts/index.html --
Params: {{ site.Params}}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `
Params: map[a:acp1 b:bc1 c:c1 d:dcp1]

View File

@@ -63,12 +63,7 @@ outputs: ["rss"]
---
P3. [I'm an inline-style link](https://www.example.org)
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `
P1: <p>P1. html-link: https://www.gohugo.io|</p>
@@ -163,12 +158,7 @@ P1 Fragments: {{ .Fragments.Identifiers }}|
{{ .Content}}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/p1/index.html", `
Self Fragments: [b c z]

View File

@@ -18,7 +18,6 @@ import (
)
func TestData(t *testing.T) {
t.Run("with theme", func(t *testing.T) {
t.Parallel()
@@ -43,14 +42,8 @@ b: {{ site.Data.b.v1 }}|
cd: {{ site.Data.c.d.v1 }}|
d: {{ site.Data.d.v1 }}|
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", "a: a_v1|\nb: b_v1|\ncd: c_d_v1|\nd: d_v1_theme|")
})
}

View File

@@ -255,12 +255,7 @@ mydata.date: {{ site.Data.mydata.date }}
Full time: {{ $p1Date | time.Format ":time_full" }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `
Future talks: 2

View File

@@ -76,12 +76,7 @@ Foo: {{< param foo >}}
-- layouts/index.html --
Content: {{ .Content }}|
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `
<figure>
@@ -94,6 +89,5 @@ Foo: bar
`)
})
}

View File

@@ -571,12 +571,7 @@ Page IsAncestor Self: {{ $page.IsAncestor $page }}
Page IsDescendant Self: {{ $page.IsDescendant $page}}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/tests/index.html", `
Tests|/tests/|IsMenuCurrent = true|HasMenuCurrent = false
@@ -609,12 +604,7 @@ Menu Item: {{ $i }}: {{ .Pre }}{{ .Name }}{{ .Post }}|{{ .URL }}|
{{ end }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `
Menu Item: 0: <span>Home</span>|/|
@@ -640,12 +630,7 @@ Menu Item: {{ $i }}|{{ .URL }}|
{{ end }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `
Menu Item: 0|/foo/posts|

View File

@@ -698,12 +698,7 @@ title: "empty"
|{{ .RawContent }}|
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/basic/index.html", "|**basic**|")
b.AssertFileContent("public/empty/index.html", "! title")

View File

@@ -153,12 +153,7 @@ Len: {{ len $empty }}: Type: {{ printf "%T" $empty }}
{{ $pag := .Paginate $pgs }}
Len Pag: {{ len $pag.Pages }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", "Len: 0", "Len Pag: 0")
}

View File

@@ -67,12 +67,7 @@ HasShortcode not found: {{ .HasShortcode "notfound" }}|
Content: {{ .Content }}|
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/p1/index.html",
"Fragments: [p1-h1 p2-h1 p2-h2 p2-h3 p2-withmarkdown p3-h1 p3-h2 p3-withmarkdown]|",
@@ -118,12 +113,7 @@ JSON: {{ .Content }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/p1/index.html", "Myshort HTML")
b.AssertFileContent("public/p1/index.json", "Myshort JSON")

View File

@@ -172,12 +172,7 @@ Has other: {{ .HasShortcode "other" }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html",
`
@@ -213,12 +208,7 @@ title: "P1"
{{ .Content }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/p1/index.html", `TableOfContents`)
}

View File

@@ -916,12 +916,7 @@ title: "p1"
{{ .Content }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/p1/index.html", `
<x
@@ -957,12 +952,7 @@ title: "p1"
{{ .Content }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/p1/index.html", "<ol>\n<li>\n<p>List 1</p>\n<ol>\n<li>Item Mark1 1</li>\n<li>Item Mark1 2</li>\n<li>Item Mark2 1</li>\n<li>Item Mark2 2\n<ol>\n<li>Item Mark2 2-1</li>\n</ol>\n</li>\n<li>Item Mark2 3</li>\n</ol>\n</li>\n</ol>")
}
@@ -987,12 +977,7 @@ echo "foo";
{{ .Content }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/p1/index.html", "<pre><code>echo &quot;foo&quot;;\n</code></pre>")
}
@@ -1023,12 +1008,7 @@ title: "p1"
{{ .Content }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/p1/index.html", `
<pre><code> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">line 1<span class="p">;</span>

View File

@@ -436,12 +436,7 @@ MainSections Site method: {{ site.MainSections }}|
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `
MainSections Params: [a b]|
@@ -469,12 +464,7 @@ MainSections Site method: {{ site.MainSections }}|
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `
MainSections Params: [a b]|
@@ -497,12 +487,7 @@ MainSections Site method: {{ site.MainSections }}|
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `
MainSections Params: [mysect]|

View File

@@ -128,12 +128,7 @@ SectionsEntries: {{ .SectionsEntries }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/withfile/index.html", "SectionsEntries: [withfile]")
b.AssertFileContent("public/withoutfile/index.html", "SectionsEntries: [withoutfile]")

View File

@@ -39,12 +39,7 @@ title: doc2
Doc2
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/sitemap.xml", " <loc>https://example.com/sect/doc1/</loc>", "doc2")
}
@@ -81,12 +76,7 @@ title: doc2
Doc2
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/sitemap.xml", "<loc>https://example.com/en/sitemap.xml</loc>", "<loc>https://example.com/nn/sitemap.xml</loc>")
b.AssertFileContent("public/en/sitemap.xml", " <loc>https://example.com/sect/doc1/</loc>", "doc2")
@@ -109,12 +99,7 @@ outputs: [ "html", "amp" ]
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
// Should link to the HTML version.
b.AssertFileContent("public/sitemap.xml", " <loc>https://example.com/blog/html-amp/</loc>")

View File

@@ -730,12 +730,7 @@ tags_weight: 40
---
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b := Test(t, files)
b.AssertFileContent("public/index.html", `:/p1/|/p3/|/p2/|:`)
}