mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 22:21:07 +03:00
hugolib: More test helper cleanup
This commit is contained in:
parent
ed847ed93d
commit
07ab7ae3d2
14 changed files with 171 additions and 162 deletions
|
@ -33,25 +33,44 @@ type testHelper struct {
|
|||
T testing.TB
|
||||
}
|
||||
|
||||
func (th testHelper) assertFileContent(filename string, defaultInSubDir bool, matches ...string) {
|
||||
filename = th.replaceDefaultContentLanguageValue(filename, defaultInSubDir)
|
||||
func (th testHelper) assertFileContent(filename string, matches ...string) {
|
||||
filename = th.replaceDefaultContentLanguageValue(filename)
|
||||
content := readDestination(th.T, th.Fs, filename)
|
||||
for _, match := range matches {
|
||||
match = th.replaceDefaultContentLanguageValue(match, defaultInSubDir)
|
||||
match = th.replaceDefaultContentLanguageValue(match)
|
||||
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)
|
||||
// TODO(bep) better name for this. It does no magic replacements depending on defaultontentLanguageInSubDir.
|
||||
func (th testHelper) assertFileContentStraight(filename string, matches ...string) {
|
||||
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, matches ...string) {
|
||||
filename = th.replaceDefaultContentLanguageValue(filename)
|
||||
content := readDestination(th.T, th.Fs, filename)
|
||||
for _, match := range matches {
|
||||
match = th.replaceDefaultContentLanguageValue(match)
|
||||
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 (th testHelper) replaceDefaultContentLanguageValue(value string) string {
|
||||
defaultInSubDir := th.Cfg.GetBool("defaultContentLanguageInSubDir")
|
||||
replace := th.Cfg.GetString("defaultContentLanguage") + "/"
|
||||
|
||||
if !defaultInSubDir {
|
||||
value = strings.Replace(value, replace, "", 1)
|
||||
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func newTestPathSpec(fs *hugofs.Fs, v *viper.Viper) *helpers.PathSpec {
|
||||
l := helpers.NewDefaultLanguage(v)
|
||||
return helpers.NewPathSpec(fs, l)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue