diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-02-28 09:12:41 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-02-28 13:38:12 +0100 |
commit | a322282e70c2935c79f9c0f5c593bfdd032eb964 (patch) | |
tree | e70177f71b79c3e1212b5b3584d1a68272a7c3dd /hugolib/integrationtest_builder.go | |
parent | 6bc0d745a5897b70a9356035f959ee0310e83fc9 (diff) | |
download | hugo-a322282e70c2935c79f9c0f5c593bfdd032eb964.tar.gz hugo-a322282e70c2935c79f9c0f5c593bfdd032eb964.zip |
Fix single mount rename panic
Fixes #12141
Diffstat (limited to 'hugolib/integrationtest_builder.go')
-rw-r--r-- | hugolib/integrationtest_builder.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go index acbc093ba..642bac7ab 100644 --- a/hugolib/integrationtest_builder.go +++ b/hugolib/integrationtest_builder.go @@ -282,7 +282,7 @@ func (s *IntegrationTestBuilder) AssertPublishDir(matches ...string) { func (s *IntegrationTestBuilder) AssertFs(fs afero.Fs, matches ...string) { s.Helper() var buff bytes.Buffer - helpers.PrintFs(fs, "", &buff) + s.Assert(s.printAndCheckFs(fs, "", &buff), qt.IsNil) printFsLines := strings.Split(buff.String(), "\n") sort.Strings(printFsLines) content := strings.TrimSpace((strings.Join(printFsLines, "\n"))) @@ -305,6 +305,34 @@ func (s *IntegrationTestBuilder) AssertFs(fs afero.Fs, matches ...string) { } } +func (s *IntegrationTestBuilder) printAndCheckFs(fs afero.Fs, path string, w io.Writer) error { + if fs == nil { + return nil + } + + return afero.Walk(fs, path, func(path string, info os.FileInfo, err error) error { + if err != nil { + return fmt.Errorf("error: path %q: %s", path, err) + } + path = filepath.ToSlash(path) + if path == "" { + path = "." + } + if !info.IsDir() { + f, err := fs.Open(path) + if err != nil { + return fmt.Errorf("error: path %q: %s", path, err) + } + defer f.Close() + // This will panic if the file is a directory. + var buf [1]byte + io.ReadFull(f, buf[:]) + } + fmt.Fprintln(w, path, info.IsDir()) + return nil + }) +} + func (s *IntegrationTestBuilder) AssertFileExists(filename string, b bool) { checker := qt.IsNil if !b { |