diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-03-21 09:35:15 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-04-08 13:26:17 +0200 |
commit | d070bdf10f14d233288f7318a4e9f7555f070a65 (patch) | |
tree | fff8d59f98bdab3027bb45c4e10ca88594332872 /hugolib/testhelpers_test.go | |
parent | b08193971a821fc27e549a73120c15e5e5186775 (diff) | |
download | hugo-d070bdf10f14d233288f7318a4e9f7555f070a65.tar.gz hugo-d070bdf10f14d233288f7318a4e9f7555f070a65.zip |
Rework the Destination filesystem to make --renderStaticToDisk work
See #9626
Diffstat (limited to 'hugolib/testhelpers_test.go')
-rw-r--r-- | hugolib/testhelpers_test.go | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 7b259a2d4..6c1aa6fd0 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -114,7 +114,7 @@ type filenameContent struct { } func newTestSitesBuilder(t testing.TB) *sitesBuilder { - v := config.New() + v := config.NewWithTestDefaults() fs := hugofs.NewMem(v) litterOptions := litter.Options{ @@ -475,6 +475,9 @@ func (s *sitesBuilder) CreateSites() *sitesBuilder { s.Fatalf("Failed to create sites: %s", err) } + s.Assert(s.Fs.PublishDir, qt.IsNotNil) + s.Assert(s.Fs.WorkingDirReadOnly, qt.IsNotNil) + return s } @@ -536,7 +539,7 @@ func (s *sitesBuilder) CreateSitesE() error { return errors.Wrap(err, "failed to load config") } - s.Fs.Destination = hugofs.NewCreateCountingFs(s.Fs.Destination) + s.Fs.PublishDir = hugofs.NewCreateCountingFs(s.Fs.PublishDir) depsCfg := s.depsCfg depsCfg.Fs = s.Fs @@ -759,8 +762,7 @@ func (s *sitesBuilder) AssertFileDoesNotExist(filename string) { } func (s *sitesBuilder) AssertImage(width, height int, filename string) { - filename = filepath.Join(s.workingDir, filename) - f, err := s.Fs.Destination.Open(filename) + f, err := s.Fs.WorkingDirReadOnly.Open(filename) s.Assert(err, qt.IsNil) defer f.Close() cfg, err := jpeg.DecodeConfig(f) @@ -771,17 +773,14 @@ func (s *sitesBuilder) AssertImage(width, height int, filename string) { func (s *sitesBuilder) AssertNoDuplicateWrites() { s.Helper() - d := s.Fs.Destination.(hugofs.DuplicatesReporter) + d := s.Fs.PublishDir.(hugofs.DuplicatesReporter) s.Assert(d.ReportDuplicates(), qt.Equals, "") } func (s *sitesBuilder) FileContent(filename string) string { - s.T.Helper() + s.Helper() filename = filepath.FromSlash(filename) - if !strings.HasPrefix(filename, s.workingDir) { - filename = filepath.Join(s.workingDir, filename) - } - return readDestination(s.T, s.Fs, filename) + return readWorkingDir(s.T, s.Fs, filename) } func (s *sitesBuilder) AssertObject(expected string, object any) { @@ -797,7 +796,7 @@ func (s *sitesBuilder) AssertObject(expected string, object any) { } func (s *sitesBuilder) AssertFileContentRe(filename string, matches ...string) { - content := readDestination(s.T, s.Fs, filename) + content := readWorkingDir(s.T, s.Fs, filename) for _, match := range matches { r := regexp.MustCompile("(?s)" + match) if !r.MatchString(content) { @@ -807,7 +806,7 @@ func (s *sitesBuilder) AssertFileContentRe(filename string, matches ...string) { } func (s *sitesBuilder) CheckExists(filename string) bool { - return destinationExists(s.Fs, filepath.Clean(filename)) + return workingDirExists(s.Fs, filepath.Clean(filename)) } func (s *sitesBuilder) GetPage(ref string) page.Page { @@ -848,7 +847,7 @@ type testHelper struct { func (th testHelper) assertFileContent(filename string, matches ...string) { th.Helper() filename = th.replaceDefaultContentLanguageValue(filename) - content := readDestination(th, th.Fs, filename) + content := readWorkingDir(th, th.Fs, filename) for _, match := range matches { match = th.replaceDefaultContentLanguageValue(match) th.Assert(strings.Contains(content, match), qt.Equals, true, qt.Commentf(match+" not in: \n"+content)) @@ -857,7 +856,7 @@ func (th testHelper) assertFileContent(filename string, matches ...string) { func (th testHelper) assertFileContentRegexp(filename string, matches ...string) { filename = th.replaceDefaultContentLanguageValue(filename) - content := readDestination(th, th.Fs, filename) + content := readWorkingDir(th, th.Fs, filename) for _, match := range matches { match = th.replaceDefaultContentLanguageValue(match) r := regexp.MustCompile(match) @@ -870,7 +869,7 @@ func (th testHelper) assertFileContentRegexp(filename string, matches ...string) } func (th testHelper) assertFileNotExist(filename string) { - exists, err := helpers.Exists(filename, th.Fs.Destination) + exists, err := helpers.Exists(filename, th.Fs.PublishDir) th.Assert(err, qt.IsNil) th.Assert(exists, qt.Equals, false) } @@ -892,7 +891,7 @@ func loadTestConfig(fs afero.Fs, withConfig ...func(cfg config.Provider) error) func newTestCfgBasic() (config.Provider, *hugofs.Fs) { mm := afero.NewMemMapFs() - v := config.New() + v := config.NewWithTestDefaults() v.Set("defaultContentLanguageInSubdir", true) fs := hugofs.NewFrom(hugofs.NewBaseFileDecorator(mm), v) |