resources/images: Refactor golden image tests to locate them closer to the implementation

This commit is contained in:
Bjørn Erik Pedersen
2025-01-11 14:10:30 +02:00
parent 06cc8673fa
commit 2501de7aab
59 changed files with 307 additions and 241 deletions

View File

@@ -19,6 +19,7 @@ import (
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/hugolib"
"github.com/gohugoio/hugo/resources/images/imagetesting"
)
func TestImageConfigFromModule(t *testing.T) {
@@ -100,3 +101,44 @@ disableKinds = ['page','rss','section','sitemap','taxonomy','term']
b, err = hugolib.TestE(t, files)
b.Assert(err.Error(), qt.Contains, "cannot encode an empty string")
}
func TestImagesGoldenFuncs(t *testing.T) {
t.Parallel()
if imagetesting.SkipGoldenTests {
t.Skip("Skip golden test on this architecture")
}
// Will be used as the base folder for generated images.
name := "funcs"
files := `
-- hugo.toml --
-- assets/sunset.jpg --
sourcefilename: ../../resources/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 }}
`
opts := imagetesting.DefaultGoldenOpts
opts.T = t
opts.Name = name
opts.Files = files
imagetesting.RunGolden(opts)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB