Replacing require.nil in app layer (#16905)

* Replacing require.nil in app layer

* Fixing some tests

* Fixing tests

* Reverting the error correction, defering it for another PR

* Fixing golangci-lint errors

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Jesús Espino
2021-02-16 12:00:01 +01:00
коммит произвёл GitHub
родитель fd2e75bc5b
Коммит 69ff686667
35 изменённых файлов: 753 добавлений и 720 удалений

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

@@ -80,7 +80,7 @@ func TestSendNotifications(t *testing.T) {
Props: model.StringInterface{"from_webhook": "true", "override_username": "a bot"},
}
rootPost, appErr := th.App.CreatePostMissingChannel(rootPost, false)
rootPost, appErr = th.App.CreatePostMissingChannel(rootPost, false)
require.Nil(t, appErr)
childPost := &model.Post{
@@ -97,20 +97,20 @@ func TestSendNotifications(t *testing.T) {
Posts: map[string]*model.Post{rootPost.Id: rootPost, childPost.Id: childPost},
}
mentions, err = th.App.SendNotifications(childPost, th.BasicTeam, th.BasicChannel, th.BasicUser2, &postList, true)
require.Nil(t, err)
require.NoError(t, err)
require.False(t, utils.StringInSlice(user.Id, mentions))
}
th.BasicUser.NotifyProps[model.COMMENTS_NOTIFY_PROP] = model.COMMENTS_NOTIFY_ANY
th.BasicUser, err = th.App.UpdateUser(th.BasicUser, false)
require.Nil(t, err)
th.BasicUser, appErr = th.App.UpdateUser(th.BasicUser, false)
require.Nil(t, appErr)
t.Run("user wants notifications on all comments", func(t *testing.T) {
testUserNotNotified(t, th.BasicUser)
})
th.BasicUser.NotifyProps[model.COMMENTS_NOTIFY_PROP] = model.COMMENTS_NOTIFY_ROOT
th.BasicUser, err = th.App.UpdateUser(th.BasicUser, false)
require.Nil(t, err)
th.BasicUser, appErr = th.App.UpdateUser(th.BasicUser, false)
require.Nil(t, appErr)
t.Run("user wants notifications on root comment", func(t *testing.T) {
testUserNotNotified(t, th.BasicUser)
})
@@ -143,7 +143,7 @@ func TestSendNotificationsWithManyUsers(t *testing.T) {
for i, user := range users {
t.Run(fmt.Sprintf("user-%d", i+1), func(t *testing.T) {
channelUnread, appErr2 := th.Server.Store.Channel().GetChannelUnread(th.BasicChannel.Id, user.Id)
require.Nil(t, appErr2)
require.NoError(t, appErr2)
assert.Equal(t, int64(1), channelUnread.MentionCount)
})
}
@@ -163,7 +163,7 @@ func TestSendNotificationsWithManyUsers(t *testing.T) {
for i, user := range users {
t.Run(fmt.Sprintf("user-%d", i+1), func(t *testing.T) {
channelUnread, appErr2 := th.Server.Store.Channel().GetChannelUnread(th.BasicChannel.Id, user.Id)
require.Nil(t, appErr2)
require.NoError(t, appErr2)
assert.Equal(t, int64(2), channelUnread.MentionCount)
})
}
@@ -185,7 +185,7 @@ func TestSendOutOfChannelMentions(t *testing.T) {
sent, err := th.App.sendOutOfChannelMentions(user1, post, channel, potentialMentions)
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, sent)
})
@@ -195,7 +195,7 @@ func TestSendOutOfChannelMentions(t *testing.T) {
sent, err := th.App.sendOutOfChannelMentions(user1, post, channel, potentialMentions)
assert.Nil(t, err)
assert.NoError(t, err)
assert.False(t, sent)
})
}
@@ -226,7 +226,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, channel, potentialMentions)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Len(t, outOfChannelUsers, 2)
assert.True(t, (outOfChannelUsers[0].Id == user2.Id || outOfChannelUsers[1].Id == user2.Id))
assert.True(t, (outOfChannelUsers[0].Id == user3.Id || outOfChannelUsers[1].Id == user3.Id))
@@ -239,7 +239,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(guest, post, channel, potentialMentions)
require.Nil(t, err)
require.NoError(t, err)
require.Len(t, outOfChannelUsers, 1)
assert.Equal(t, user4.Id, outOfChannelUsers[0].Id)
assert.Nil(t, outOfGroupUsers)
@@ -253,7 +253,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, channel, potentialMentions)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Nil(t, outOfChannelUsers)
assert.Nil(t, outOfGroupUsers)
})
@@ -267,7 +267,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, directChannel, potentialMentions)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Nil(t, outOfChannelUsers)
assert.Nil(t, outOfGroupUsers)
})
@@ -281,7 +281,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, groupChannel, potentialMentions)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Nil(t, outOfChannelUsers)
assert.Nil(t, outOfGroupUsers)
})
@@ -296,7 +296,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, channel, potentialMentions)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Nil(t, outOfChannelUsers)
assert.Nil(t, outOfGroupUsers)
})
@@ -310,7 +310,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, channel, potentialMentions)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Nil(t, outOfChannelUsers)
assert.Nil(t, outOfGroupUsers)
})
@@ -321,7 +321,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, channel, potentialMentions)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Nil(t, outOfChannelUsers)
assert.Nil(t, outOfGroupUsers)
})
@@ -355,7 +355,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, constrainedChannel, potentialMentions)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Len(t, outOfChannelUsers, 1)
assert.Equal(t, nonChannelMember.Id, outOfChannelUsers[0].Id)
assert.Len(t, outOfGroupUsers, 1)
@@ -2519,7 +2519,7 @@ func TestGetGroupsAllowedForReferenceInChannel(t *testing.T) {
t.Run("should return empty map when no groups with allow reference", func(t *testing.T) {
groupsMap, nErr := th.App.getGroupsAllowedForReferenceInChannel(channel, team)
require.Nil(t, nErr)
require.NoError(t, nErr)
require.Len(t, groupsMap, 0)
})
@@ -2530,7 +2530,7 @@ func TestGetGroupsAllowedForReferenceInChannel(t *testing.T) {
group2 := th.CreateGroup()
t.Run("should only return groups with allow reference", func(t *testing.T) {
groupsMap, nErr := th.App.getGroupsAllowedForReferenceInChannel(channel, team)
require.Nil(t, nErr)
require.NoError(t, nErr)
require.Len(t, groupsMap, 1)
require.Nil(t, groupsMap[*group2.Name])
require.Equal(t, groupsMap[*group1.Name], group1)
@@ -2554,7 +2554,7 @@ func TestGetGroupsAllowedForReferenceInChannel(t *testing.T) {
t.Run("should return only groups synced to channel if channel is group constrained", func(t *testing.T) {
groupsMap, nErr := th.App.getGroupsAllowedForReferenceInChannel(constrainedChannel, team)
require.Nil(t, nErr)
require.NoError(t, nErr)
require.Len(t, groupsMap, 1)
require.Nil(t, groupsMap[*group2.Name])
require.Equal(t, groupsMap[*group1.Name], group1)
@@ -2579,7 +2579,7 @@ func TestGetGroupsAllowedForReferenceInChannel(t *testing.T) {
t.Run("should return union of groups synced to team and any channels if team is group constrained", func(t *testing.T) {
groupsMap, nErr := th.App.getGroupsAllowedForReferenceInChannel(channel, team)
require.Nil(t, nErr)
require.NoError(t, nErr)
require.Len(t, groupsMap, 2)
require.Nil(t, groupsMap[*group3.Name])
require.Equal(t, groupsMap[*group2.Name], group2)
@@ -2588,7 +2588,7 @@ func TestGetGroupsAllowedForReferenceInChannel(t *testing.T) {
t.Run("should return only subset of groups synced to channel for group constrained channel when team is also group constrained", func(t *testing.T) {
groupsMap, nErr := th.App.getGroupsAllowedForReferenceInChannel(constrainedChannel, team)
require.Nil(t, nErr)
require.NoError(t, nErr)
require.Len(t, groupsMap, 1)
require.Nil(t, groupsMap[*group3.Name])
require.Nil(t, groupsMap[*group2.Name])
@@ -2601,7 +2601,7 @@ func TestGetGroupsAllowedForReferenceInChannel(t *testing.T) {
t.Run("should return all groups when team and channel are not group constrained", func(t *testing.T) {
groupsMap, nErr := th.App.getGroupsAllowedForReferenceInChannel(channel, team)
require.Nil(t, nErr)
require.NoError(t, nErr)
require.Len(t, groupsMap, 3)
require.Equal(t, groupsMap[*group1.Name], group1)
require.Equal(t, groupsMap[*group2.Name], group2)