From a31f6660191e8805dd15356747a05f44219e2c11 Mon Sep 17 00:00:00 2001 From: Atanas Alexandrov <56699232+cupakob@users.noreply.github.com> Date: Tue, 2 Feb 2021 11:28:31 +0100 Subject: [PATCH] [NO-TICKET] Cleanup - remove unused code (#16828) --- app/file.go | 10 +++++----- app/file_test.go | 30 +++++++++++++++++++++++++++++ app/helper_test.go | 12 ------------ services/slackimport/slackimport.go | 6 +++--- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/app/file.go b/app/file.go index c7c55d0dab..fbdb098dcd 100644 --- a/app/file.go +++ b/app/file.go @@ -1026,13 +1026,13 @@ func (a *App) HandleImages(previewPathList []string, thumbnailPathList []string, wg := new(sync.WaitGroup) for i := range fileData { - img, width, height := prepareImage(fileData[i]) + img, width, _ := prepareImage(fileData[i]) if img != nil { wg.Add(2) - go func(img image.Image, path string, width int, height int) { + go func(img image.Image, path string) { defer wg.Done() - a.generateThumbnailImage(img, path, width, height) - }(img, thumbnailPathList[i], width, height) + a.generateThumbnailImage(img, path) + }(img, thumbnailPathList[i]) go func(img image.Image, path string, width int) { defer wg.Done() @@ -1109,7 +1109,7 @@ func getImageOrientation(input io.Reader) (int, error) { return orientation, nil } -func (a *App) generateThumbnailImage(img image.Image, thumbnailPath string, width int, height int) { +func (a *App) generateThumbnailImage(img image.Image, thumbnailPath string) { buf := new(bytes.Buffer) if err := jpeg.Encode(buf, genThumbnail(img), &jpeg.Options{Quality: 90}); err != nil { mlog.Error("Unable to encode image as jpeg", mlog.String("path", thumbnailPath), mlog.Err(err)) diff --git a/app/file_test.go b/app/file_test.go index da735007cf..88c1b4b703 100644 --- a/app/file_test.go +++ b/app/file_test.go @@ -6,6 +6,7 @@ package app import ( "errors" "fmt" + "image" "os" "path/filepath" "testing" @@ -319,3 +320,32 @@ func TestCopyFileInfos(t *testing.T) { assert.NotEqual(t, info1.Id, info2.Id, "should not be equal") assert.Equal(t, info2.PostId, "", "should be empty string") } + +func TestGenerateThumbnailImage(t *testing.T) { + t.Run("test generating thumbnail image", func(t *testing.T) { + // given + th := Setup(t) + defer th.TearDown() + img := createDummyImage() + dataPath, _ := fileutils.FindDir("data") + thumbailName := "thumb.jpg" + thumbnailPath := filepath.Join(dataPath, thumbailName) + + // when + th.App.generateThumbnailImage(img, thumbailName) + defer os.Remove(thumbnailPath) + + // then + outputImage, err := os.Stat(thumbnailPath) + assert.NoError(t, err) + assert.Equal(t, int64(957), outputImage.Size()) + }) +} + +func createDummyImage() *image.RGBA { + width := 200 + height := 100 + upperLeftCorner := image.Point{0, 0} + lowerRightCorner := image.Point{width, height} + return image.NewRGBA(image.Rectangle{upperLeftCorner, lowerRightCorner}) +} diff --git a/app/helper_test.go b/app/helper_test.go index b9cc09f39a..e88c1f805e 100644 --- a/app/helper_test.go +++ b/app/helper_test.go @@ -133,18 +133,6 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo return th } -func SetupEnterprise(tb testing.TB) *TestHelper { - if testing.Short() { - tb.SkipNow() - } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - - return setupTestHelper(dbStore, true, true, tb, nil) -} - func Setup(tb testing.TB) *TestHelper { if testing.Short() { tb.SkipNow() diff --git a/services/slackimport/slackimport.go b/services/slackimport/slackimport.go index 80678e3443..bcf2a26300 100644 --- a/services/slackimport/slackimport.go +++ b/services/slackimport/slackimport.go @@ -88,7 +88,7 @@ type Actions struct { CreateGroupChannel func([]string, string) (*model.Channel, *model.AppError) CreateChannel func(*model.Channel, bool) (*model.Channel, *model.AppError) DoUploadFile func(time.Time, string, string, string, string, []byte) (*model.FileInfo, *model.AppError) - GenerateThumbnailImage func(image.Image, string, int, int) + GenerateThumbnailImage func(image.Image, string) GeneratePreviewImage func(image.Image, string, int) InvalidateAllCaches func() MaxPostSize func() int @@ -771,9 +771,9 @@ func (si *SlackImporter) oldImportFile(timestamp time.Time, file io.Reader, team } if fileInfo.IsImage() && fileInfo.MimeType != "image/svg+xml" { - img, width, height := si.actions.PrepareImage(data) + img, width, _ := si.actions.PrepareImage(data) if img != nil { - si.actions.GenerateThumbnailImage(img, fileInfo.ThumbnailPath, width, height) + si.actions.GenerateThumbnailImage(img, fileInfo.ThumbnailPath) si.actions.GeneratePreviewImage(img, fileInfo.PreviewPath, width) } }