summaryrefslogtreecommitdiffstats
path: root/hugolib/testhelpers_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'hugolib/testhelpers_test.go')
-rw-r--r--hugolib/testhelpers_test.go128
1 files changed, 7 insertions, 121 deletions
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go
index cf054897d..e2bd57f3c 100644
--- a/hugolib/testhelpers_test.go
+++ b/hugolib/testhelpers_test.go
@@ -11,14 +11,10 @@ import (
"os"
"path/filepath"
"regexp"
- "runtime"
- "sort"
- "strconv"
"strings"
"testing"
"text/template"
"time"
- "unicode/utf8"
"github.com/gohugoio/hugo/config/allconfig"
"github.com/gohugoio/hugo/config/security"
@@ -117,6 +113,7 @@ type filenameContent struct {
func newTestSitesBuilder(t testing.TB) *sitesBuilder {
v := config.New()
v.Set("publishDir", "public")
+ v.Set("disableLiveReload", true)
fs := hugofs.NewFromOld(afero.NewMemMapFs(), v)
litterOptions := litter.Options{
@@ -718,6 +715,9 @@ func (s *sitesBuilder) DumpTxtar() string {
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 {
+ if err != nil {
+ return err
+ }
rel := strings.TrimPrefix(path, s.workingDir+"/")
if skipRe.MatchString(rel) {
if info.IsDir() {
@@ -754,7 +754,7 @@ func (s *sitesBuilder) AssertFileContent(filename string, matches ...string) {
continue
}
if !strings.Contains(content, match) {
- s.Fatalf("No match for \n%q in content\n%q\nin file %s\n", match, content, filename)
+ s.Assert(content, qt.Contains, match, qt.Commentf(match+" not in: \n"+content))
}
}
}
@@ -819,13 +819,13 @@ func (s *sitesBuilder) CheckExists(filename string) bool {
}
func (s *sitesBuilder) GetPage(ref string) page.Page {
- p, err := s.H.Sites[0].getPageNew(nil, ref)
+ p, err := s.H.Sites[0].getPage(nil, ref)
s.Assert(err, qt.IsNil)
return p
}
func (s *sitesBuilder) GetPageRel(p page.Page, ref string) page.Page {
- p, err := s.H.Sites[0].getPageNew(p, ref)
+ p, err := s.H.Sites[0].getPage(p, ref)
s.Assert(err, qt.IsNil)
return p
}
@@ -902,17 +902,6 @@ func loadTestConfigFromProvider(cfg config.Provider) (*allconfig.Configs, error)
return res, err
}
-func newTestCfgBasic() (config.Provider, *hugofs.Fs) {
- mm := afero.NewMemMapFs()
- v := config.New()
- v.Set("publishDir", "public")
- v.Set("defaultContentLanguageInSubdir", true)
-
- fs := hugofs.NewFromOld(hugofs.NewBaseFileDecorator(mm), v)
-
- return v, fs
-}
-
func newTestCfg(withConfig ...func(cfg config.Provider) error) (config.Provider, *hugofs.Fs) {
mm := afero.NewMemMapFs()
cfg := config.New()
@@ -1011,106 +1000,3 @@ func content(c resource.ContentProvider) string {
}
return ccs
}
-
-func pagesToString(pages ...page.Page) string {
- var paths []string
- for _, p := range pages {
- paths = append(paths, p.Pathc())
- }
- sort.Strings(paths)
- return strings.Join(paths, "|")
-}
-
-func dumpPagesLinks(pages ...page.Page) {
- var links []string
- for _, p := range pages {
- links = append(links, p.RelPermalink())
- }
- sort.Strings(links)
-
- for _, link := range links {
- fmt.Println(link)
- }
-}
-
-func dumpPages(pages ...page.Page) {
- fmt.Println("---------")
- for _, p := range pages {
- fmt.Printf("Kind: %s Title: %-10s RelPermalink: %-10s Path: %-10s sections: %s Lang: %s\n",
- p.Kind(), p.Title(), p.RelPermalink(), p.Pathc(), p.SectionsPath(), p.Lang())
- }
-}
-
-func dumpSPages(pages ...*pageState) {
- for i, p := range pages {
- fmt.Printf("%d: Kind: %s Title: %-10s RelPermalink: %-10s Path: %-10s sections: %s\n",
- i+1,
- p.Kind(), p.Title(), p.RelPermalink(), p.Pathc(), p.SectionsPath())
- }
-}
-
-func printStringIndexes(s string) {
- lines := strings.Split(s, "\n")
- i := 0
-
- for _, line := range lines {
-
- for _, r := range line {
- fmt.Printf("%-3s", strconv.Itoa(i))
- i += utf8.RuneLen(r)
- }
- i++
- fmt.Println()
- for _, r := range line {
- fmt.Printf("%-3s", string(r))
- }
- fmt.Println()
-
- }
-}
-
-// See https://github.com/golang/go/issues/19280
-// Not in use.
-var parallelEnabled = true
-
-func parallel(t *testing.T) {
- if parallelEnabled {
- t.Parallel()
- }
-}
-
-func skipSymlink(t *testing.T) {
- if runtime.GOOS == "windows" && os.Getenv("CI") == "" {
- t.Skip("skip symlink test on local Windows (needs admin)")
- }
-}
-
-func captureStderr(f func() error) (string, error) {
- old := os.Stderr
- r, w, _ := os.Pipe()
- os.Stderr = w
-
- err := f()
-
- w.Close()
- os.Stderr = old
-
- var buf bytes.Buffer
- io.Copy(&buf, r)
- return buf.String(), err
-}
-
-func captureStdout(f func() error) (string, error) {
- old := os.Stdout
- r, w, _ := os.Pipe()
- os.Stdout = w
-
- err := f()
-
- w.Close()
- os.Stdout = old
-
- var buf bytes.Buffer
- io.Copy(&buf, r)
- return buf.String(), err
-}