Includes []string
}
+func (gm GlobMatcher) IsZero() bool {
+ return len(gm.Includes) == 0 && len(gm.Excludes) == 0
+}
+
type ConfigCompiled struct {
For predicate.P[string]
PollConfigs []PollConfigCompiled
}
func (gm *GlobMatcher) CompilePredicate() (func(string) bool, error) {
+ if gm.IsZero() {
+ panic("no includes or excludes")
+ }
var p predicate.P[string]
for _, include := range gm.Includes {
g, err := glob.Compile(include, '/')
return c, err
}
+ if c.Cache.For.IsZero() {
+ c.Cache.For = DefaultConfig.Cache.For
+ }
+
return c, nil
}
)
func TestConfigCustom(t *testing.T) {
+ t.Parallel()
+
files := `
-- hugo.toml --
[httpcache]
}
func TestConfigDefault(t *testing.T) {
+ t.Parallel()
+
files := `
-- hugo.toml --
`
b.Assert(compiled.For("https://gohugo.io/foo.jpg"), qt.IsFalse)
b.Assert(compiled.PollConfigFor("https://gohugo.io/foo.jpg").Config.Disable, qt.IsTrue)
}
+
+func TestConfigPollsOnly(t *testing.T) {
+ t.Parallel()
+ files := `
+-- hugo.toml --
+[httpcache]
+[[httpcache.polls]]
+low = "5s"
+high = "32s"
+[httpcache.polls.for]
+includes = ["**gohugo.io**"]
+
+
+`
+
+ b := hugolib.Test(t, files)
+
+ compiled := b.H.Configs.Base.C.HTTPCache
+
+ b.Assert(compiled.For("https://gohugo.io/posts.json"), qt.IsFalse)
+ b.Assert(compiled.For("https://gohugo.io/foo.jpg"), qt.IsFalse)
+
+ pc := compiled.PollConfigFor("https://gohugo.io/foo.jpg")
+ b.Assert(pc.Config.Low, qt.Equals, 5*time.Second)
+ b.Assert(pc.Config.High, qt.Equals, 32*time.Second)
+ b.Assert(compiled.PollConfigFor("https://example.com/foo.jpg").IsZero(), qt.IsTrue)
+}