summaryrefslogtreecommitdiffstats
path: root/hugolib/resource_chain_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-10-20 10:11:48 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-04-05 18:00:44 +0200
commite58a540895c28b8884823dcb1b64c272422f9923 (patch)
tree3fefb267f87e61a969a6ccf776d75fe64b50b2b1 /hugolib/resource_chain_test.go
parent20162518c450770ebfd54e0e987f34a5cccf236b (diff)
resources: Create a common ResourceFinder interface
And make both .Resources and resources implement it. This gets us 2 new methods/functions, so you can now also do: * .Resources.Get * resources.ByType Note that GetRemote is not covered by this interface, as that is only available as a global template function. Fixes #8653
Diffstat (limited to 'hugolib/resource_chain_test.go')
-rw-r--r--hugolib/resource_chain_test.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go
index 471ea54e8..c7bf8a68a 100644
--- a/hugolib/resource_chain_test.go
+++ b/hugolib/resource_chain_test.go
@@ -696,6 +696,8 @@ func TestResourcesMatch(t *testing.T) {
b.WithContent("page.md", "")
b.WithSourceFile(
+ "assets/images/img1.png", "png",
+ "assets/images/img2.jpg", "jpg",
"assets/jsons/data1.json", "json1 content",
"assets/jsons/data2.json", "json2 content",
"assets/jsons/data3.xml", "xml content",
@@ -704,7 +706,9 @@ func TestResourcesMatch(t *testing.T) {
b.WithTemplates("index.html", `
{{ $jsons := (resources.Match "jsons/*.json") }}
{{ $json := (resources.GetMatch "jsons/*.json") }}
-{{ printf "JSONS: %d" (len $jsons) }}
+{{ printf "jsonsMatch: %d" (len $jsons) }}
+{{ printf "imagesByType: %d" (len (resources.ByType "image") ) }}
+{{ printf "applicationByType: %d" (len (resources.ByType "application") ) }}
JSON: {{ $json.RelPermalink }}: {{ $json.Content }}
{{ range $jsons }}
{{- .RelPermalink }}: {{ .Content }}
@@ -715,7 +719,10 @@ JSON: {{ $json.RelPermalink }}: {{ $json.Content }}
b.AssertFileContent("public/index.html",
"JSON: /jsons/data1.json: json1 content",
- "JSONS: 2", "/jsons/data1.json: json1 content")
+ "jsonsMatch: 2",
+ "imagesByType: 2",
+ "applicationByType: 3",
+ "/jsons/data1.json: json1 content")
}
func TestResourceMinifyDisabled(t *testing.T) {