diff --git a/server/.golangci.yml b/server/.golangci.yml index 769f614822..decb04f764 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -70,7 +70,6 @@ issues: channels/api4/config_local.go|\ channels/api4/config_test.go|\ channels/api4/data_retention.go|\ - channels/api4/file_test.go|\ channels/api4/job_test.go|\ channels/api4/post_test.go|\ channels/api4/preference_test.go|\ diff --git a/server/channels/api4/file_test.go b/server/channels/api4/file_test.go index 27ba615d15..735b81bbaa 100644 --- a/server/channels/api4/file_test.go +++ b/server/channels/api4/file_test.go @@ -728,13 +728,16 @@ func TestUploadFiles(t *testing.T) { if !tc.skipPayloadValidation { compare := func(get func(context.Context, string) ([]byte, *model.Response, error), name string) { - data, _, err := get(context.Background(), ri.Id) + var data []byte + data, _, err = get(context.Background(), ri.Id) require.NoError(t, err) - expected, err := os.ReadFile(filepath.Join(testDir, name)) + var expected []byte + expected, err = os.ReadFile(filepath.Join(testDir, name)) require.NoError(t, err) if !bytes.Equal(data, expected) { - tf, err := os.CreateTemp("", fmt.Sprintf("test_%v_*_%s", i, name)) + var tf *os.File + tf, err = os.CreateTemp("", fmt.Sprintf("test_%v_*_%s", i, name)) require.NoError(t, err) defer tf.Close() _, err = io.Copy(tf, bytes.NewReader(data)) @@ -755,7 +758,8 @@ func TestUploadFiles(t *testing.T) { } } - th.cleanupTestFile(dbInfo) + err = th.cleanupTestFile(dbInfo) + require.NoError(t, err) } }) } @@ -796,7 +800,8 @@ func TestGetFile(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetFile(context.Background(), fileId) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -904,18 +909,21 @@ func TestGetFileThumbnail(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetFileThumbnail(context.Background(), fileId) require.Error(t, err) CheckUnauthorizedStatus(t, resp) otherUser := th.CreateUser() - client.Login(context.Background(), otherUser.Email, otherUser.Password) + _, _, err = client.Login(context.Background(), otherUser.Email, otherUser.Password) + require.NoError(t, err) _, resp, err = client.GetFileThumbnail(context.Background(), fileId) require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, _, err = th.SystemAdminClient.GetFileThumbnail(context.Background(), fileId) require.NoError(t, err) CheckForbiddenStatus(t, resp) @@ -968,24 +976,28 @@ func TestGetFileLink(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetFileLink(context.Background(), fileId) require.Error(t, err) CheckUnauthorizedStatus(t, resp) otherUser := th.CreateUser() - client.Login(context.Background(), otherUser.Email, otherUser.Password) + _, _, err = client.Login(context.Background(), otherUser.Email, otherUser.Password) + require.NoError(t, err) _, resp, err = client.GetFileLink(context.Background(), fileId) require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, _, err = th.SystemAdminClient.GetFileLink(context.Background(), fileId) require.NoError(t, err) fileInfo, err := th.App.Srv().Store().FileInfo().Get(fileId) require.NoError(t, err) - th.cleanupTestFile(fileInfo) + err = th.cleanupTestFile(fileInfo) + require.NoError(t, err) } func TestGetFilePreview(t *testing.T) { @@ -1017,18 +1029,21 @@ func TestGetFilePreview(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetFilePreview(context.Background(), fileId) require.Error(t, err) CheckUnauthorizedStatus(t, resp) otherUser := th.CreateUser() - client.Login(context.Background(), otherUser.Email, otherUser.Password) + _, _, err = client.Login(context.Background(), otherUser.Email, otherUser.Password) + require.NoError(t, err) _, resp, err = client.GetFilePreview(context.Background(), fileId) require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, _, err = th.SystemAdminClient.GetFilePreview(context.Background(), fileId) require.NoError(t, err) CheckForbiddenStatus(t, resp) @@ -1071,18 +1086,21 @@ func TestGetFileInfo(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetFileInfo(context.Background(), fileId) require.Error(t, err) CheckUnauthorizedStatus(t, resp) otherUser := th.CreateUser() - client.Login(context.Background(), otherUser.Email, otherUser.Password) + _, _, err = client.Login(context.Background(), otherUser.Email, otherUser.Password) + require.NoError(t, err) _, resp, err = client.GetFileInfo(context.Background(), fileId) require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, _, err = th.SystemAdminClient.GetFileInfo(context.Background(), fileId) require.NoError(t, err) CheckForbiddenStatus(t, resp) @@ -1143,11 +1161,8 @@ func TestGetPublicFile(t *testing.T) { require.NoError(t, err) require.Equal(t, http.StatusBadRequest, resp.StatusCode, "should've failed to get image with public link after salt changed") - fileInfo, err := th.App.Srv().Store().FileInfo().Get(fileId) + err = th.cleanupTestFile(info) require.NoError(t, err) - require.NoError(t, th.cleanupTestFile(fileInfo)) - - th.cleanupTestFile(info) link = th.App.GeneratePublicLink(client.URL, info) resp, err = http.Get(link) require.NoError(t, err) @@ -1204,7 +1219,8 @@ func TestSearchFiles(t *testing.T) { require.NoError(t, err) err = th.App.Srv().Store().FileInfo().AttachToPost(th.Context, fileInfo5.Id, rpost.Id, rpost.ChannelId, th.BasicUser.Id) require.NoError(t, err) - th.Client.DeleteChannel(context.Background(), archivedChannel.Id) + _, err = th.Client.DeleteChannel(context.Background(), archivedChannel.Id) + require.NoError(t, err) terms := "search" isOrSearch := false @@ -1296,7 +1312,8 @@ func TestSearchFiles(t *testing.T) { require.Error(t, err) CheckBadRequestStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.SearchFiles(context.Background(), th.BasicTeam.Id, "#sgtitlereview", false) require.Error(t, err) CheckUnauthorizedStatus(t, resp)