MM-16548: Fixing bug with empty type in the second line of the bulk import (#11567)
* MM-16548: Fixing bug with empty type in the second line of the bulk import * Adding tests to this behavior * Changing the approach to fix the problem
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
efc342f294
Коммит
c0b51b03de
@@ -64,11 +64,13 @@ func (a *App) BulkImport(fileReader io.Reader, dryRun bool, workers int) (*model
|
|||||||
if importDataFileVersion != 1 {
|
if importDataFileVersion != 1 {
|
||||||
return model.NewAppError("BulkImport", "app.import.bulk_import.unsupported_version.error", nil, "", http.StatusBadRequest), lineNumber
|
return model.NewAppError("BulkImport", "app.import.bulk_import.unsupported_version.error", nil, "", http.StatusBadRequest), lineNumber
|
||||||
}
|
}
|
||||||
|
lastLineType = line.Type
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if line.Type != lastLineType {
|
if line.Type != lastLineType {
|
||||||
if lastLineType != "" {
|
// Only clear the worker queue if is not the first data entry
|
||||||
|
if lineNumber != 2 {
|
||||||
// Changing type. Clear out the worker queue before continuing.
|
// Changing type. Clear out the worker queue before continuing.
|
||||||
close(linesChan)
|
close(linesChan)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|||||||
@@ -226,6 +226,14 @@ func TestImportBulkImport(t *testing.T) {
|
|||||||
if err, line := th.App.BulkImport(strings.NewReader(data3), false, 2); err == nil || line != 1 {
|
if err, line := th.App.BulkImport(strings.NewReader(data3), false, 2); err == nil || line != 1 {
|
||||||
t.Fatalf("Should have failed due to missing version line on line 1.")
|
t.Fatalf("Should have failed due to missing version line on line 1.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Run("First item after version without type", func(t *testing.T) {
|
||||||
|
data := `{"type": "version", "version": 1}
|
||||||
|
{"name": "custom-emoji-troll", "image": "bulkdata/emoji/trollolol.png"}`
|
||||||
|
err, line := th.App.BulkImport(strings.NewReader(data), false, 2)
|
||||||
|
require.NotNil(t, err, "Should have failed due to invalid type on line 2.")
|
||||||
|
require.Equal(t, 2, line, "Should have failed due to invalid type on line 2.")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImportProcessImportDataFileVersionLine(t *testing.T) {
|
func TestImportProcessImportDataFileVersionLine(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user