aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-01-28 11:14:35 +0100
committerBjørn Erik Pedersen <[email protected]>2024-01-28 11:29:23 +0100
commit50dc327d1aa52a785382468aaf5a5f9cae456dbf (patch)
tree6a86e67a2e83f7a5e5ecd70ae93e83468b0253c6
parent7285e74090852b5d52f25e577850fa75f4aa8573 (diff)
downloadhugo-50dc327d1aa52a785382468aaf5a5f9cae456dbf.tar.gz
hugo-50dc327d1aa52a785382468aaf5a5f9cae456dbf.zip
Port some integration tests to new test setup
The method I'm currently using (if other want to help) is: * Add fmt.Println(b.DumpTxtar()) after the Build step * Add that to a files var and pass that to Test(t, files) or similar * Then, if possible, try to reduce the files/content down to what's needed in test. Note that if the test is small, it's probably faster just to manually re-create the test.
-rw-r--r--hugolib/hugo_modules_test.go77
1 files changed, 30 insertions, 47 deletions
diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go
index b37cf0e78..243447805 100644
--- a/hugolib/hugo_modules_test.go
+++ b/hugolib/hugo_modules_test.go
@@ -657,30 +657,24 @@ min_version = 0.55.0
func TestMountsProject(t *testing.T) {
t.Parallel()
- config := `
-
+ files := `
+-- config.toml --
baseURL="https://example.org"
[module]
[[module.mounts]]
source="mycontent"
target="content"
-
-`
- b := newTestSitesBuilder(t).
- WithConfigFile("toml", config).
- WithSourceFile(filepath.Join("mycontent", "mypage.md"), `
+-- layouts/_default/single.html --
+Permalink: {{ .Permalink }}|
+-- mycontent/mypage.md --
---
title: "My Page"
---
+`
+ b := Test(t, files)
-`)
-
- b.Build(BuildCfg{})
-
- // helpers.PrintFs(b.H.Fs.Source, "public", os.Stdout)
-
- b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/")
+ b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/|")
}
// https://github.com/gohugoio/hugo/issues/6684
@@ -706,25 +700,20 @@ Home: {{ .Title }}|{{ .Content }}|
func TestSiteWithGoModButNoModules(t *testing.T) {
t.Parallel()
- c := qt.New(t)
- // We need to use the OS fs for this.
- workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-no-mod")
- c.Assert(err, qt.IsNil)
-
- cfg := config.New()
- cfg.Set("workingDir", workDir)
- cfg.Set("publishDir", "public")
- fs := hugofs.NewFromOld(hugofs.Os, cfg)
+ tempDir := t.TempDir()
- defer clean()
+ files := `
+-- hugo.toml --
+baseURL = "https://example.org"
+-- go.mod --
- b := newTestSitesBuilder(t)
- b.Fs = fs
+`
- b.WithWorkingDir(workDir).WithViper(cfg)
+ b := Test(t, files, TestOptWithConfig(func(cfg *IntegrationTestConfig) {
+ cfg.WorkingDir = tempDir
+ }))
- b.WithSourceFile("go.mod", "")
- b.Build(BuildCfg{})
+ b.Build()
}
// https://github.com/gohugoio/hugo/issues/6622
@@ -783,7 +772,9 @@ P1: {{ $p1.Title }}|{{ $p1.RelPermalink }}|Filename: {{ $p1.File.Filename }}
// Issue 9426
func TestMountSameSource(t *testing.T) {
- config := `baseURL = 'https://example.org/'
+ files := `
+-- hugo.toml --
+baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'Hugo GitHub Issue #9426'
@@ -800,18 +791,15 @@ target = "content/resources-a"
[[module.mounts]]
source = "extra-content"
target = "content/resources-b"
+-- layouts/_default/single.html --
+Single
+-- content/p1.md --
+-- extra-content/_index.md --
+-- extra-content/subdir/_index.md --
+-- extra-content/subdir/about.md --
+"
`
- b := newTestSitesBuilder(t).WithConfigFile("toml", config)
-
- b.WithContent("p1.md", "")
-
- b.WithSourceFile(
- "extra-content/_index.md", "",
- "extra-content/subdir/_index.md", "",
- "extra-content/subdir/about.md", "",
- )
-
- b.Build(BuildCfg{})
+ b := Test(t, files)
b.AssertFileContent("public/resources-a/subdir/about/index.html", "Single")
b.AssertFileContent("public/resources-b/subdir/about/index.html", "Single")
@@ -836,12 +824,7 @@ message: Hugo Rocks
{{ site.Data.extra.test.message }}
`
- b := NewIntegrationTestBuilder(
- IntegrationTestConfig{
- T: t,
- TxtarString: files,
- },
- ).Build()
+ b := Test(t, files)
b.AssertFileContent("public/index.html", "Hugo Rocks")
}