mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 14:10:31 +03:00
Rework the Destination filesystem to make --renderStaticToDisk work
See #9626
This commit is contained in:
parent
b08193971a
commit
d070bdf10f
75 changed files with 651 additions and 566 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue