MM-22707: improved image upload tests and logging (#14018)
* improved image upload tests and error logging message Signed-off-by: Gabriel Linden Sagula <gsagula@gmail.com> * removed unecessary logging message Signed-off-by: Gabriel Linden Sagula <gsagula@gmail.com> * fixed null ptr issue Signed-off-by: Gabriel Linden Sagula <gsagula@gmail.com> * rolled back pointer to the client Signed-off-by: Gabriel Linden Sagula <gsagula@gmail.com> * added hexdump of the previewer file Signed-off-by: Gabriel Linden Sagula <gsagula@gmail.com> * fixed tests that use the renamed files Signed-off-by: Gabriel Linden Sagula <gsagula@gmail.com> * addressed reviewer notes Signed-off-by: Gabriel Linden Sagula <gsagula@gmail.com> * addressed reviewer concerns Signed-off-by: Gabriel Linden Sagula <gsagula@gmail.com> Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1c498996a4
Коммит
a1719e9fcf
@@ -5,6 +5,7 @@ package api4
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -221,13 +222,13 @@ func TestUploadFiles(t *testing.T) {
|
|||||||
// Upload a bunch of files, mixed images and non-images
|
// Upload a bunch of files, mixed images and non-images
|
||||||
{
|
{
|
||||||
title: "Happy",
|
title: "Happy",
|
||||||
names: []string{"test.png", "testgif.gif", "testplugin.tar.gz", "test-search.md", "test.tiff"},
|
names: []string{"test.png", "testgif.gif", "testplugin.tar.gz", "test-search.md", "test_compressed_tiff.tiff"},
|
||||||
expectedCreatorId: th.BasicUser.Id,
|
expectedCreatorId: th.BasicUser.Id,
|
||||||
},
|
},
|
||||||
// Upload a bunch of files, with clientIds
|
// Upload a bunch of files, with clientIds
|
||||||
{
|
{
|
||||||
title: "Happy client_ids",
|
title: "Happy client_ids",
|
||||||
names: []string{"test.png", "testgif.gif", "testplugin.tar.gz", "test-search.md", "test.tiff"},
|
names: []string{"test.png", "testgif.gif", "testplugin.tar.gz", "test-search.md", "test_compressed_tiff.tiff"},
|
||||||
clientIds: []string{"1", "2", "3", "4", "5"},
|
clientIds: []string{"1", "2", "3", "4", "5"},
|
||||||
expectedCreatorId: th.BasicUser.Id,
|
expectedCreatorId: th.BasicUser.Id,
|
||||||
},
|
},
|
||||||
@@ -356,9 +357,20 @@ func TestUploadFiles(t *testing.T) {
|
|||||||
// TIFF preview test
|
// TIFF preview test
|
||||||
{
|
{
|
||||||
title: "Happy image thumbnail/preview 9",
|
title: "Happy image thumbnail/preview 9",
|
||||||
names: []string{"test.tiff"},
|
names: []string{"test_compressed_tiff.tiff"},
|
||||||
expectedImageThumbnailNames: []string{"test_expected_thumb.tiff"},
|
expectedImageThumbnailNames: []string{"test_expected_tiff_thumb.jpeg"},
|
||||||
expectedImagePreviewNames: []string{"test_expected_preview.tiff"},
|
expectedImagePreviewNames: []string{"test_expected_tiff_preview.jpeg"},
|
||||||
|
expectImage: true,
|
||||||
|
expectedImageWidths: []int{701},
|
||||||
|
expectedImageHeights: []int{701},
|
||||||
|
expectedImageHasPreview: []bool{true},
|
||||||
|
expectedCreatorId: th.BasicUser.Id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Happy image thumbnail/preview 10",
|
||||||
|
names: []string{"test_raw_tiff.tiff"},
|
||||||
|
expectedImageThumbnailNames: []string{"test_expected_tiff_thumb.jpeg"},
|
||||||
|
expectedImagePreviewNames: []string{"test_expected_tiff_preview.jpeg"},
|
||||||
expectImage: true,
|
expectImage: true,
|
||||||
expectedImageWidths: []int{701},
|
expectedImageWidths: []int{701},
|
||||||
expectedImageHeights: []int{701},
|
expectedImageHeights: []int{701},
|
||||||
@@ -609,10 +621,16 @@ func TestUploadFiles(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
if !bytes.Equal(data, expected) {
|
if !bytes.Equal(data, expected) {
|
||||||
tf, err := ioutil.TempFile("", fmt.Sprintf("test_%v_*_%s", i, name))
|
tf, err := ioutil.TempFile("", fmt.Sprintf("test_%v_*_%s", i, name))
|
||||||
|
defer tf.Close()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
_, _ = io.Copy(tf, bytes.NewReader(data))
|
_, err = io.Copy(tf, bytes.NewReader(data))
|
||||||
tf.Close()
|
require.Nil(t, err)
|
||||||
t.Errorf("Actual data mismatched %s, written to %q", name, tf.Name())
|
if strings.Contains(name, "test_expected_tiff") {
|
||||||
|
// TODO: remove this once MM-22056 is fixed.
|
||||||
|
t.Errorf("Actual data mismatched %s, written to %q - expected %d bytes, got %d. Previewer Image: \n\n%s\n", name, tf.Name(), len(expected), len(data), hex.Dump(data))
|
||||||
|
} else {
|
||||||
|
t.Errorf("Actual data mismatched %s, written to %q - expected %d bytes, got %d.", name, tf.Name(), len(expected), len(data))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(tc.expectedPayloadNames) == 0 {
|
if len(tc.expectedPayloadNames) == 0 {
|
||||||
|
|||||||
@@ -2181,7 +2181,7 @@ func TestParseImages(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"tiff": {
|
"tiff": {
|
||||||
FileName: "test.tiff",
|
FileName: "test_compressed_tiff.tiff",
|
||||||
Expected: (*model.PostImage)(nil),
|
Expected: (*model.PostImage)(nil),
|
||||||
},
|
},
|
||||||
"not an image": {
|
"not an image": {
|
||||||
|
|||||||
|
До Ширина: | Высота: | Размер: 24 KiB После Ширина: | Высота: | Размер: 24 KiB |
|
До Ширина: | Высота: | Размер: 3.5 KiB После Ширина: | Высота: | Размер: 3.5 KiB |
Двоичные данные
tests/test_raw_tiff.tiff
Обычный файл
Двоичные данные
tests/test_raw_tiff.tiff
Обычный файл
Двоичный файл не отображается.
Ссылка в новой задаче
Block a user