mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
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>
This commit is contained in:
parent
1c498996a4
commit
a1719e9fcf
6 changed files with 27 additions and 9 deletions
|
|
@ -5,6 +5,7 @@ package api4
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
|
@ -221,13 +222,13 @@ func TestUploadFiles(t *testing.T) {
|
|||
// Upload a bunch of files, mixed images and non-images
|
||||
{
|
||||
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,
|
||||
},
|
||||
// Upload a bunch of files, with clientIds
|
||||
{
|
||||
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"},
|
||||
expectedCreatorId: th.BasicUser.Id,
|
||||
},
|
||||
|
|
@ -356,9 +357,20 @@ func TestUploadFiles(t *testing.T) {
|
|||
// TIFF preview test
|
||||
{
|
||||
title: "Happy image thumbnail/preview 9",
|
||||
names: []string{"test.tiff"},
|
||||
expectedImageThumbnailNames: []string{"test_expected_thumb.tiff"},
|
||||
expectedImagePreviewNames: []string{"test_expected_preview.tiff"},
|
||||
names: []string{"test_compressed_tiff.tiff"},
|
||||
expectedImageThumbnailNames: []string{"test_expected_tiff_thumb.jpeg"},
|
||||
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,
|
||||
expectedImageWidths: []int{701},
|
||||
expectedImageHeights: []int{701},
|
||||
|
|
@ -609,10 +621,16 @@ func TestUploadFiles(t *testing.T) {
|
|||
require.Nil(t, err)
|
||||
if !bytes.Equal(data, expected) {
|
||||
tf, err := ioutil.TempFile("", fmt.Sprintf("test_%v_*_%s", i, name))
|
||||
defer tf.Close()
|
||||
require.Nil(t, err)
|
||||
_, _ = io.Copy(tf, bytes.NewReader(data))
|
||||
tf.Close()
|
||||
t.Errorf("Actual data mismatched %s, written to %q", name, tf.Name())
|
||||
_, err = io.Copy(tf, bytes.NewReader(data))
|
||||
require.Nil(t, err)
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -2181,7 +2181,7 @@ func TestParseImages(t *testing.T) {
|
|||
},
|
||||
},
|
||||
"tiff": {
|
||||
FileName: "test.tiff",
|
||||
FileName: "test_compressed_tiff.tiff",
|
||||
Expected: (*model.PostImage)(nil),
|
||||
},
|
||||
"not an image": {
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
BIN
tests/test_raw_tiff.tiff
Normal file
BIN
tests/test_raw_tiff.tiff
Normal file
Binary file not shown.
Loading…
Reference in a new issue