summaryrefslogtreecommitdiffstats
path: root/hugolib/page_test.go
diff options
context:
space:
mode:
authorsatotake <doublequotation@gmail.com>2022-04-27 02:57:04 +0900
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-08 16:56:26 +0200
commite77ca3c105bd64c5077d823d2127f6f812a4f681 (patch)
treeebbe9c310bfab1e34f9fd2e36b738fd2a37d6f11 /hugolib/page_test.go
parentf2946da9e806c2bafbdd26707fe339db79bd980b (diff)
Add `clock` cli flag
Close #8787
Diffstat (limited to 'hugolib/page_test.go')
-rw-r--r--hugolib/page_test.go51
1 files changed, 50 insertions, 1 deletions
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index 84e54306a..05a1c3d77 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -22,12 +22,14 @@ import (
"testing"
"time"
+ "github.com/bep/clock"
"github.com/gohugoio/hugo/htesting"
"github.com/gohugoio/hugo/markup/asciidocext"
"github.com/gohugoio/hugo/markup/rst"
"github.com/gohugoio/hugo/config"
+ "github.com/gohugoio/hugo/common/htime"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/hugofs"
@@ -1536,7 +1538,6 @@ Content.
}
func TestShouldBuild(t *testing.T) {
- t.Parallel()
past := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
future := time.Date(2037, 11, 17, 20, 34, 58, 651387237, time.UTC)
zero := time.Time{}
@@ -1582,6 +1583,54 @@ func TestShouldBuild(t *testing.T) {
}
}
+func TestShouldBuildWithClock(t *testing.T) {
+ htime.Clock = clock.Start(time.Date(2021, 11, 17, 20, 34, 58, 651387237, time.UTC))
+ t.Cleanup(func() { htime.Clock = clock.Start(time.Now()) })
+ past := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
+ future := time.Date(2037, 11, 17, 20, 34, 58, 651387237, time.UTC)
+ zero := time.Time{}
+
+ publishSettings := []struct {
+ buildFuture bool
+ buildExpired bool
+ buildDrafts bool
+ draft bool
+ publishDate time.Time
+ expiryDate time.Time
+ out bool
+ }{
+ // publishDate and expiryDate
+ {false, false, false, false, zero, zero, true},
+ {false, false, false, false, zero, future, true},
+ {false, false, false, false, past, zero, true},
+ {false, false, false, false, past, future, true},
+ {false, false, false, false, past, past, false},
+ {false, false, false, false, future, future, false},
+ {false, false, false, false, future, past, false},
+
+ // buildFuture and buildExpired
+ {false, true, false, false, past, past, true},
+ {true, true, false, false, past, past, true},
+ {true, false, false, false, past, past, false},
+ {true, false, false, false, future, future, true},
+ {true, true, false, false, future, future, true},
+ {false, true, false, false, future, past, false},
+
+ // buildDrafts and draft
+ {true, true, false, true, past, future, false},
+ {true, true, true, true, past, future, true},
+ {true, true, true, true, past, future, true},
+ }
+
+ for _, ps := range publishSettings {
+ s := shouldBuild(ps.buildFuture, ps.buildExpired, ps.buildDrafts, ps.draft,
+ ps.publishDate, ps.expiryDate)
+ if s != ps.out {
+ t.Errorf("AssertShouldBuildWithClock unexpected output with params: %+v", ps)
+ }
+ }
+}
+
// "dot" in path: #1885 and #2110
// disablePathToLower regression: #3374
func TestPathIssues(t *testing.T) {