summaryrefslogtreecommitdiffstats
path: root/hugolib
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
parentb08193971a821fc27e549a73120c15e5e5186775 (diff)
Rework the Destination filesystem to make --renderStaticToDisk work
See #9626
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/config.go3
-rw-r--r--hugolib/filesystems/basefs.go24
-rw-r--r--hugolib/filesystems/basefs_test.go17
-rw-r--r--hugolib/hugo_modules_test.go69
-rw-r--r--hugolib/hugo_sites.go2
-rw-r--r--hugolib/hugo_sites_build.go6
-rw-r--r--hugolib/hugo_sites_build_test.go22
-rw-r--r--hugolib/image_test.go4
-rw-r--r--hugolib/integrationtest_builder.go22
-rw-r--r--hugolib/language_content_dir_test.go22
-rw-r--r--hugolib/minify_publisher_test.go2
-rw-r--r--hugolib/mount_filters_test.go4
-rw-r--r--hugolib/page_test.go16
-rw-r--r--hugolib/pagebundler_test.go75
-rw-r--r--hugolib/paths/paths.go18
-rw-r--r--hugolib/paths/paths_test.go2
-rw-r--r--hugolib/resource_chain_test.go2
-rw-r--r--hugolib/robotstxt_test.go2
-rw-r--r--hugolib/rss_test.go2
-rw-r--r--hugolib/shortcode_test.go4
-rw-r--r--hugolib/site_output_test.go10
-rw-r--r--hugolib/site_test.go4
-rw-r--r--hugolib/site_url_test.go4
-rw-r--r--hugolib/sitemap_test.go2
-rw-r--r--hugolib/testhelpers_test.go31
25 files changed, 172 insertions, 197 deletions
diff --git a/hugolib/config.go b/hugolib/config.go
index b2479cbfe..5d2c6ddf7 100644
--- a/hugolib/config.go
+++ b/hugolib/config.go
@@ -35,7 +35,6 @@ import (
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/hugo"
- "github.com/gohugoio/hugo/hugolib/paths"
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/modules"
"github.com/pkg/errors"
@@ -359,7 +358,7 @@ func (l configLoader) collectModules(modConfig modules.Config, v1 config.Provide
workingDir = v1.GetString("workingDir")
}
- themesDir := paths.AbsPathify(l.WorkingDir, v1.GetString("themesDir"))
+ themesDir := cpaths.AbsPathify(l.WorkingDir, v1.GetString("themesDir"))
var ignoreVendor glob.Glob
if s := v1.GetString("ignoreVendorPaths"); s != "" {
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go
index 0290d2e1c..693dd8575 100644
--- a/hugolib/filesystems/basefs.go
+++ b/hugolib/filesystems/basefs.go
@@ -38,8 +38,8 @@ import (
"github.com/gohugoio/hugo/modules"
+ hpaths "github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/hugofs"
-
"github.com/gohugoio/hugo/hugolib/paths"
"github.com/spf13/afero"
)
@@ -68,12 +68,12 @@ type BaseFs struct {
// This usually maps to /my-project/public.
PublishFs afero.Fs
- // A read-only filesystem starting from the project workDir.
- WorkDir afero.Fs
-
// The filesystem used for renderStaticToDisk.
PublishFsStatic afero.Fs
+ // A read-only filesystem starting from the project workDir.
+ WorkDir afero.Fs
+
theBigFs *filesystemsCollector
// Locks.
@@ -434,21 +434,13 @@ func NewBase(p *paths.Paths, logger loggers.Logger, options ...func(*BaseFs) err
logger = loggers.NewWarningLogger()
}
- // Make sure we always have the /public folder ready to use.
- if err := fs.Destination.MkdirAll(p.AbsPublishDir, 0777); err != nil && !os.IsExist(err) {
- return nil, err
- }
-
- publishFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Destination, p.AbsPublishDir))
+ publishFs := hugofs.NewBaseFileDecorator(fs.PublishDir)
sourceFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Source, p.WorkingDir))
- publishFsStatic := afero.NewBasePathFs(fs.Source, p.AbsPublishDir)
-
- // Same as sourceFs, but no decoration. This is what's used by os.ReadDir etc.
- workDir := afero.NewBasePathFs(afero.NewReadOnlyFs(fs.Source), p.WorkingDir)
+ publishFsStatic := fs.PublishDirStatic
b := &BaseFs{
SourceFs: sourceFs,
- WorkDir: workDir,
+ WorkDir: fs.WorkingDirReadOnly,
PublishFs: publishFs,
PublishFsStatic: publishFsStatic,
buildMu: lockedfile.MutexAt(filepath.Join(p.WorkingDir, lockFileBuild)),
@@ -638,7 +630,7 @@ func (b *sourceFilesystemsBuilder) createModFs(
if filepath.IsAbs(path) {
return "", path
}
- return md.dir, paths.AbsPathify(md.dir, path)
+ return md.dir, hpaths.AbsPathify(md.dir, path)
}
for i, mount := range md.Mounts() {
diff --git a/hugolib/filesystems/basefs_test.go b/hugolib/filesystems/basefs_test.go
index 32d1eef71..a729e63b1 100644
--- a/hugolib/filesystems/basefs_test.go
+++ b/hugolib/filesystems/basefs_test.go
@@ -75,7 +75,7 @@ func initConfig(fs afero.Fs, cfg config.Provider) error {
func TestNewBaseFs(t *testing.T) {
c := qt.New(t)
- v := config.New()
+ v := config.NewWithTestDefaults()
fs := hugofs.NewMem(v)
@@ -181,7 +181,7 @@ theme = ["atheme"]
}
func createConfig() config.Provider {
- v := config.New()
+ v := config.NewWithTestDefaults()
v.Set("contentDir", "mycontent")
v.Set("i18nDir", "myi18n")
v.Set("staticDir", "mystatic")
@@ -219,22 +219,19 @@ func TestNewBaseFsEmpty(t *testing.T) {
func TestRealDirs(t *testing.T) {
c := qt.New(t)
v := createConfig()
+ root, themesDir := t.TempDir(), t.TempDir()
+ v.Set("workingDir", root)
+ v.Set("themesDir", themesDir)
+ v.Set("theme", "mytheme")
+
fs := hugofs.NewDefault(v)
sfs := fs.Source
- root, err := afero.TempDir(sfs, "", "realdir")
- c.Assert(err, qt.IsNil)
- themesDir, err := afero.TempDir(sfs, "", "themesDir")
- c.Assert(err, qt.IsNil)
defer func() {
os.RemoveAll(root)
os.RemoveAll(themesDir)
}()
- v.Set("workingDir", root)
- v.Set("themesDir", themesDir)
- v.Set("theme", "mytheme")
-
c.Assert(sfs.MkdirAll(filepath.Join(root, "myassets", "scss", "sf1"), 0755), qt.IsNil)
c.Assert(sfs.MkdirAll(filepath.Join(root, "myassets", "scss", "sf2"), 0755), qt.IsNil)
c.Assert(sfs.MkdirAll(filepath.Join(themesDir, "mytheme", "assets", "scss", "sf2"), 0755), qt.IsNil)
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)
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index 09e1a331a..d67652dab 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -597,7 +597,7 @@ func (h *HugoSites) reset(config *BuildCfg) {
if config.ResetState {
for i, s := range h.Sites {
h.Sites[i] = s.reset()
- if r, ok := s.Fs.Destination.(hugofs.Reseter); ok {
+ if r, ok := s.Fs.PublishDir.(hugofs.Reseter); ok {
r.Reset()
}
}
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index bf52277a9..4616b6dbb 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -496,9 +496,9 @@ func (h *HugoSites) writeBuildStats() error {
return err
}
- // Write to the destination, too, if a mem fs is in play.
- if h.Fs.Source != hugofs.Os {
- if err := afero.WriteFile(h.Fs.Destination, filename, js, 0666); err != nil {
+ // Write to the destination as well if it's a in-memory fs.
+ if !hugofs.IsOsFs(h.Fs.Source) {
+ if err := afero.WriteFile(h.Fs.WorkingDirWritable, filename, js, 0666); err != nil {
return err
}
}
diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go
index d71e7c7a4..4a629eedd 100644
--- a/hugolib/hugo_sites_build_test.go
+++ b/hugolib/hugo_sites_build_test.go
@@ -489,7 +489,7 @@ func TestMultiSitesRebuild(t *testing.T) {
c.Assert(enSite.RegularPages()[0].Title(), qt.Equals, "new_en_2")
c.Assert(enSite.RegularPages()[1].Title(), qt.Equals, "new_en_1")
- rendered := readDestination(t, fs, "public/en/new1/index.html")
+ rendered := readWorkingDir(t, fs, "public/en/new1/index.html")
c.Assert(strings.Contains(rendered, "new_en_1"), qt.Equals, true)
},
},
@@ -503,7 +503,7 @@ func TestMultiSitesRebuild(t *testing.T) {
[]fsnotify.Event{{Name: filepath.FromSlash("content/sect/doc1.en.md"), Op: fsnotify.Write}},
func(t *testing.T) {
c.Assert(len(enSite.RegularPages()), qt.Equals, 6)
- doc1 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
+ doc1 := readWorkingDir(t, fs, "public/en/sect/doc1-slug/index.html")
c.Assert(strings.Contains(doc1, "CHANGED"), qt.Equals, true)
},
},
@@ -521,7 +521,7 @@ func TestMultiSitesRebuild(t *testing.T) {
func(t *testing.T) {
c.Assert(len(enSite.RegularPages()), qt.Equals, 6, qt.Commentf("Rename"))
c.Assert(enSite.RegularPages()[1].Title(), qt.Equals, "new_en_1")
- rendered := readDestination(t, fs, "public/en/new1renamed/index.html")
+ rendered := readWorkingDir(t, fs, "public/en/new1renamed/index.html")
c.Assert(rendered, qt.Contains, "new_en_1")
},
},
@@ -538,7 +538,7 @@ func TestMultiSitesRebuild(t *testing.T) {
c.Assert(len(enSite.RegularPages()), qt.Equals, 6)
c.Assert(len(enSite.AllPages()), qt.Equals, 34)
c.Assert(len(frSite.RegularPages()), qt.Equals, 5)
- doc1 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
+ doc1 := readWorkingDir(t, fs, "public/en/sect/doc1-slug/index.html")
c.Assert(strings.Contains(doc1, "Template Changed"), qt.Equals, true)
},
},
@@ -555,9 +555,9 @@ func TestMultiSitesRebuild(t *testing.T) {
c.Assert(len(enSite.RegularPages()), qt.Equals, 6)
c.Assert(len(enSite.AllPages()), qt.Equals, 34)
c.Assert(len(frSite.RegularPages()), qt.Equals, 5)
- docEn := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
+ docEn := readWorkingDir(t, fs, "public/en/sect/doc1-slug/index.html")
c.Assert(strings.Contains(docEn, "Hello"), qt.Equals, true)
- docFr := readDestination(t, fs, "public/fr/sect/doc1/index.html")
+ docFr := readWorkingDir(t, fs, "public/fr/sect/doc1/index.html")
c.Assert(strings.Contains(docFr, "Salut"), qt.Equals, true)
homeEn := enSite.getPage(page.KindHome)
@@ -700,7 +700,7 @@ END
func checkContent(s *sitesBuilder, filename string, matches ...string) {
s.T.Helper()
- content := readDestination(s.T, s.Fs, filename)
+ content := readWorkingDir(s.T, s.Fs, filename)
for _, match := range matches {
if !strings.Contains(content, match) {
s.Fatalf("No match for\n%q\nin content for %s\n%q\nDiff:\n%s", match, filename, content, htesting.DiffStrings(content, match))
@@ -1170,13 +1170,13 @@ func writeToFs(t testing.TB, fs afero.Fs, filename, content string) {
}
}
-func readDestination(t testing.TB, fs *hugofs.Fs, filename string) string {
+func readWorkingDir(t testing.TB, fs *hugofs.Fs, filename string) string {
t.Helper()
- return readFileFromFs(t, fs.Destination, filename)
+ return readFileFromFs(t, fs.WorkingDirReadOnly, filename)
}
-func destinationExists(fs *hugofs.Fs, filename string) bool {
- b, err := helpers.Exists(filename, fs.Destination)
+func workingDirExists(fs *hugofs.Fs, filename string) bool {
+ b, err := helpers.Exists(filename, fs.WorkingDirReadOnly)
if err != nil {
panic(err)
}
diff --git a/hugolib/image_test.go b/hugolib/image_test.go
index 5f056e4ad..ac18b9423 100644
--- a/hugolib/image_test.go
+++ b/hugolib/image_test.go
@@ -38,7 +38,7 @@ func TestImageOps(t *testing.T) {
defer clean()
newBuilder := func(timeout any) *sitesBuilder {
- v := config.New()
+ v := config.NewWithTestDefaults()
v.Set("workingDir", workDir)
v.Set("baseURL", "https://example.org")
v.Set("timeout", timeout)
@@ -141,7 +141,7 @@ IMG SHORTCODE: /images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_129x239_r
assertImages := func() {
b.Helper()
- b.AssertFileContent(filepath.Join(workDir, "public/index.html"), imgExpect)
+ b.AssertFileContent("public/index.html", imgExpect)
b.AssertImage(350, 219, "public/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_350x0_resize_q75_box.a86fe88d894e5db613f6aa8a80538fefc25b20fa24ba0d782c057adcef616f56.jpg")
b.AssertImage(129, 239, "public/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_129x239_resize_q75_box.jpg")
}
diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go
index d49e29763..e5c9a6856 100644
--- a/hugolib/integrationtest_builder.go
+++ b/hugolib/integrationtest_builder.go
@@ -47,6 +47,8 @@ func NewIntegrationTestBuilder(conf IntegrationTestConfig) *IntegrationTestBuild
if doClean {
c.Cleanup(clean)
}
+ } else if conf.WorkingDir == "" {
+ conf.WorkingDir = helpers.FilePathSeparator
}
return &IntegrationTestBuilder{
@@ -157,7 +159,7 @@ func (s *IntegrationTestBuilder) AssertDestinationExists(filename string, b bool
}
func (s *IntegrationTestBuilder) destinationExists(filename string) bool {
- b, err := helpers.Exists(filename, s.fs.Destination)
+ b, err := helpers.Exists(filename, s.fs.PublishDir)
if err != nil {
panic(err)
}
@@ -258,11 +260,7 @@ func (s *IntegrationTestBuilder) RenameFile(old, new string) *IntegrationTestBui
func (s *IntegrationTestBuilder) FileContent(filename string) string {
s.Helper()
- filename = filepath.FromSlash(filename)
- if !strings.HasPrefix(filename, s.Cfg.WorkingDir) {
- filename = filepath.Join(s.Cfg.WorkingDir, filename)
- }
- return s.readDestination(s, s.fs, filename)
+ return s.readWorkingDir(s, s.fs, filepath.FromSlash(filename))
}
func (s *IntegrationTestBuilder) initBuilder() {
@@ -280,8 +278,6 @@ func (s *IntegrationTestBuilder) initBuilder() {
logger := loggers.NewBasicLoggerForWriter(s.Cfg.LogLevel, &s.logBuff)
- fs := hugofs.NewFrom(afs, config.New())
-
for _, f := range s.data.Files {
filename := filepath.Join(s.Cfg.WorkingDir, f.Name)
s.Assert(afs.MkdirAll(filepath.Dir(filename), 0777), qt.IsNil)
@@ -301,10 +297,12 @@ func (s *IntegrationTestBuilder) initBuilder() {
},
)
- s.Assert(err, qt.IsNil)
-
cfg.Set("workingDir", s.Cfg.WorkingDir)
+ fs := hugofs.NewFrom(afs, cfg)
+
+ s.Assert(err, qt.IsNil)
+
depsCfg := deps.DepsCfg{Cfg: cfg, Fs: fs, Running: s.Cfg.Running, Logger: logger}
sites, err := NewHugoSites(depsCfg)
s.Assert(err, qt.IsNil)
@@ -400,9 +398,9 @@ func (s *IntegrationTestBuilder) changeEvents() []fsnotify.Event {
return events
}
-func (s *IntegrationTestBuilder) readDestination(t testing.TB, fs *hugofs.Fs, filename string) string {
+func (s *IntegrationTestBuilder) readWorkingDir(t testing.TB, fs *hugofs.Fs, filename string) string {
t.Helper()
- return s.readFileFromFs(t, fs.Destination, filename)
+ return s.readFileFromFs(t, fs.WorkingDirReadOnly, filename)
}
func (s *IntegrationTestBuilder) readFileFromFs(t testing.TB, fs afero.Fs, filename string) string {
diff --git a/hugolib/language_content_dir_test.go b/hugolib/language_content_dir_test.go
index 541878220..57cdab67b 100644
--- a/hugolib/language_content_dir_test.go
+++ b/hugolib/language_content_dir_test.go
@@ -224,8 +224,8 @@ Content.
nnSite := b.H.Sites[1]
svSite := b.H.Sites[2]
- b.AssertFileContent("/my/project/public/en/mystatic/file1.yaml", "en")
- b.AssertFileContent("/my/project/public/nn/mystatic/file1.yaml", "nn")
+ b.AssertFileContent("public/en/mystatic/file1.yaml", "en")
+ b.AssertFileContent("public/nn/mystatic/file1.yaml", "nn")
// dumpPages(nnSite.RegularPages()...)
@@ -300,16 +300,16 @@ Content.
c.Assert(len(bundleSv.Resources()), qt.Equals, 4)
c.Assert(len(bundleEn.Resources()), qt.Equals, 4)
- b.AssertFileContent("/my/project/public/en/sect/mybundle/index.html", "image/png: /en/sect/mybundle/logo.png")
- b.AssertFileContent("/my/project/public/nn/sect/mybundle/index.html", "image/png: /nn/sect/mybundle/logo.png")
- b.AssertFileContent("/my/project/public/sv/sect/mybundle/index.html", "image/png: /sv/sect/mybundle/logo.png")
+ b.AssertFileContent("public/en/sect/mybundle/index.html", "image/png: /en/sect/mybundle/logo.png")
+ b.AssertFileContent("public/nn/sect/mybundle/index.html", "image/png: /nn/sect/mybundle/logo.png")
+ b.AssertFileContent("public/sv/sect/mybundle/index.html", "image/png: /sv/sect/mybundle/logo.png")
- b.AssertFileContent("/my/project/public/sv/sect/mybundle/featured.png", "PNG Data for sv")
- b.AssertFileContent("/my/project/public/nn/sect/mybundle/featured.png", "PNG Data for nn")
- b.AssertFileContent("/my/project/public/en/sect/mybundle/featured.png", "PNG Data for en")
- b.AssertFileContent("/my/project/public/en/sect/mybundle/logo.png", "PNG Data")
- b.AssertFileContent("/my/project/public/sv/sect/mybundle/logo.png", "PNG Data")
- b.AssertFileContent("/my/project/public/nn/sect/mybundle/logo.png", "PNG Data")
+ b.AssertFileContent("public/sv/sect/mybundle/featured.png", "PNG Data for sv")
+ b.AssertFileContent("public/nn/sect/mybundle/featured.png", "PNG Data for nn")
+ b.AssertFileContent("public/en/sect/mybundle/featured.png", "PNG Data for en")
+ b.AssertFileContent("public/en/sect/mybundle/logo.png", "PNG Data")
+ b.AssertFileContent("public/sv/sect/mybundle/logo.png", "PNG Data")
+ b.AssertFileContent("public/nn/sect/mybundle/logo.png", "PNG Data")
nnSect := nnSite.getPage(page.KindSection, "sect")
c.Assert(nnSect, qt.Not(qt.IsNil))
diff --git a/hugolib/minify_publisher_test.go b/hugolib/minify_publisher_test.go
index ef460efa2..03b46a5fe 100644
--- a/hugolib/minify_publisher_test.go
+++ b/hugolib/minify_publisher_test.go
@@ -22,7 +22,7 @@ import (
func TestMinifyPublisher(t *testing.T) {
t.Parallel()
- v := config.New()
+ v := config.NewWithTestDefaults()
v.Set("minify", true)
v.Set("baseURL", "https://example.org/")
diff --git a/hugolib/mount_filters_test.go b/hugolib/mount_filters_test.go
index 5f4157715..688cf2558 100644
--- a/hugolib/mount_filters_test.go
+++ b/hugolib/mount_filters_test.go
@@ -101,13 +101,13 @@ Resources: {{ resources.Match "**.js" }}
assertExists := func(name string, shouldExist bool) {
b.Helper()
- b.Assert(b.CheckExists(filepath.Join(workingDir, name)), qt.Equals, shouldExist)
+ b.Assert(b.CheckExists(name), qt.Equals, shouldExist)
}
assertExists("public/a/b/p1/index.html", true)
assertExists("public/a/c/p2/index.html", false)
- b.AssertFileContent(filepath.Join(workingDir, "public", "index.html"), `
+ b.AssertFileContent(filepath.Join("public", "index.html"), `
Data: map[mydata:map[b:map[b1:bval]]]:END
Template: false
Resource1: js/include.js:END
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index d29a4f865..c16754cd9 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -23,7 +23,6 @@ import (
"time"
"g