From 2583135a8575d4f245f4c757b5109216069840eb Mon Sep 17 00:00:00 2001 From: kikoqiu Date: Tue, 9 Nov 2021 14:36:07 +0800 Subject: [PATCH] Add some tests for thumbnail generation --- pkg/filesystem/image_test.go | 9 +++++++++ pkg/thumb/image_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/pkg/filesystem/image_test.go b/pkg/filesystem/image_test.go index 0c4d0261..9678df92 100644 --- a/pkg/filesystem/image_test.go +++ b/pkg/filesystem/image_test.go @@ -38,3 +38,12 @@ func TestFileSystem_GetThumb(t *testing.T) { asserts.EqualValues(50, res.MaxAge) } } + +func TestFileSystem_ThumbWorker(t *testing.T) { + asserts := assert.New(t) + + asserts.NotPanics(func() { + getThumbWorker().addWorker() + getThumbWorker().releaseWorker() + }) +} diff --git a/pkg/thumb/image_test.go b/pkg/thumb/image_test.go index 7fe65a18..210a39a4 100644 --- a/pkg/thumb/image_test.go +++ b/pkg/thumb/image_test.go @@ -86,6 +86,30 @@ func TestThumb_GetThumb(t *testing.T) { }) } +func TestThumb_Thumbnail(t *testing.T) { + asserts := assert.New(t) + { + img := image.NewRGBA(image.Rect(0, 0, 500, 200)) + thumb := Thumbnail(100, 100, img) + asserts.Equal(thumb.Bounds(), image.Rect(0, 0, 100, 40)) + } + { + img := image.NewRGBA(image.Rect(0, 0, 200, 200)) + thumb := Thumbnail(100, 100, img) + asserts.Equal(thumb.Bounds(), image.Rect(0, 0, 100, 100)) + } + { + img := image.NewRGBA(image.Rect(0, 0, 500, 500)) + thumb := Thumbnail(100, 100, img) + asserts.Equal(thumb.Bounds(), image.Rect(0, 0, 100, 100)) + } + { + img := image.NewRGBA(image.Rect(0, 0, 200, 500)) + thumb := Thumbnail(100, 100, img) + asserts.Equal(thumb.Bounds(), image.Rect(0, 0, 40, 100)) + } +} + func TestThumb_Save(t *testing.T) { asserts := assert.New(t) file := CreateTestImage()