aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/pagebundler_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2019-09-19 10:12:29 +0200
committerBjørn Erik Pedersen <[email protected]>2019-09-19 12:36:01 +0200
commit6dec671fb930029e18ba9aa5135b3a27adcddb21 (patch)
treefa614878e492d099255baf8b6ab0d2cbf4512458 /hugolib/pagebundler_test.go
parentc0d7188ec85e7a4b61489e38896108d877f6d902 (diff)
downloadhugo-6dec671fb930029e18ba9aa5135b3a27adcddb21.tar.gz
hugo-6dec671fb930029e18ba9aa5135b3a27adcddb21.zip
Fix cache key transformed resources
Fixes #6348
Diffstat (limited to 'hugolib/pagebundler_test.go')
-rw-r--r--hugolib/pagebundler_test.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/hugolib/pagebundler_test.go b/hugolib/pagebundler_test.go
index 1f7addb28..af4bc391b 100644
--- a/hugolib/pagebundler_test.go
+++ b/hugolib/pagebundler_test.go
@@ -20,6 +20,8 @@ import (
"strings"
"testing"
+ "github.com/gohugoio/hugo/helpers"
+
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/common/loggers"
@@ -1216,3 +1218,60 @@ title: %q
`)
}
+
+func TestBundleTransformMany(t *testing.T) {
+
+ b := newTestSitesBuilder(t).WithSimpleConfigFile().Running()
+
+ for i := 1; i <= 50; i++ {
+ b.WithContent(fmt.Sprintf("bundle%d/index.md", i), fmt.Sprintf(`
+---
+title: "Page"
+weight: %d
+---
+
+`, i))
+ b.WithSourceFile(fmt.Sprintf("content/bundle%d/data.yaml", i), fmt.Sprintf(`data: v%d`, i))
+
+ b.WithSourceFile(fmt.Sprintf("assets/data%d/data.yaml", i), fmt.Sprintf(`vdata: v%d`, i))
+
+ }
+
+ b.WithTemplatesAdded("_default/single.html", `
+{{ $bundleYaml := .Resources.GetMatch "*.yaml" }}
+{{ $assetsYaml := resources.GetMatch (printf "data%d/*.yaml" .Weight) }}
+{{ $data1 := $bundleYaml | transform.Unmarshal }}
+{{ $data2 := $assetsYaml | transform.Unmarshal }}
+{{ $bundleFingerprinted := $bundleYaml | fingerprint "md5" }}
+{{ $assetsFingerprinted := $assetsYaml | fingerprint "md5" }}
+
+data content unmarshaled: {{ $data1.data }}
+data assets content unmarshaled: {{ $data2.vdata }}
+bundle fingerprinted: {{ $bundleFingerprinted.RelPermalink }}
+assets fingerprinted: {{ $assetsFingerprinted.RelPermalink }}
+`)
+
+ for i := 0; i < 3; i++ {
+
+ b.Build(BuildCfg{})
+
+ for i := 1; i <= 50; i++ {
+ b.AssertFileContent(fmt.Sprintf("public/bundle%d/data.yaml", i), fmt.Sprintf("data: v%d", i))
+ b.AssertFileContent(fmt.Sprintf("public/bundle%d/index.html", i), fmt.Sprintf("data content unmarshaled: v%d", i))
+ b.AssertFileContent(fmt.Sprintf("public/bundle%d/index.html", i), fmt.Sprintf("data assets content unmarshaled: v%d", i))
+
+ md5Asset := helpers.MD5String(fmt.Sprintf(`vdata: v%d`, i))
+ b.AssertFileContent(fmt.Sprintf("public/bundle%d/index.html", i), fmt.Sprintf("assets fingerprinted: /data%d/data.%s.yaml", i, md5Asset))
+
+ // The original is not used, make sure it's not published.
+ b.Assert(b.CheckExists(fmt.Sprintf("public/data%d/data.yaml", i)), qt.Equals, false)
+
+ md5Bundle := helpers.MD5String(fmt.Sprintf(`data: v%d`, i))
+ b.AssertFileContent(fmt.Sprintf("public/bundle%d/index.html", i), fmt.Sprintf("bundle fingerprinted: /bundle%d/data.%s.yaml", i, md5Bundle))
+
+ }
+
+ b.EditFiles("assets/data/foo.yaml", "FOO")
+
+ }
+}