unparam lint (#16927)
* fix "always receives ..." lint err * add unparam lint check * fix failed test * rm details param * ignore unparam lint * magic string replaced with model.NewRandomString * rm unused enableComplianceFeatures param * generate random message inside createPost Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4c5ea07aff
Коммит
62fa7b9350
16
app/file.go
16
app/file.go
@@ -710,12 +710,10 @@ func (a *App) UploadFileX(channelID, name string, input io.Reader,
|
||||
}
|
||||
|
||||
if *a.Config().FileSettings.DriverName == "" {
|
||||
return nil, t.newAppError("api.file.upload_file.storage.app_error",
|
||||
"", http.StatusNotImplemented)
|
||||
return nil, t.newAppError("api.file.upload_file.storage.app_error", http.StatusNotImplemented)
|
||||
}
|
||||
if t.ContentLength > t.maxFileSize {
|
||||
return nil, t.newAppError("api.file.upload_file.too_large_detailed.app_error",
|
||||
"", http.StatusRequestEntityTooLarge, "Length", t.ContentLength, "Limit", t.maxFileSize)
|
||||
return nil, t.newAppError("api.file.upload_file.too_large_detailed.app_error", http.StatusRequestEntityTooLarge, "Length", t.ContentLength, "Limit", t.maxFileSize)
|
||||
}
|
||||
|
||||
t.init(a)
|
||||
@@ -737,8 +735,7 @@ func (a *App) UploadFileX(channelID, name string, input io.Reader,
|
||||
if fileErr := a.RemoveFile(t.fileinfo.Path); fileErr != nil {
|
||||
mlog.Error("Failed to remove file", mlog.Err(fileErr))
|
||||
}
|
||||
return nil, t.newAppError("api.file.upload_file.too_large_detailed.app_error",
|
||||
"", http.StatusRequestEntityTooLarge, "Length", t.ContentLength, "Limit", t.maxFileSize)
|
||||
return nil, t.newAppError("api.file.upload_file.too_large_detailed.app_error", http.StatusRequestEntityTooLarge, "Length", t.ContentLength, "Limit", t.maxFileSize)
|
||||
}
|
||||
|
||||
t.fileinfo.Size = written
|
||||
@@ -827,8 +824,7 @@ func (t *UploadFileTask) preprocessImage() *model.AppError {
|
||||
// in 64 bits systems because images can't have more than 32 bits height or
|
||||
// width)
|
||||
if int64(t.fileinfo.Width)*int64(t.fileinfo.Height) > MaxImageSize {
|
||||
return t.newAppError("api.file.upload_file.large_image_detailed.app_error",
|
||||
"", http.StatusBadRequest)
|
||||
return t.newAppError("api.file.upload_file.large_image_detailed.app_error", http.StatusBadRequest)
|
||||
}
|
||||
t.fileinfo.HasPreviewImage = true
|
||||
nameWithoutExtension := t.Name[:strings.LastIndex(t.Name, ".")]
|
||||
@@ -942,7 +938,7 @@ func (t UploadFileTask) pathPrefix() string {
|
||||
"/" + t.fileinfo.Id + "/"
|
||||
}
|
||||
|
||||
func (t UploadFileTask) newAppError(id string, details interface{}, httpStatus int, extra ...interface{}) *model.AppError {
|
||||
func (t UploadFileTask) newAppError(id string, httpStatus int, extra ...interface{}) *model.AppError {
|
||||
params := map[string]interface{}{
|
||||
"Name": t.Name,
|
||||
"Filename": t.Name,
|
||||
@@ -960,7 +956,7 @@ func (t UploadFileTask) newAppError(id string, details interface{}, httpStatus i
|
||||
params[fmt.Sprintf("%v", extra[i])] = extra[i+1]
|
||||
}
|
||||
|
||||
return model.NewAppError("uploadFileTask", id, params, fmt.Sprintf("%v", details), httpStatus)
|
||||
return model.NewAppError("uploadFileTask", id, params, "", httpStatus)
|
||||
}
|
||||
|
||||
func (a *App) DoUploadFileExpectModification(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError) {
|
||||
|
||||
@@ -42,7 +42,7 @@ type TestHelper struct {
|
||||
tempWorkspace string
|
||||
}
|
||||
|
||||
func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer bool, tb testing.TB, configSet func(*model.Config)) *TestHelper {
|
||||
func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer bool, tb testing.TB) *TestHelper {
|
||||
tempWorkspace, err := ioutil.TempDir("", "apptest")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -51,9 +51,6 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
||||
configStore := config.NewTestMemoryStore()
|
||||
|
||||
config := configStore.Get()
|
||||
if configSet != nil {
|
||||
configSet(config)
|
||||
}
|
||||
*config.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins")
|
||||
*config.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp")
|
||||
*config.PluginSettings.AutomaticPrepackagedPlugins = false
|
||||
@@ -142,7 +139,7 @@ func Setup(tb testing.TB) *TestHelper {
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadMigrations()
|
||||
|
||||
return setupTestHelper(dbStore, false, true, tb, nil)
|
||||
return setupTestHelper(dbStore, false, true, tb)
|
||||
}
|
||||
|
||||
func SetupWithoutPreloadMigrations(tb testing.TB) *TestHelper {
|
||||
@@ -153,12 +150,12 @@ func SetupWithoutPreloadMigrations(tb testing.TB) *TestHelper {
|
||||
dbStore.DropAllTables()
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
|
||||
return setupTestHelper(dbStore, false, true, tb, nil)
|
||||
return setupTestHelper(dbStore, false, true, tb)
|
||||
}
|
||||
|
||||
func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
||||
mockStore := testlib.GetMockStoreForSetupFunctions()
|
||||
th := setupTestHelper(mockStore, false, false, tb, nil)
|
||||
th := setupTestHelper(mockStore, false, false, tb)
|
||||
emptyMockStore := mocks.Store{}
|
||||
emptyMockStore.On("Close").Return(nil)
|
||||
th.App.Srv().Store = &emptyMockStore
|
||||
@@ -167,7 +164,7 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
||||
|
||||
func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper {
|
||||
mockStore := testlib.GetMockStoreForSetupFunctions()
|
||||
th := setupTestHelper(mockStore, true, false, tb, nil)
|
||||
th := setupTestHelper(mockStore, true, false, tb)
|
||||
emptyMockStore := mocks.Store{}
|
||||
emptyMockStore.On("Close").Return(nil)
|
||||
th.App.Srv().Store = &emptyMockStore
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestStartServerSuccess(t *testing.T) {
|
||||
serverErr := s.Start()
|
||||
|
||||
client := &http.Client{}
|
||||
checkEndpoint(t, client, "http://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/", http.StatusNotFound)
|
||||
checkEndpoint(t, client, "http://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/")
|
||||
|
||||
s.Shutdown()
|
||||
require.NoError(t, serverErr)
|
||||
@@ -156,7 +156,7 @@ func TestStartServerTLSSuccess(t *testing.T) {
|
||||
}
|
||||
|
||||
client := &http.Client{Transport: tr}
|
||||
checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/", http.StatusNotFound)
|
||||
checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/")
|
||||
|
||||
s.Shutdown()
|
||||
require.NoError(t, serverErr)
|
||||
@@ -362,7 +362,7 @@ func TestStartServerTLSVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
client := &http.Client{Transport: tr}
|
||||
err = checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/", http.StatusNotFound)
|
||||
err = checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/")
|
||||
|
||||
if !strings.Contains(err.Error(), "remote error: tls: protocol version not supported") {
|
||||
t.Errorf("Expected protocol version error, got %s", err)
|
||||
@@ -374,7 +374,7 @@ func TestStartServerTLSVersion(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err = checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/", http.StatusNotFound)
|
||||
err = checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/")
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil, got %s", err)
|
||||
@@ -412,7 +412,7 @@ func TestStartServerTLSOverwriteCipher(t *testing.T) {
|
||||
}
|
||||
|
||||
client := &http.Client{Transport: tr}
|
||||
err = checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/", http.StatusNotFound)
|
||||
err = checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/")
|
||||
require.Error(t, err, "Expected error due to Cipher mismatch")
|
||||
if !strings.Contains(err.Error(), "remote error: tls: handshake failure") {
|
||||
t.Errorf("Expected protocol version error, got %s", err)
|
||||
@@ -429,7 +429,7 @@ func TestStartServerTLSOverwriteCipher(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err = checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/", http.StatusNotFound)
|
||||
err = checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/")
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil, got %s", err)
|
||||
@@ -439,7 +439,7 @@ func TestStartServerTLSOverwriteCipher(t *testing.T) {
|
||||
require.NoError(t, serverErr)
|
||||
}
|
||||
|
||||
func checkEndpoint(t *testing.T, client *http.Client, url string, expectedStatus int) error {
|
||||
func checkEndpoint(t *testing.T, client *http.Client, url string) error {
|
||||
res, err := client.Get(url)
|
||||
|
||||
if err != nil {
|
||||
@@ -448,8 +448,8 @@ func checkEndpoint(t *testing.T, client *http.Client, url string, expectedStatus
|
||||
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != expectedStatus {
|
||||
t.Errorf("Response code was %d; want %d", res.StatusCode, expectedStatus)
|
||||
if res.StatusCode != http.StatusNotFound {
|
||||
t.Errorf("Response code was %d; want %d", res.StatusCode, http.StatusNotFound)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
//nolint:unparam
|
||||
func generateSVGData(width int, height int, useViewBox bool, useDimensions bool, useAlternateFormat bool) io.Reader {
|
||||
var (
|
||||
viewBoxAttribute = ""
|
||||
@@ -64,7 +65,7 @@ func TestParseInvalidSVGData(t *testing.T) {
|
||||
invalidSVGs := []io.Reader{
|
||||
generateSVGData(width, height, false, false, false), // missing viewBox, width & height
|
||||
generateSVGData(width, 0, false, true, false), // missing viewBox, malformed width & height
|
||||
generateSVGData(300, 0, false, true, false), // missing viewBox, malformed height, properly formed width
|
||||
generateSVGData(width, 0, false, true, false), // missing viewBox, malformed height, properly formed width
|
||||
}
|
||||
for index, svg := range invalidSVGs {
|
||||
_, err := parseSVG(svg)
|
||||
|
||||
Ссылка в новой задаче
Block a user