Skip to content

Commit

Permalink
Add a migration test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Feb 9, 2022
1 parent 215a715 commit f60714b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions hugolib/testhelpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"image/jpeg"
"io"
"io/fs"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -702,6 +703,34 @@ func (s *sitesBuilder) AssertFileContentFn(filename string, f func(s string) boo
}
}

// Helper to migrate tests to new format.
func (s *sitesBuilder) DumpTxtar() string {
var sb strings.Builder

skipRe := regexp.MustCompile(`^(public|resources|package-lock.json|go.sum)`)

afero.Walk(s.Fs.Source, s.workingDir, func(path string, info fs.FileInfo, err error) error {
rel := strings.TrimPrefix(path, s.workingDir+"/")
if skipRe.MatchString(rel) {
if info.IsDir() {
return filepath.SkipDir
}
return nil
}
if info == nil || info.IsDir() {
return nil
}
sb.WriteString(fmt.Sprintf("-- %s --\n", rel))
b, err := afero.ReadFile(s.Fs.Source, path)
s.Assert(err, qt.IsNil)
sb.WriteString(strings.TrimSpace(string(b)))
sb.WriteString("\n")
return nil
})

return sb.String()
}

func (s *sitesBuilder) AssertHome(matches ...string) {
s.AssertFileContent("public/index.html", matches...)
}
Expand Down

0 comments on commit f60714b

Please sign in to comment.