resources/images: Add some golden tests for images.QR

This commit is contained in:
Bjørn Erik Pedersen 2025-01-08 22:03:41 +01:00
parent c5a63a3b4f
commit 892b49110e
3 changed files with 36 additions and 0 deletions

View file

@ -229,6 +229,42 @@ Home.
runGolden(t, name, files)
}
func TestGoldenFuncs(t *testing.T) {
t.Parallel()
if skipGolden {
t.Skip("Skip golden test on this architecture")
}
// Will be used to generate golden files.
name := "funcs"
files := `
-- hugo.toml --
-- assets/sunset.jpg --
sourcefilename: ../testdata/sunset.jpg
-- layouts/index.html --
Home.
{{ template "copy" (dict "name" "qr-default.png" "img" (images.QR "https://gohugo.io")) }}
{{ template "copy" (dict "name" "qr-level-high_scale-6.png" "img" (images.QR "https://gohugo.io" (dict "level" "high" "scale" 6))) }}
{{ define "copy"}}
{{ if lt (len (path.Ext .name)) 4 }}
{{ errorf "No extension in %q" .name }}
{{ end }}
{{ $img := .img }}
{{ $name := printf "images/%s" .name }}
{{ with $img | resources.Copy $name }}
{{ .Publish }}
{{ end }}
{{ end }}
`
runGolden(t, name, files)
}
func runGolden(t testing.TB, name, files string) *hugolib.IntegrationTestBuilder {
t.Helper()

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB