Skip to content

Commit

Permalink
using its as testing helper
Browse files Browse the repository at this point in the history
  • Loading branch information
logica0419 committed Sep 1, 2024
1 parent d01701c commit e6a9b83
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
8 changes: 2 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ module github.com/logica0419/resigif
go 1.22.2

require (
github.com/stretchr/testify v1.9.0
github.com/youta-t/its v0.5.0
golang.org/x/image v0.19.0
golang.org/x/sync v0.8.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
require golang.org/x/mod v0.20.0 // indirect
16 changes: 6 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/youta-t/its v0.5.0 h1:KScN5T5OHZPcj4KdPWmoOjLSyMRbG21LPB2dijxQKQA=
github.com/youta-t/its v0.5.0/go.mod h1:BIW52yCMszkfw3y00YtIB5I5EP10+vVJFu3cV78DqlU=
golang.org/x/image v0.19.0 h1:D9FX4QWkLfkeqaC62SonffIIuYdOk/UE2XKUBgRIBIQ=
golang.org/x/image v0.19.0/go.mod h1:y0zrRqlQRWQ5PXaYCOMLTW2fpsxZ8Qh9I/ohnInJEys=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
47 changes: 23 additions & 24 deletions resigif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (

"github.com/logica0419/resigif"
"github.com/logica0419/resigif/testdata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/youta-t/its"
"golang.org/x/image/draw"
)

Expand All @@ -21,14 +20,14 @@ func mustOpenGif(t *testing.T, name string) *gif.GIF {
t.Helper()

file, err := testdata.FS.Open(name)
require.NoError(t, err)
its.Nil[error]().Match(err).OrFatal(t)

defer func() {
_ = file.Close()
}()

image, err := gif.DecodeAll(file)
require.NoError(t, err)
its.Nil[error]().Match(err).OrFatal(t)

return image
}
Expand All @@ -37,14 +36,14 @@ func mustEncodeGif(t *testing.T, name string, image *gif.GIF) {
t.Helper()

file, err := os.OpenFile(filepath.Clean("testdata/"+name), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
require.NoError(t, err)
its.Nil[error]().Match(err).OrFatal(t)

defer func() {
_ = file.Close()
}()

err = gif.EncodeAll(file, image)
require.NoError(t, err)
its.Nil[error]().Match(err).OrFatal(t)
}

func TestResize(t *testing.T) {
Expand All @@ -61,10 +60,10 @@ func TestResize(t *testing.T) {
}

tests := []struct {
name string
args args
want string
assertion require.ErrorAssertionFunc
name string
args args
want string
errMatcher its.Matcher[error]
}{
{
name: "success (mushroom 正方形、小サイズ)",
Expand All @@ -77,8 +76,8 @@ func TestResize(t *testing.T) {
resigif.WithAspectRatio(resigif.Ignore),
},
},
want: "mushroom_resized.gif",
assertion: require.NoError,
want: "mushroom_resized.gif",
errMatcher: its.Nil[error](),
},
{
name: "success (tooth 正方形、DisposalBackground)",
Expand All @@ -91,8 +90,8 @@ func TestResize(t *testing.T) {
resigif.WithParallel(1),
},
},
want: "tooth_resized.gif",
assertion: require.NoError,
want: "tooth_resized.gif",
errMatcher: its.Nil[error](),
},
{
name: "success (new_year 横長)",
Expand All @@ -105,8 +104,8 @@ func TestResize(t *testing.T) {
resigif.WithImageResizeFunc(resigif.FromDrawScaler(draw.BiLinear)),
},
},
want: "new_year_resized.gif",
assertion: require.NoError,
want: "new_year_resized.gif",
errMatcher: its.Nil[error](),
},
{
name: "success (miku 縦長、差分最適化)",
Expand All @@ -117,8 +116,8 @@ func TestResize(t *testing.T) {
height: 256,
opts: nil,
},
want: "miku_resized.gif",
assertion: require.NoError,
want: "miku_resized.gif",
errMatcher: its.Nil[error](),
},
{
name: "success (frog 縦長、DisposalBackground + 背景色不整合)",
Expand All @@ -129,8 +128,8 @@ func TestResize(t *testing.T) {
height: 256,
opts: nil,
},
want: "frog_resized.gif",
assertion: require.NoError,
want: "frog_resized.gif",
errMatcher: its.Nil[error](),
},
{
name: "success (surprised 正方形、空のGlobal Color Table)",
Expand All @@ -141,8 +140,8 @@ func TestResize(t *testing.T) {
height: 256,
opts: nil,
},
want: "surprised_resized.gif",
assertion: require.NoError,
want: "surprised_resized.gif",
errMatcher: its.Nil[error](),
},
}

Expand All @@ -156,8 +155,8 @@ func TestResize(t *testing.T) {
mustEncodeGif(t, tt.want, got)
}

tt.assertion(t, err)
assert.Equal(t, mustOpenGif(t, tt.want), got)
tt.errMatcher.Match(err).OrError(t)
its.DeepEqual(mustOpenGif(t, tt.want)).Match(got).OrError(t)
})
}
}

0 comments on commit e6a9b83

Please sign in to comment.