summaryrefslogtreecommitdiffstats
path: root/hugolib/integrationtest_builder.go
diff options
context:
space:
mode:
Diffstat (limited to 'hugolib/integrationtest_builder.go')
-rw-r--r--hugolib/integrationtest_builder.go30
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 {