Skip to content

Commit a2469d5

Browse files
committed
testing: Rewrite all the old style integration tests to txtar style tests
And remove some not worth keeping (or too much work to convert).
1 parent 0efcb24 commit a2469d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4034
-8176
lines changed

‎config/configLoader.go‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 The Hugo Authors. All rights reserved.
1+
// Copyright 2025 The Hugo Authors. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import (
2020
"strings"
2121

2222
"github.com/gohugoio/hugo/common/herrors"
23+
"github.com/gohugoio/hugo/parser"
2324

2425
"github.com/gohugoio/hugo/common/paths"
2526

@@ -57,6 +58,7 @@ func IsValidConfigFilename(filename string) bool {
5758
return validConfigFileExtensionsMap[ext]
5859
}
5960

61+
// FromTOMLConfigString creates a config from the given TOML config. This is useful in tests.
6062
func FromTOMLConfigString(config string) Provider {
6163
cfg, err := FromConfigString(config, "toml")
6264
if err != nil {
@@ -65,6 +67,16 @@ func FromTOMLConfigString(config string) Provider {
6567
return cfg
6668
}
6769

70+
// FromMapToTOMLString converts the given map to a TOML string. This is useful in tests.
71+
func FromMapToTOMLString(v map[string]any) string {
72+
var sb strings.Builder
73+
err := parser.InterfaceToConfig(v, metadecoders.TOML, &sb)
74+
if err != nil {
75+
panic(err)
76+
}
77+
return sb.String()
78+
}
79+
6880
// FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests.
6981
func FromConfigString(config, configType string) (Provider, error) {
7082
m, err := readConfig(metadecoders.FormatFromString(configType), []byte(config))
@@ -218,7 +230,6 @@ func init() {
218230
// Before 0.53 we used singular for "menu".
219231
"{menu,languages/*/menu}", "menus",
220232
)
221-
222233
if err != nil {
223234
panic(err)
224235
}

‎go.mod‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ require (
4444
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.3.1
4545
github.com/gohugoio/locales v0.14.0
4646
github.com/gohugoio/localescompressed v1.0.1
47-
github.com/gohugoio/testmodBuilder/mods v0.0.0-20190520184928-c56af20f2e95
4847
github.com/google/go-cmp v0.7.0
4948
github.com/gorilla/websocket v1.5.3
5049
github.com/hairyhenderson/go-codeowners v0.7.0

‎hugolib/404_test.go‎

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 The Hugo Authors. All rights reserved.
1+
// Copyright 2025 The Hugo Authors. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -41,12 +41,7 @@ Page: {{ .Page.RelPermalink }}|
4141
Data: {{ len .Data }}|
4242
`
4343

44-
b := NewIntegrationTestBuilder(
45-
IntegrationTestConfig{
46-
T: t,
47-
TxtarString: files,
48-
},
49-
).Build()
44+
b := Test(t, files)
5045

5146
b.AssertFileContent("public/index.html", "All. home. |")
5247

@@ -68,25 +63,6 @@ Data: 1|
6863
`)
6964
}
7065

71-
func Test404WithBase(t *testing.T) {
72-
t.Parallel()
73-
74-
b := newTestSitesBuilder(t)
75-
b.WithSimpleConfigFile().WithTemplates("404.html", `{{ define "main" }}
76-
Page not found
77-
{{ end }}`,
78-
"baseof.html", `Base: {{ block "main" . }}{{ end }}`).WithContent("page.md", ``)
79-
80-
b.Build(BuildCfg{})
81-
82-
// Note: We currently have only 1 404 page. One might think that we should have
83-
// multiple, to follow the Custom Output scheme, but I don't see how that would work
84-
// right now.
85-
b.AssertFileContent("public/404.html", `
86-
Base:
87-
Page not found`)
88-
}
89-
9066
func Test404EditTemplate(t *testing.T) {
9167
t.Parallel()
9268

‎hugolib/alias_test.go‎

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 The Hugo Authors. All rights reserved.
1+
// Copyright 2025 The Hugo Authors. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -14,37 +14,17 @@
1414
package hugolib
1515

1616
import (
17-
"os"
1817
"path/filepath"
1918
"runtime"
19+
"strings"
2020
"testing"
2121

22-
qt "github.com/frankban/quicktest"
2322
"github.com/gohugoio/hugo/common/loggers"
24-
)
25-
26-
const pageWithAlias = `---
27-
title: Has Alias
28-
aliases: ["/foo/bar/", "rel"]
29-
---
30-
For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.
31-
`
32-
33-
const pageWithAliasMultipleOutputs = `---
34-
title: Has Alias for HTML and AMP
35-
aliases: ["/foo/bar/"]
36-
outputs: ["HTML", "AMP", "JSON"]
37-
---
38-
For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.
39-
`
40-
41-
const (
42-
basicTemplate = "<html><body>{{.Content}}</body></html>"
23+
"github.com/gohugoio/hugo/config"
4324
)
4425

4526
func TestAlias(t *testing.T) {
4627
t.Parallel()
47-
c := qt.New(t)
4828

4929
tests := []struct {
5030
fileSuffix string
@@ -60,15 +40,26 @@ func TestAlias(t *testing.T) {
6040
}
6141

6242
for _, test := range tests {
63-
b := newTestSitesBuilder(t)
64-
b.WithSimpleConfigFileAndSettings(test.settings).WithContent("blog/page.md", pageWithAlias)
65-
b.CreateSites().Build(BuildCfg{})
43+
files := `
44+
-- hugo.toml --
45+
disableKinds = ["rss", "sitemap", "taxonomy", "term"]
46+
CONFIG
47+
-- content/blog/page.md --
48+
---
49+
title: Has Alias
50+
aliases: ["/foo/bar/", "rel"]
51+
---
52+
For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.
53+
-- layouts/all.html --
54+
Title: {{ .Title }}|Content: {{ .Content }}|
55+
`
56+
files = strings.Replace(files, "CONFIG", config.FromMapToTOMLString(test.settings), 1)
6657

67-
c.Assert(len(b.H.Sites), qt.Equals, 1)
68-
c.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 1)
58+
b := Test(t, files)
6959

7060
// the real page
7161
b.AssertFileContent("public/blog/page"+test.fileSuffix, "For some moments the old man")
62+
7263
// the alias redirectors
7364
b.AssertFileContent("public/foo/bar"+test.fileSuffix, "<meta http-equiv=\"refresh\" content=\"0; url="+test.urlPrefix+"/blog/page"+test.urlSuffix+"\">")
7465
b.AssertFileContent("public/blog/rel"+test.fileSuffix, "<meta http-equiv=\"refresh\" content=\"0; url="+test.urlPrefix+"/blog/page"+test.urlSuffix+"\">")
@@ -78,19 +69,25 @@ func TestAlias(t *testing.T) {
7869
func TestAliasMultipleOutputFormats(t *testing.T) {
7970
t.Parallel()
8071

81-
c := qt.New(t)
82-
83-
b := newTestSitesBuilder(t)
84-
b.WithSimpleConfigFile().WithContent("blog/page.md", pageWithAliasMultipleOutputs)
85-
86-
b.WithTemplates(
87-
"_default/single.html", basicTemplate,
88-
"_default/single.amp.html", basicTemplate,
89-
"_default/single.json", basicTemplate)
90-
91-
b.CreateSites().Build(BuildCfg{})
72+
files := `
73+
-- hugo.toml --
74+
baseURL = "http://example.com"
75+
-- layouts/_default/single.html --
76+
{{ .Content }}
77+
-- layouts/_default/single.amp.html --
78+
{{ .Content }}
79+
-- layouts/_default/single.json --
80+
{{ .Content }}
81+
-- content/blog/page.md --
82+
---
83+
title: Has Alias for HTML and AMP
84+
aliases: ["/foo/bar/"]
85+
outputs: ["html", "amp", "json"]
86+
---
87+
For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.
88+
`
9289

93-
b.H.Sites[0].pageMap.debugPrint("", 999, os.Stdout)
90+
b := Test(t, files)
9491

9592
// the real pages
9693
b.AssertFileContent("public/blog/page/index.html", "For some moments the old man")
@@ -100,7 +97,7 @@ func TestAliasMultipleOutputFormats(t *testing.T) {
10097
// the alias redirectors
10198
b.AssertFileContent("public/foo/bar/index.html", "<meta http-equiv=\"refresh\" content=\"0; ")
10299
b.AssertFileContent("public/amp/foo/bar/index.html", "<meta http-equiv=\"refresh\" content=\"0; ")
103-
c.Assert(b.CheckExists("public/foo/bar/index.json"), qt.Equals, false)
100+
b.AssertFileExists("public/foo/bar/index.json", false)
104101
}
105102

106103
func TestAliasTemplate(t *testing.T) {

0 commit comments

Comments
 (0)