Skip to content

Commit

Permalink
add ImageResizeFunc error pattern to test
Browse files Browse the repository at this point in the history
  • Loading branch information
logica0419 committed Sep 1, 2024
1 parent 9046045 commit 9cfcddb
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion resigif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resigif_test
import (
"context"
"flag"
"image"
"image/gif"
"os"
"path/filepath"
Expand Down Expand Up @@ -143,6 +144,20 @@ func TestResize(t *testing.T) {
want: "surprised_resized.gif",
errMatcher: its.Nil[error](),
},
{
name: "fail (error from ImageResizeFunc)",
args: args{
ctx: context.Background(),
src: "surprised.gif",
width: 256,
height: 256,
opts: []resigif.Option{resigif.WithImageResizeFunc(func(_ *image.NRGBA, _, _ int) (*image.NRGBA, error) {
return nil, os.ErrInvalid
})},
},
want: "surprised_resized.gif",
errMatcher: its.Error(os.ErrInvalid),
},
}

for _, tt := range tests {
Expand All @@ -151,11 +166,16 @@ func TestResize(t *testing.T) {

got, err := resigif.Resize(tt.args.ctx, mustOpenGif(t, tt.args.src), tt.args.width, tt.args.height, tt.args.opts...)

if overWrite != nil && *overWrite {
if err != nil && overWrite != nil && *overWrite {
mustEncodeGif(t, tt.want, got)
}

tt.errMatcher.Match(err).OrError(t)

if err != nil {
return
}

its.DeepEqual(mustOpenGif(t, tt.want)).Match(got).OrError(t)
})
}
Expand Down

0 comments on commit 9cfcddb

Please sign in to comment.