@@ -17,27 +17,32 @@ import (
1717 "bytes"
1818 "image"
1919 "image/color"
20- "image/png"
2120 "path/filepath"
2221 "testing"
2322
2423 qt "github.com/frankban/quicktest"
2524 "github.com/gohugoio/hugo/config"
2625 "github.com/gohugoio/hugo/config/testconfig"
26+ "github.com/gohugoio/hugo/resources/images"
2727 "github.com/spf13/afero"
2828 "github.com/spf13/cast"
2929)
3030
3131type tstNoStringer struct {}
3232
33+ type widthHeight struct {
34+ Width int
35+ Height int
36+ }
37+
3338var configTests = []struct {
3439 path any
35- input [] byte
40+ input widthHeight
3641 expect any
3742}{
3843 {
3944 path : "a.png" ,
40- input : blankImage ( 10 , 10 ) ,
45+ input : widthHeight { 10 , 10 } ,
4146 expect : image.Config {
4247 Width : 10 ,
4348 Height : 10 ,
@@ -46,7 +51,7 @@ var configTests = []struct {
4651 },
4752 {
4853 path : "a.png" ,
49- input : blankImage ( 10 , 10 ) ,
54+ input : widthHeight { 10 , 10 } ,
5055 expect : image.Config {
5156 Width : 10 ,
5257 Height : 10 ,
@@ -55,7 +60,7 @@ var configTests = []struct {
5560 },
5661 {
5762 path : "b.png" ,
58- input : blankImage ( 20 , 15 ) ,
63+ input : widthHeight { 20 , 15 } ,
5964 expect : image.Config {
6065 Width : 20 ,
6166 Height : 15 ,
@@ -64,7 +69,7 @@ var configTests = []struct {
6469 },
6570 {
6671 path : "a.png" ,
67- input : blankImage ( 20 , 15 ) ,
72+ input : widthHeight { 20 , 15 } ,
6873 expect : image.Config {
6974 Width : 10 ,
7075 Height : 10 ,
@@ -101,7 +106,8 @@ func TestNSConfig(t *testing.T) {
101106 // cast path to string for afero.WriteFile
102107 sp , err := cast .ToStringE (test .path )
103108 c .Assert (err , qt .IsNil )
104- afero .WriteFile (ns .deps .Fs .Source , filepath .Join (bcfg .WorkingDir (), sp ), test .input , 0o755 )
109+ img := blankImage (d .ResourceSpec .Imaging .Codec , test .input .Width , test .input .Height )
110+ afero .WriteFile (ns .deps .Fs .Source , filepath .Join (bcfg .WorkingDir (), sp ), img , 0o755 )
105111
106112 result , err := ns .Config (test .path )
107113
@@ -111,10 +117,13 @@ func TestNSConfig(t *testing.T) {
111117 }
112118}
113119
114- func blankImage (width , height int ) []byte {
120+ func blankImage (codec * images. Codec , width , height int ) []byte {
115121 var buf bytes.Buffer
116122 img := image .NewRGBA (image .Rect (0 , 0 , width , height ))
117- if err := png .Encode (& buf , img ); err != nil {
123+ cfg := images.ImageConfig {
124+ TargetFormat : images .PNG ,
125+ }
126+ if err := codec .EncodeTo (cfg , & buf , img ); err != nil {
118127 panic (err )
119128 }
120129 return buf .Bytes ()
0 commit comments