Skip to content

Commit

Permalink
resources/images: Add some mask tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jan 11, 2025
1 parent 27a422d commit e16e302
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion resources/images/images_golden_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var goldenOpts = struct {
// This will skip any assertions. Useful when adding new golden variants to a test.
devMode bool
}{
writeGoldenFiles: false,
writeGoldenFiles: true,
devMode: false,
}

Expand Down Expand Up @@ -133,6 +133,57 @@ Home.
runGolden(t, name, files)
}

func TestGoldenFiltersMask(t *testing.T) {
t.Parallel()

if skipGolden {
t.Skip("Skip golden test on this architecture")
}

// Will be used to generate golden files.
name := "filters_mask"

files := `
-- hugo.toml --
[imaging]
bgColor = '#ebcc34'
hint = 'photo'
quality = 75
resampleFilter = 'Lanczos'
-- assets/sunset.jpg --
sourcefilename: ../testdata/sunset.jpg
-- assets/mask.png --
sourcefilename: ../testdata/mask.png
-- layouts/index.html --
Home.
{{ $sunset := resources.Get "sunset.jpg" }}
{{ $mask := resources.Get "mask.png" }}
{{/* template "mask" (dict "name" "transparant.png" "base" $sunset "mask" $mask) }}
{{ template "mask" (dict "name" "yellow.jpg" "base" $sunset "mask" $mask) */}}
{{ template "mask" (dict "name" "wide.jpg" "base" $sunset "mask" $mask "spec" "resize 600x200") }}
{{ define "mask"}}
{{ $ext := path.Ext .name }}
{{ if lt (len (path.Ext .name)) 4 }}
{{ errorf "No extension in %q" .name }}
{{ end }}
{{ $format := strings.TrimPrefix "." $ext }}
{{ $spec := .spec | default (printf "resize 300x300 %s" $format) }}
{{ $filters := slice (images.Process $spec) (images.Mask .mask) }}
{{ $name := printf "images/%s" .name }}
{{ $img := .base.Filter $filters }}
{{ with $img | resources.Copy $name }}
{{ .Publish }}
{{ end }}
{{ end }}
`

runGolden(t, name, files)
}

func TestGoldenFiltersText(t *testing.T) {
t.Parallel()

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/testdata/mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e16e302

Please sign in to comment.