Skip to content

Commit

Permalink
chore: add test for webp files
Browse files Browse the repository at this point in the history
  • Loading branch information
waynezhang committed Jun 14, 2024
1 parent 123f529 commit 0208bdf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/images/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,24 @@ func TestResizeWithRotation(t *testing.T) {
assert.Equal(t, testdata.RotatedImageThumbnailWidth, size.Width)
assert.Equal(t, testdata.RotatedImageThumbnailHeight, size.Height)
}

func TestWebpSupport(t *testing.T) {
tmp, err := os.MkdirTemp("", "foto-test")
assert.Nil(t, err)

size, err := GetPhotoSize(testdata.WebpTestFile)
assert.Equal(t, testdata.WebpTestfileWidth, size.Width)
assert.Equal(t, testdata.WebpTestfileHeight, size.Height)

path := filepath.Join(tmp, "resized.webp")

err = ResizeImage(testdata.WebpTestFile, path, testdata.WebpThumbnailWidth)
assert.Nil(t, err)

size, err = GetPhotoSize(path)
assert.Equal(t, testdata.WebpThumbnailWidth, size.Width)
assert.Equal(t, testdata.WebpThumbnailHeight, size.Height)

checksum, _ := files.Checksum(path)
assert.Equal(t, testdata.WebpExpectedThubmnailChecksum, *checksum)
}
10 changes: 10 additions & 0 deletions internal/testdata/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ var (
RotatedImageThumbnailWidth = 640
RotatedImageThumbnailHeight = 480
)

var (
WebpTestFile = "../../testdata/webp/test.webp"
WebpTestfileWidth = 8000
WebpTestfileHeight = 6000

WebpThumbnailWidth = 640
WebpThumbnailHeight = 480
WebpExpectedThubmnailChecksum = "5a5f8fcae2e37e504d6e062ee8adefac45ec9102a410faa16d4a0278b310b0c8"
)
Binary file added testdata/webp/test-640.webp
Binary file not shown.
Binary file added testdata/webp/test.webp
Binary file not shown.

0 comments on commit 0208bdf

Please sign in to comment.