Enable the errorAssertions govet check for mattermost-server code (#17346)

* Enable the errorAssertions govet check for mattermost-server code

* Removing unnecesary change

* Fixing some tests

* Fixing tests

* Fixing more after merge

* Fixing new offending entries

* Fixing small vet checks

* Fixing new cases detected by govet

* Fixing remote_cluster_test errors

* Fixing assertion

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Jesús Espino
2021-04-12 12:51:31 +02:00
коммит произвёл GitHub
родитель e37e902ddf
Коммит 35d00b4644
22 изменённых файлов: 202 добавлений и 199 удалений

Просмотреть файл

@@ -1689,7 +1689,7 @@ func TestPatchChannelModerationsForChannel(t *testing.T) {
},
},
{
Name: "Removing manage members from guests role should error",
Name: "Removing manage members from guests role should not error",
ChannelModerationsPatch: []*model.ChannelModerationPatch{
{
Name: &manageMembers,
@@ -1697,10 +1697,11 @@ func TestPatchChannelModerationsForChannel(t *testing.T) {
},
},
PermissionsModeratedByPatch: map[string]*model.ChannelModeratedRoles{},
ShouldError: true,
ShouldError: false,
ShouldHaveNoChannelScheme: true,
},
{
Name: "Removing a permission that is not channel moderated should error",
Name: "Removing a permission that is not channel moderated should not error",
ChannelModerationsPatch: []*model.ChannelModerationPatch{
{
Name: &nonChannelModeratedPermission,
@@ -1711,7 +1712,8 @@ func TestPatchChannelModerationsForChannel(t *testing.T) {
},
},
PermissionsModeratedByPatch: map[string]*model.ChannelModeratedRoles{},
ShouldError: true,
ShouldError: false,
ShouldHaveNoChannelScheme: true,
},
{
Name: "Error when adding a permission that is disabled in the parent member role",
@@ -1829,12 +1831,12 @@ func TestPatchChannelModerationsForChannel(t *testing.T) {
}
}
moderations, err := th.App.PatchChannelModerationsForChannel(channel, tc.ChannelModerationsPatch)
moderations, appErr := th.App.PatchChannelModerationsForChannel(channel, tc.ChannelModerationsPatch)
if tc.ShouldError {
require.Error(t, err)
require.NotNil(t, appErr)
return
}
require.Nil(t, err)
require.Nil(t, appErr)
updatedChannel, _ := th.App.GetChannel(channel.Id)
if tc.ShouldHaveNoChannelScheme {

Просмотреть файл

@@ -283,7 +283,7 @@ func TestCreateZipFileAndAddFiles(t *testing.T) {
err := th.App.CreateZipFileAndAddFiles(&mockBackend, []model.FileData{}, "zip-file-name-to-heaven.zip", "directory-to-heaven")
require.NotNil(t, err)
require.Error(t, err)
require.Equal(t, err.Error(), "only those who dare to fail greatly can ever achieve greatly")
mockBackend = filesStoreMocks.FileBackend{}
@@ -371,7 +371,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) {
})
time.Sleep(1 * time.Millisecond)
require.Nil(t, err)
require.NoError(t, err)
fileInfos[i] = fileInfo
}

Просмотреть файл

@@ -2030,26 +2030,26 @@ func TestReplyToPostWithLag(t *testing.T) {
t.Run("replication lag time great than reply time", func(t *testing.T) {
err := mainHelper.SetReplicationLagForTesting(5)
require.Nil(t, err)
require.NoError(t, err)
defer mainHelper.SetReplicationLagForTesting(0)
mainHelper.ToggleReplicasOn()
defer mainHelper.ToggleReplicasOff()
root, err := th.App.CreatePost(&model.Post{
root, appErr := th.App.CreatePost(&model.Post{
UserId: th.BasicUser.Id,
ChannelId: th.BasicChannel.Id,
Message: "root post",
}, th.BasicChannel, false, true)
require.Nil(t, err)
require.Nil(t, appErr)
reply, err := th.App.CreatePost(&model.Post{
reply, appErr := th.App.CreatePost(&model.Post{
UserId: th.BasicUser2.Id,
ChannelId: th.BasicChannel.Id,
RootId: root.Id,
ParentId: root.Id,
Message: fmt.Sprintf("@%s", th.BasicUser2.Username),
}, th.BasicChannel, false, true)
require.Nil(t, err)
require.Nil(t, appErr)
require.NotNil(t, reply)
})
}

Просмотреть файл

@@ -32,7 +32,7 @@ func TestAddRemoteCluster(t *testing.T) {
remoteCluster.RemoteId = model.NewId()
_, err = th.App.AddRemoteCluster(remoteCluster)
require.Error(t, err, "Adding a duplicate remote cluster should error")
require.NotNil(t, err, "Adding a duplicate remote cluster should error")
assert.Contains(t, err.Error(), "Remote cluster has already been added.")
})
@@ -103,7 +103,7 @@ func TestUpdateRemoteCluster(t *testing.T) {
savedRemoteClustered.SiteURL = remoteCluster.SiteURL
savedRemoteClustered.RemoteTeamId = remoteCluster.RemoteTeamId
_, err = th.App.UpdateRemoteCluster(savedRemoteClustered)
require.Error(t, err, "Updating remote cluster with duplicate site url should error")
require.NotNil(t, err, "Updating remote cluster with duplicate site url should error")
assert.Contains(t, err.Error(), "Remote cluster with the same url already exists.")
})

Просмотреть файл

@@ -173,10 +173,10 @@ func TestStartServerNoS3Bucket(t *testing.T) {
require.NoError(t, err)
// ensure that a new bucket was created
backend, err := s.FileBackend()
require.Nil(t, err)
backend, appErr := s.FileBackend()
require.Nil(t, appErr)
err = backend.(*filestore.S3FileBackend).TestConnection()
require.Nil(t, err)
require.NoError(t, err)
}
func TestStartServerTLSSuccess(t *testing.T) {

Просмотреть файл

@@ -465,13 +465,13 @@ func TestGetRemoteClusterSession(t *testing.T) {
t.Run("Invalid remote token should return error", func(t *testing.T) {
session, err := th.App.GetRemoteClusterSession(model.NewId(), remoteId)
require.Error(t, err)
require.NotNil(t, err)
require.Nil(t, session)
})
t.Run("Invalid remote id should return error", func(t *testing.T) {
session, err := th.App.GetRemoteClusterSession(token, model.NewId())
require.Error(t, err)
require.NotNil(t, err)
require.Nil(t, session)
})
}

Просмотреть файл

@@ -118,7 +118,8 @@ func TestSetDefaultProfileImage(t *testing.T) {
Id: model.NewId(),
Username: "notvaliduser",
})
require.Error(t, err)
// It doesn't fail, but it does nothing
require.Nil(t, err)
user := th.BasicUser