summaryrefslogtreecommitdiffstats
path: root/hugolib/hugo_modules_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-03-21 09:35:15 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-04-08 13:26:17 +0200
commitd070bdf10f14d233288f7318a4e9f7555f070a65 (patch)
treefff8d59f98bdab3027bb45c4e10ca88594332872 /hugolib/hugo_modules_test.go
parentb08193971a821fc27e549a73120c15e5e5186775 (diff)
Rework the Destination filesystem to make --renderStaticToDisk work
See #9626
Diffstat (limited to 'hugolib/hugo_modules_test.go')
-rw-r--r--hugolib/hugo_modules_test.go69
1 files changed, 34 insertions, 35 deletions
diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go
index eb6b7433b..358286495 100644
--- a/hugolib/hugo_modules_test.go
+++ b/hugolib/hugo_modules_test.go
@@ -59,13 +59,14 @@ path="github.com/gohugoio/hugoTestModule2"
return fmt.Sprintf(tomlConfig, workingDir, moduleOpts)
}
- newTestBuilder := func(t testing.TB, moduleOpts string) (*sitesBuilder, func()) {
+ newTestBuilder := func(t testing.TB, moduleOpts string) *sitesBuilder {
b := newTestSitesBuilder(t)
- tempDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-variants")
- b.Assert(err, qt.IsNil)
+ tempDir := t.TempDir()
workingDir := filepath.Join(tempDir, "myhugosite")
b.Assert(os.MkdirAll(workingDir, 0777), qt.IsNil)
- b.Fs = hugofs.NewDefault(config.New())
+ cfg := config.NewWithTestDefaults()
+ cfg.Set("workingDir", workingDir)
+ b.Fs = hugofs.NewDefault(cfg)
b.WithWorkingDir(workingDir).WithConfigFile("toml", createConfig(workingDir, moduleOpts))
b.WithTemplates(
"index.html", `
@@ -92,22 +93,18 @@ github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877 h1:WLM2bQ
github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877/go.mod h1:CBFZS3khIAXKxReMwq0le8sEl/D8hcXmixlOHVv+Gd0=
`)
- return b, clean
+ return b
}
t.Run("Target in subfolder", func(t *testing.T) {
- b, clean := newTestBuilder(t, "ignoreImports=true")
- defer clean()
-
+ b := newTestBuilder(t, "ignoreImports=true")
b.Build(BuildCfg{})
b.AssertFileContent("public/p1/index.html", `<p>Page|https://bep.is|Title: |Text: A link|END</p>`)
})
t.Run("Ignore config", func(t *testing.T) {
- b, clean := newTestBuilder(t, "ignoreConfig=true")
- defer clean()
-
+ b := newTestBuilder(t, "ignoreConfig=true")
b.Build(BuildCfg{})
b.AssertFileContent("public/index.html", `
@@ -117,9 +114,7 @@ JS imported in module: |
})
t.Run("Ignore imports", func(t *testing.T) {
- b, clean := newTestBuilder(t, "ignoreImports=true")
- defer clean()
-
+ b := newTestBuilder(t, "ignoreImports=true")
b.Build(BuildCfg{})
b.AssertFileContent("public/index.html", `
@@ -129,8 +124,7 @@ JS imported in module: |
})
t.Run("Create package.json", func(t *testing.T) {
- b, clean := newTestBuilder(t, "")
- defer clean()
+ b := newTestBuilder(t, "")
b.WithSourceFile("package.json", `{
"name": "mypack",
@@ -205,8 +199,7 @@ JS imported in module: |
})
t.Run("Create package.json, no default", func(t *testing.T) {
- b, clean := newTestBuilder(t, "")
- defer clean()
+ b := newTestBuilder(t, "")
const origPackageJSON = `{
"name": "mypack",
@@ -268,8 +261,7 @@ JS imported in module: |
})
t.Run("Create package.json, no default, no package.json", func(t *testing.T) {
- b, clean := newTestBuilder(t, "")
- defer clean()
+ b := newTestBuilder(t, "")
b.Build(BuildCfg{})
b.Assert(npm.Pack(b.H.BaseFs.SourceFs, b.H.BaseFs.Assets.Dirs), qt.IsNil)
@@ -333,12 +325,13 @@ func TestHugoModulesMatrix(t *testing.T) {
for _, m := range testmods[:2] {
c := qt.New(t)
- v := config.New()
-
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-test")
c.Assert(err, qt.IsNil)
defer clean()
+ v := config.NewWithTestDefaults()
+ v.Set("workingDir", workingDir)
+
configTemplate := `
baseURL = "https://example.com"
title = "My Modular Site"
@@ -670,13 +663,14 @@ func TestModulesSymlinks(t *testing.T) {
}()
c := qt.New(t)
+ workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-mod-sym")
+ c.Assert(err, qt.IsNil)
+
// We need to use the OS fs for this.
- cfg := config.New()
+ cfg := config.NewWithTestDefaults()
+ cfg.Set("workingDir", workingDir)
fs := hugofs.NewFrom(hugofs.Os, cfg)
- workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-mod-sym")
- c.Assert(err, qt.IsNil)
-
defer clean()
const homeTemplate = `
@@ -694,9 +688,9 @@ Data: {{ .Site.Data }}
}
// Create project dirs and files.
- createDirsAndFiles(workDir)
+ createDirsAndFiles(workingDir)
// Create one module inside the default themes folder.
- themeDir := filepath.Join(workDir, "themes", "mymod")
+ themeDir := filepath.Join(workingDir, "themes", "mymod")
createDirsAndFiles(themeDir)
createSymlinks := func(baseDir, id string) {
@@ -711,7 +705,7 @@ Data: {{ .Site.Data }}
}
}
- createSymlinks(workDir, "project")
+ createSymlinks(workingDir, "project")
createSymlinks(themeDir, "mod")
config := `
@@ -729,12 +723,12 @@ weight = 2
`
- b := newTestSitesBuilder(t).WithNothingAdded().WithWorkingDir(workDir)
+ b := newTestSitesBuilder(t).WithNothingAdded().WithWorkingDir(workingDir)
b.WithLogger(loggers.NewErrorLogger())
b.Fs = fs
b.WithConfigFile("toml", config)
- c.Assert(os.Chdir(workDir), qt.IsNil)
+ c.Assert(os.Chdir(workingDir), qt.IsNil)
b.Build(BuildCfg{})
@@ -846,7 +840,10 @@ workingDir = %q
b := newTestSitesBuilder(t).Running()
- b.Fs = hugofs.NewDefault(config.New())
+ cfg := config.NewWithTestDefaults()
+ cfg.Set("workingDir", workingDir)
+
+ b.Fs = hugofs.NewDefault(cfg)
b.WithWorkingDir(workingDir).WithConfigFile("toml", tomlConfig)
b.WithTemplatesAdded("index.html", `
@@ -968,7 +965,9 @@ workingDir = %q
b := newTestSitesBuilder(c).Running()
- b.Fs = hugofs.NewDefault(config.New())
+ cfg := config.NewWithTestDefaults()
+ cfg.Set("workingDir", workingDir)
+ b.Fs = hugofs.NewDefault(cfg)
os.MkdirAll(filepath.Join(workingDir, "content", "blog"), 0777)
@@ -1067,7 +1066,7 @@ func TestSiteWithGoModButNoModules(t *testing.T) {
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-no-mod")
c.Assert(err, qt.IsNil)
- cfg := config.New()
+ cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", workDir)
fs := hugofs.NewFrom(hugofs.Os, cfg)
@@ -1093,7 +1092,7 @@ func TestModuleAbsMount(t *testing.T) {
absContentDir, clean2, err := htesting.CreateTempDir(hugofs.Os, "hugo-content")
c.Assert(err, qt.IsNil)
- cfg := config.New()
+ cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", workDir)
fs := hugofs.NewFrom(hugofs.Os, cfg)