[NO-TICKET] Cleanup - remove unused code (#16828)

Этот коммит содержится в:
Atanas Alexandrov
2021-02-02 11:28:31 +01:00
коммит произвёл GitHub
родитель 57f2e7dcd4
Коммит a31f666019
4 изменённых файлов: 38 добавлений и 20 удалений

Просмотреть файл

@@ -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))

Просмотреть файл

@@ -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})
}

Просмотреть файл

@@ -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()