diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-17 20:52:50 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-17 20:52:50 +0100 |
commit | ed847ed93d86d0e1c0993adfee787e7fa02e604b (patch) | |
tree | fc85030e7109f3c1f8192bb417cba221f74342fe /hugolib/testhelpers_test.go | |
parent | 10c13f5d79e467796088cd305c8c3cb0fa7c0ee0 (diff) |
hugolib: Test helper cleanup
Diffstat (limited to 'hugolib/testhelpers_test.go')
-rw-r--r-- | hugolib/testhelpers_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index f0fcd9530..3c931ca48 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -4,7 +4,14 @@ import ( "path/filepath" "testing" + "regexp" + + "github.com/spf13/hugo/config" "github.com/spf13/hugo/deps" + + "fmt" + "strings" + "github.com/spf13/hugo/helpers" "github.com/spf13/hugo/source" "github.com/spf13/hugo/tpl" @@ -20,6 +27,31 @@ import ( "github.com/stretchr/testify/require" ) +type testHelper struct { + Cfg config.Provider + Fs *hugofs.Fs + T testing.TB +} + +func (th testHelper) assertFileContent(filename string, defaultInSubDir bool, matches ...string) { + filename = th.replaceDefaultContentLanguageValue(filename, defaultInSubDir) + content := readDestination(th.T, th.Fs, filename) + for _, match := range matches { + match = th.replaceDefaultContentLanguageValue(match, defaultInSubDir) + require.True(th.T, strings.Contains(content, match), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1))) + } +} + +func (th testHelper) assertFileContentRegexp(filename string, defaultInSubDir bool, matches ...string) { + filename = th.replaceDefaultContentLanguageValue(filename, defaultInSubDir) + content := readDestination(th.T, th.Fs, filename) + for _, match := range matches { + match = th.replaceDefaultContentLanguageValue(match, defaultInSubDir) + r := regexp.MustCompile(match) + require.True(th.T, r.MatchString(content), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1))) + } +} + func newTestPathSpec(fs *hugofs.Fs, v *viper.Viper) *helpers.PathSpec { l := helpers.NewDefaultLanguage(v) return helpers.NewPathSpec(fs, l) |