From ce6e4310febf5659392a41b543594382441f3681 Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Sun, 11 Mar 2018 18:59:11 +0100 Subject: Refactor the GitInfo into the date handlers Fixes #4495 --- hugolib/page_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'hugolib/page_test.go') diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 905793ca6..875c5bdde 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -18,6 +18,7 @@ import ( "fmt" "html/template" "os" + "path/filepath" "reflect" "sort" @@ -25,6 +26,11 @@ import ( "testing" "time" + "github.com/gohugoio/hugo/hugofs" + "github.com/spf13/afero" + + "github.com/spf13/viper" + "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/helpers" "github.com/spf13/cast" @@ -904,6 +910,32 @@ func TestPageWithDate(t *testing.T) { checkPageDate(t, p, d) } +func TestPageWithLastmodFromGitInfo(t *testing.T) { + assrt := require.New(t) + + // We need to use the OS fs for this. + cfg := viper.New() + fs := hugofs.NewFrom(hugofs.Os, cfg) + fs.Destination = &afero.MemMapFs{} + + cfg.Set("frontmatter", map[string]interface{}{ + "lastmod": []string{":git", "lastmod"}, + }) + + cfg.Set("enableGitInfo", true) + + assrt.NoError(loadDefaultSettingsFor(cfg)) + + wd, err := os.Getwd() + assrt.NoError(err) + cfg.Set("workingDir", filepath.Join(wd, "testsite")) + + s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true}) + + assrt.Len(s.RegularPages, 1) + assrt.Equal("2018-02-28", s.RegularPages[0].Lastmod.Format("2006-01-02")) +} + func TestPageWithFrontMatterConfig(t *testing.T) { t.Parallel() -- cgit v1.2.3