Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 481baa0

Browse files
committed
all: Replace NewIntegrationTestBuilder with Test/TestE/TestRunning
1 parent 43aad71 commit 481baa0

47 files changed

Lines changed: 230 additions & 1130 deletions

Some content is hidden

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

cache/filecache/filecache_integration_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"testing"
1919
"time"
2020

21-
"github.com/bep/logg"
2221
qt "github.com/frankban/quicktest"
2322
"github.com/gohugoio/hugo/htesting"
2423
"github.com/gohugoio/hugo/hugolib"
@@ -39,9 +38,9 @@ title: "Home"
3938
4039
`
4140

42-
b := hugolib.NewIntegrationTestBuilder(
43-
hugolib.IntegrationTestConfig{T: t, TxtarString: files, RunGC: true, NeedsOsFS: true},
44-
).Build()
41+
b := hugolib.Test(t, files, hugolib.TestOptOsFs(), hugolib.TestOptWithConfig(func(c *hugolib.IntegrationTestConfig) {
42+
c.RunGC = true
43+
}))
4544

4645
_, err := b.H.BaseFs.ResourcesCache.Stat(filepath.Join("_gen", "images"))
4746

@@ -77,9 +76,9 @@ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAA
7776
7877
`
7978

80-
b := hugolib.NewIntegrationTestBuilder(
81-
hugolib.IntegrationTestConfig{T: t, TxtarString: files, Running: true, RunGC: true, NeedsOsFS: true, LogLevel: logg.LevelInfo},
82-
).Build()
79+
b := hugolib.TestRunning(t, files, hugolib.TestOptOsFs(), hugolib.TestOptInfo(), hugolib.TestOptWithConfig(func(c *hugolib.IntegrationTestConfig) {
80+
c.RunGC = true
81+
}))
8382

8483
b.Assert(b.GCCount, qt.Equals, 0)
8584
b.Assert(b.H, qt.IsNotNil)

config/allconfig/allconfig_integration_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ title: "p1"
4343
Title: {{ .Title }}
4444
`
4545

46-
b := hugolib.NewIntegrationTestBuilder(
47-
hugolib.IntegrationTestConfig{T: t, TxtarString: files},
48-
).Build()
46+
b := hugolib.Test(t, files)
4947

5048
// b.AssertFileContent("public/p1/index.html", "Title: p1")
5149

@@ -81,9 +79,7 @@ baseURL = "https://example.com"
8179
logI18nWarnings = true
8280
logPathWarnings = true
8381
`
84-
b := hugolib.NewIntegrationTestBuilder(
85-
hugolib.IntegrationTestConfig{T: t, TxtarString: files},
86-
).Build()
82+
b := hugolib.Test(t, files)
8783

8884
conf := b.H.Configs.Base
8985

hugolib/config_test.go

Lines changed: 27 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,7 @@ weight = 1
125125
[languages.sv]
126126
weight = 2
127127
`
128-
b, err := NewIntegrationTestBuilder(
129-
IntegrationTestConfig{
130-
T: t,
131-
TxtarString: files,
132-
},
133-
).BuildE()
128+
b, err := TestE(t, files)
134129

135130
b.Assert(err, qt.IsNotNil)
136131
b.Assert(err.Error(), qt.Contains, `default language "sv" is disabled`)
@@ -174,13 +169,9 @@ pm31: {{ .Site.Params.pm3.pm31 }}
174169
175170
176171
`
177-
b := NewIntegrationTestBuilder(
178-
IntegrationTestConfig{
179-
T: t,
180-
TxtarString: files,
181-
Environ: []string{"HUGO_PARAMS_P2=p2env", "HUGO_PARAMS_PM2_PM21=pm21env", "HUGO_PARAMS_PM3_PM31=pm31env"},
182-
},
183-
).Build()
172+
b := Test(t, files, TestOptWithConfig(func(c *IntegrationTestConfig) {
173+
c.Environ = []string{"HUGO_PARAMS_P2=p2env", "HUGO_PARAMS_PM2_PM21=pm21env", "HUGO_PARAMS_PM3_PM31=pm31env"}
174+
}))
184175

185176
b.AssertFileContent("public/index.html", "p1: p1base\np2: p2env\npm21: pm21env\npm22: pm22base\npm31: pm31env")
186177
})
@@ -254,14 +245,9 @@ Home.
254245
for i, v := range environ {
255246
environ[i] = strings.ReplaceAll(v, " ", delim)
256247
}
257-
b := NewIntegrationTestBuilder(
258-
IntegrationTestConfig{
259-
T: t,
260-
TxtarString: files,
261-
Environ: environ,
262-
BuildCfg: BuildCfg{SkipRender: true},
263-
},
264-
).Build()
248+
b := Test(t, files, TestOptSkipRender(), TestOptWithConfig(func(c *IntegrationTestConfig) {
249+
c.Environ = environ
250+
}))
265251

266252
conf := b.H.Configs.Base
267253
b.Assert(conf.DisableLanguages, qt.DeepEquals, []string{"no", "sv"})
@@ -651,12 +637,7 @@ defaultMarkdownHandler = 'blackfriday'
651637
652638
`
653639

654-
b, err := NewIntegrationTestBuilder(
655-
IntegrationTestConfig{
656-
T: t,
657-
TxtarString: files,
658-
},
659-
).BuildE()
640+
b, err := TestE(t, files)
660641

661642
b.Assert(err, qt.IsNotNil)
662643
b.Assert(err.Error(), qt.Contains, "Configured defaultMarkdownHandler \"blackfriday\" not found. Did you mean to use goldmark? Blackfriday was removed in Hugo v0.100.0.")
@@ -692,12 +673,7 @@ themeconfigdirparam: {{ site.Params.themeconfigdirparam }}
692673

693674
files := strings.ReplaceAll(filesTemplate, "hugo.toml", configName)
694675

695-
b, err := NewIntegrationTestBuilder(
696-
IntegrationTestConfig{
697-
T: t,
698-
TxtarString: files,
699-
},
700-
).BuildE()
676+
b, err := TestE(t, files)
701677

702678
b.Assert(err, qt.IsNil)
703679
b.AssertFileContent("public/index.html",
@@ -743,13 +719,9 @@ Single.
743719
files = strings.ReplaceAll(files, "WEIGHT_SV", "2")
744720

745721
cfg := config.New()
746-
b, err := NewIntegrationTestBuilder(
747-
IntegrationTestConfig{
748-
T: t,
749-
TxtarString: files,
750-
BaseCfg: cfg,
751-
},
752-
).BuildE()
722+
b, err := TestE(t, files, TestOptWithConfig(func(c *IntegrationTestConfig) {
723+
c.BaseCfg = cfg
724+
}))
753725

754726
b.Assert(err, qt.IsNil)
755727
b.AssertFileContent("public/index.html", "Home: en|2|")
@@ -762,13 +734,9 @@ Single.
762734

763735
for range 20 {
764736
cfg := config.New()
765-
b, err := NewIntegrationTestBuilder(
766-
IntegrationTestConfig{
767-
T: t,
768-
TxtarString: files,
769-
BaseCfg: cfg,
770-
},
771-
).BuildE()
737+
b, err := TestE(t, files, TestOptWithConfig(func(c *IntegrationTestConfig) {
738+
c.BaseCfg = cfg
739+
}))
772740

773741
b.Assert(err, qt.IsNil)
774742
b.AssertFileContent("public/index.html", "Home: en|2|")
@@ -801,12 +769,7 @@ Home.
801769
802770
`
803771

804-
b, err := NewIntegrationTestBuilder(
805-
IntegrationTestConfig{
806-
T: t,
807-
TxtarString: files,
808-
},
809-
).BuildE()
772+
b, err := TestE(t, files)
810773

811774
b.Assert(err, qt.IsNil)
812775
b.AssertFileContent("public/myindex.html", "Home.")
@@ -836,12 +799,7 @@ ThisIsAParam: {{ site.Params.thisIsAParam }}
836799
837800
`
838801

839-
b, err := NewIntegrationTestBuilder(
840-
IntegrationTestConfig{
841-
T: t,
842-
TxtarString: files,
843-
},
844-
).BuildE()
802+
b, err := TestE(t, files)
845803

846804
b.Assert(err, qt.IsNil)
847805
b.AssertFileContent("public/index.html", `
@@ -882,13 +840,7 @@ LanguageCode: {{ eq site.LanguageCode site.Language.LanguageCode }}|{{ site.Lang
882840
{{ end }}
883841
884842
`
885-
b := NewIntegrationTestBuilder(
886-
IntegrationTestConfig{
887-
T: t,
888-
TxtarString: files,
889-
LogLevel: logg.LevelWarn,
890-
},
891-
).Build()
843+
b := Test(t, files, TestOptWarn())
892844

893845
b.Assert(b.H.Log.LoggCount(logg.LevelWarn), qt.Equals, 1)
894846

@@ -936,13 +888,9 @@ func TestConfigHugoWorkingDir(t *testing.T) {
936888
WorkingDir: {{ hugo.WorkingDir }}|
937889
938890
`
939-
b := NewIntegrationTestBuilder(
940-
IntegrationTestConfig{
941-
T: t,
942-
TxtarString: files,
943-
WorkingDir: "myworkingdir",
944-
},
945-
).Build()
891+
b := Test(t, files, TestOptWithConfig(func(c *IntegrationTestConfig) {
892+
c.WorkingDir = "myworkingdir"
893+
}))
946894

947895
b.AssertFileContent("public/index.html", `
948896
WorkingDir: myworkingdir|
@@ -1009,12 +957,7 @@ Home
1009957
1010958
`
1011959

1012-
b, err := NewIntegrationTestBuilder(
1013-
IntegrationTestConfig{
1014-
T: t,
1015-
TxtarString: files,
1016-
},
1017-
).BuildE()
960+
b, err := TestE(t, files)
1018961

1019962
b.Assert(err, qt.IsNil)
1020963
b.AssertFileContent("public/index.html", `
@@ -1147,12 +1090,7 @@ Foo: {{ site.Params.foo }}|
11471090
11481091
11491092
`
1150-
b, err := NewIntegrationTestBuilder(
1151-
IntegrationTestConfig{
1152-
T: t,
1153-
TxtarString: files,
1154-
},
1155-
).BuildE()
1093+
b, err := TestE(t, files)
11561094

11571095
b.Assert(err, qt.IsNotNil)
11581096
b.Assert(err.Error(), qt.Contains, "invalid language configuration ")
@@ -1174,12 +1112,7 @@ weight = 1
11741112
11751113
11761114
`
1177-
b, err := NewIntegrationTestBuilder(
1178-
IntegrationTestConfig{
1179-
T: t,
1180-
TxtarString: files,
1181-
},
1182-
).BuildE()
1115+
b, err := TestE(t, files)
11831116

11841117
b.Assert(err, qt.IsNotNil)
11851118
b.Assert(err.Error(), qt.Contains, `defaultContentLanguage "sv" not found in languages configuration`)
@@ -1339,14 +1272,9 @@ func TestLoadConfigYamlEnvVar(t *testing.T) {
13391272
env = defaultEnv
13401273
}
13411274

1342-
b := NewIntegrationTestBuilder(
1343-
IntegrationTestConfig{
1344-
T: t,
1345-
TxtarString: files,
1346-
Environ: env,
1347-
BuildCfg: BuildCfg{SkipRender: true},
1348-
},
1349-
).Build()
1275+
b := Test(t, files, TestOptSkipRender(), TestOptWithConfig(func(c *IntegrationTestConfig) {
1276+
c.Environ = env
1277+
}))
13501278

13511279
outputs := b.H.Configs.Base.Outputs
13521280
if env == nil {

hugolib/content_map_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ Home: {{ .Title }}|
210210
211211
`
212212

213-
b := NewIntegrationTestBuilder(
214-
IntegrationTestConfig{
215-
T: c,
216-
TxtarString: files,
217-
}).Build()
213+
b := Test(c, files)
218214

219215
b.AssertFileContent("public/index.html", "Home: Integration Test|")
220216
}

hugolib/filesystems/basefs_test.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,9 @@ F1 text
296296

297297
os.Chdir(wd)
298298

299-
b := hugolib.NewIntegrationTestBuilder(
300-
hugolib.IntegrationTestConfig{
301-
T: t,
302-
TxtarString: files,
303-
NeedsOsFS: true,
304-
WorkingDir: tmpDir,
305-
},
306-
).Build()
299+
b := hugolib.Test(t, files, hugolib.TestOptOsFs(), hugolib.TestOptWithConfig(func(c *hugolib.IntegrationTestConfig) {
300+
c.WorkingDir = tmpDir
301+
}))
307302

308303
bfs := b.H.BaseFs
309304
watchFilenames := bfs.WatchFilenames()
@@ -432,13 +427,9 @@ title: "Foo"
432427
---
433428
`
434429

435-
b := hugolib.NewIntegrationTestBuilder(
436-
hugolib.IntegrationTestConfig{
437-
T: t,
438-
WorkingDir: tempDir,
439-
TxtarString: files,
440-
},
441-
).Build()
430+
b := hugolib.Test(t, files, hugolib.TestOptWithConfig(func(c *hugolib.IntegrationTestConfig) {
431+
c.WorkingDir = tempDir
432+
}))
442433

443434
abs1 := filepath.Join(tempDir, "content", "foo.md")
444435
rel, abs2, err := b.H.BaseFs.AbsProjectContentDir("foo.md")

hugolib/frontmatter_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ Ints: {{ printf "%T" .Params.ints }} {{ range .Params.ints }}Int: {{ fmt.Printf
3131
Mixed: {{ printf "%T" .Params.mixed }} {{ range .Params.mixed }}Mixed: {{ fmt.Printf "%[1]v (%[1]T)" . }}|{{ end }}
3232
Strings: {{ printf "%T" .Params.strings }} {{ range .Params.strings }}Strings: {{ fmt.Printf "%[1]v (%[1]T)" . }}|{{ end }}
3333
`
34-
b := NewIntegrationTestBuilder(
35-
IntegrationTestConfig{
36-
T: t,
37-
TxtarString: files,
38-
},
39-
)
40-
41-
b.Build()
34+
b := Test(t, files)
4235

4336
b.AssertFileContent("public/post/one/index.html", "Ints: []interface {} Int: 1 (uint64)|Int: 2 (uint64)|Int: 3 (uint64)|")
4437
b.AssertFileContent("public/post/one/index.html", "Mixed: []interface {} Mixed: 1 (string)|Mixed: 2 (uint64)|Mixed: 3 (uint64)|")

hugolib/hugo_smoke_test.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ title: Page
3838
Home: {{ .Title }}
3939
`
4040

41-
b := NewIntegrationTestBuilder(
42-
IntegrationTestConfig{
43-
T: t,
44-
TxtarString: files,
45-
// LogLevel: logg.LevelTrace,
46-
},
47-
).Build()
41+
b := Test(t, files)
4842

4943
b.Assert(b.H.Log.LoggCount(logg.LevelWarn), qt.Equals, 0)
5044
b.AssertFileContent("public/index.html", `Hello`)
@@ -508,13 +502,7 @@ Content Tag 1.
508502
509503
`
510504

511-
b := NewIntegrationTestBuilder(IntegrationTestConfig{
512-
T: t,
513-
TxtarString: files,
514-
NeedsOsFS: true,
515-
// Verbose: true,
516-
// LogLevel: logg.LevelTrace,
517-
}).Build()
505+
b := Test(t, files, TestOptOsFs())
518506

519507
b.AssertFileContent("public/en/index.html",
520508
"Home: en|home|/en/|Home in English|<p>Home Content.</p>\n|HTML",
@@ -751,11 +739,7 @@ The content.
751739

752740
// This is just a test to verify that BenchmarkBaseline is working as intended.
753741
func TestBenchmarkBaseline(t *testing.T) {
754-
cfg := IntegrationTestConfig{
755-
T: t,
756-
TxtarString: benchmarkBaselineFiles(true),
757-
}
758-
b := NewIntegrationTestBuilder(cfg).Build()
742+
b := Test(t, benchmarkBaselineFiles(true))
759743

760744
b.Assert(len(b.H.Sites), qt.Equals, 4)
761745
b.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 161)

0 commit comments

Comments
 (0)