mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Use require/assert.Empty instead of require/assert.Len(t, X, 0) (#13413)
This commit is contained in:
@@ -653,11 +653,11 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) {
|
||||
// get posts from sysadmin1 and sysadmin2 DM channels
|
||||
posts1, err := th.App.GetPosts(channelSys1.Id, 0, 5)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, posts1.Order, 0)
|
||||
assert.Empty(t, posts1.Order)
|
||||
|
||||
posts2, err := th.App.GetPosts(channelSys2.Id, 0, 5)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, posts2.Order, 0)
|
||||
assert.Empty(t, posts2.Order)
|
||||
|
||||
// send notification for user with bots
|
||||
err = th.App.notifySysadminsBotOwnerDeactivated(user1.Id)
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -25,10 +26,10 @@ func TestHandleNewNotifications(t *testing.T) {
|
||||
|
||||
job.handleNewNotifications()
|
||||
|
||||
require.Len(t, job.pendingNotifications, 0, "shouldn't have added any pending notifications")
|
||||
require.Empty(t, job.pendingNotifications, "shouldn't have added any pending notifications")
|
||||
|
||||
job.Add(&model.User{Id: id1}, &model.Post{UserId: id1, Message: "test"}, &model.Team{Name: "team"})
|
||||
require.Len(t, job.pendingNotifications, 0, "shouldn't have added any pending notifications")
|
||||
require.Empty(t, job.pendingNotifications, "shouldn't have added any pending notifications")
|
||||
|
||||
job.handleNewNotifications()
|
||||
require.Len(t, job.pendingNotifications, 1, "should have received posts for 1 user")
|
||||
@@ -117,7 +118,7 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
job.checkPendingNotifications(time.Unix(10002, 0), func(string, []*batchedNotification) {})
|
||||
|
||||
require.Nil(t, job.pendingNotifications[th.BasicUser.Id])
|
||||
require.Len(t, job.pendingNotifications[th.BasicUser.Id], 0, "should've remove queued post since user acted")
|
||||
require.Empty(t, job.pendingNotifications[th.BasicUser.Id], "should've remove queued post since user acted")
|
||||
|
||||
// test that notifications are sent if enough time passes since the first message
|
||||
job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{
|
||||
@@ -210,7 +211,7 @@ func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
|
||||
// notifications should be sent 901s after post was created, because default batch interval is 15mins
|
||||
job.checkPendingNotifications(time.Unix(10901, 0), func(string, []*batchedNotification) {})
|
||||
require.Nil(t, job.pendingNotifications[th.BasicUser.Id])
|
||||
require.Len(t, job.pendingNotifications[th.BasicUser.Id], 0, "should have sent queued post")
|
||||
require.Empty(t, job.pendingNotifications[th.BasicUser.Id], "should have sent queued post")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -834,7 +834,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
|
||||
require.Equal(t, user.AuthData, data.AuthData, "Expected AuthData to be set.")
|
||||
|
||||
require.Len(t, user.Password, 0, "Expected password to be empty.")
|
||||
require.Empty(t, user.Password, "Expected password to be empty.")
|
||||
|
||||
require.True(t, user.EmailVerified, "Expected EmailVerified to be true.")
|
||||
|
||||
@@ -2190,7 +2190,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, len(posts), 1)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post := posts[0]
|
||||
require.Equal(t, post.Message, *data.Message)
|
||||
@@ -2205,7 +2205,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, len(posts), 1)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post = posts[0]
|
||||
require.Equal(t, post.Message, *data.Message)
|
||||
@@ -2233,7 +2233,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, len(posts), 1)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post = posts[0]
|
||||
require.Equal(t, post.Message, *data.Message)
|
||||
@@ -2262,7 +2262,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, len(posts), 1)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post = posts[0]
|
||||
checkPreference(t, th.App, th.BasicUser.Id, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id, "true")
|
||||
@@ -2361,7 +2361,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, len(posts), 1)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post = posts[0]
|
||||
require.Equal(t, post.Message, *data.Message)
|
||||
@@ -2376,7 +2376,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, len(posts), 1)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post = posts[0]
|
||||
require.Equal(t, post.Message, *data.Message)
|
||||
@@ -2404,7 +2404,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, len(posts), 1)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post = posts[0]
|
||||
require.Equal(t, post.Message, *data.Message)
|
||||
@@ -2434,7 +2434,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, len(posts), 1)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
post = posts[0]
|
||||
checkPreference(t, th.App, th.BasicUser.Id, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id, "true")
|
||||
@@ -2497,7 +2497,7 @@ func TestImportAttachment(t *testing.T) {
|
||||
assert.Nil(t, err, "sample run without errors")
|
||||
|
||||
attachments := GetAttachments(userId, th, t)
|
||||
assert.Equal(t, len(attachments), 1)
|
||||
assert.Len(t, attachments, 1)
|
||||
|
||||
data = AttachmentImportData{Path: &invalidPath}
|
||||
_, err = th.App.ImportAttachment(&data, &model.Post{UserId: model.NewId(), ChannelId: "some-channel"}, "some-team", true)
|
||||
@@ -2574,7 +2574,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
|
||||
attachments := GetAttachments(user3.Id, th, t)
|
||||
assert.Equal(t, len(attachments), 2)
|
||||
assert.Len(t, attachments, 2)
|
||||
assert.Contains(t, attachments[0].Path, team.Id)
|
||||
assert.Contains(t, attachments[1].Path, team.Id)
|
||||
AssertFileIdsInPost(attachments, th, t)
|
||||
@@ -2585,12 +2585,12 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
|
||||
attachments = GetAttachments(user3.Id, th, t)
|
||||
assert.Equal(t, len(attachments), 1)
|
||||
assert.Len(t, attachments, 1)
|
||||
assert.Contains(t, attachments[0].Path, team.Id)
|
||||
AssertFileIdsInPost(attachments, th, t)
|
||||
|
||||
attachments = GetAttachments(user4.Id, th, t)
|
||||
assert.Equal(t, len(attachments), 1)
|
||||
assert.Len(t, attachments, 1)
|
||||
assert.Contains(t, attachments[0].Path, team.Id)
|
||||
AssertFileIdsInPost(attachments, th, t)
|
||||
|
||||
@@ -2635,7 +2635,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
require.Nil(t, err, "Expected success.")
|
||||
|
||||
attachments = GetAttachments(user4.Id, th, t)
|
||||
assert.Equal(t, len(attachments), 1)
|
||||
assert.Len(t, attachments, 1)
|
||||
assert.Contains(t, attachments[0].Path, "noteam")
|
||||
AssertFileIdsInPost(attachments, th, t)
|
||||
}
|
||||
@@ -2690,7 +2690,7 @@ func TestImportDirectPostWithAttachments(t *testing.T) {
|
||||
require.Nil(t, err, "Expected success.")
|
||||
|
||||
attachments := GetAttachments(user1.Id, th, t)
|
||||
assert.Equal(t, len(attachments), 1)
|
||||
assert.Len(t, attachments, 1)
|
||||
assert.Contains(t, attachments[0].Path, "noteam")
|
||||
AssertFileIdsInPost(attachments, th, t)
|
||||
})
|
||||
@@ -2700,7 +2700,7 @@ func TestImportDirectPostWithAttachments(t *testing.T) {
|
||||
require.Nil(t, err, "Expected success.")
|
||||
|
||||
attachments := GetAttachments(user1.Id, th, t)
|
||||
assert.Equal(t, len(attachments), 1)
|
||||
assert.Len(t, attachments, 1)
|
||||
})
|
||||
|
||||
t.Run("Attempt to import again with same name and size but different content, SHOULD add an attachment", func(t *testing.T) {
|
||||
@@ -2719,7 +2719,7 @@ func TestImportDirectPostWithAttachments(t *testing.T) {
|
||||
require.Nil(t, err, "Expected success.")
|
||||
|
||||
attachments := GetAttachments(user1.Id, th, t)
|
||||
assert.Equal(t, len(attachments), 2)
|
||||
assert.Len(t, attachments, 2)
|
||||
})
|
||||
|
||||
t.Run("Attempt to import again with same data, SHOULD add an attachment, since it's different name", func(t *testing.T) {
|
||||
@@ -2738,6 +2738,6 @@ func TestImportDirectPostWithAttachments(t *testing.T) {
|
||||
require.Nil(t, err, "Expected success.")
|
||||
|
||||
attachments := GetAttachments(user1.Id, th, t)
|
||||
assert.Equal(t, len(attachments), 3)
|
||||
assert.Len(t, attachments, 3)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
th.BasicChannel.DeleteAt = 1
|
||||
mentions, err = th.App.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, mentions, 0)
|
||||
require.Empty(t, mentions)
|
||||
}
|
||||
|
||||
func TestSendNotificationsWithManyUsers(t *testing.T) {
|
||||
|
||||
@@ -528,7 +528,7 @@ func TestPluginSync(t *testing.T) {
|
||||
// Check if removed
|
||||
pluginStatus, err = env.Statuses()
|
||||
require.Nil(t, err)
|
||||
require.Len(t, pluginStatus, 0)
|
||||
require.Empty(t, pluginStatus)
|
||||
|
||||
// RequirePluginSignature = true case
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
@@ -544,7 +544,7 @@ func TestPluginSync(t *testing.T) {
|
||||
checkNoError(t, appErr)
|
||||
pluginStatus, err = env.Statuses()
|
||||
require.Nil(t, err)
|
||||
require.Len(t, pluginStatus, 0)
|
||||
require.Empty(t, pluginStatus)
|
||||
|
||||
// Wrong signature
|
||||
signatureFileReader, err := os.Open(filepath.Join(path, "testpluginv2.tar.gz.sig"))
|
||||
@@ -559,7 +559,7 @@ func TestPluginSync(t *testing.T) {
|
||||
|
||||
pluginStatus, err = env.Statuses()
|
||||
require.Nil(t, err)
|
||||
require.Len(t, pluginStatus, 0)
|
||||
require.Empty(t, pluginStatus)
|
||||
|
||||
// Correct signature
|
||||
key, err := os.Open(filepath.Join(path, "development-private-key.asc"))
|
||||
|
||||
@@ -132,11 +132,11 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
t.Run("populates all fields", func(t *testing.T) {
|
||||
assert.Equal(t, message, clientPost.Message, "shouldn't have changed Message")
|
||||
assert.NotEqual(t, nil, clientPost.Metadata, "should've populated Metadata")
|
||||
assert.Len(t, clientPost.Metadata.Embeds, 0, "should've populated Embeds")
|
||||
assert.Len(t, clientPost.Metadata.Reactions, 0, "should've populated Reactions")
|
||||
assert.Len(t, clientPost.Metadata.Files, 0, "should've populated Files")
|
||||
assert.Len(t, clientPost.Metadata.Emojis, 0, "should've populated Emojis")
|
||||
assert.Len(t, clientPost.Metadata.Images, 0, "should've populated Images")
|
||||
assert.Empty(t, clientPost.Metadata.Embeds, "should've populated Embeds")
|
||||
assert.Empty(t, clientPost.Metadata.Reactions, "should've populated Reactions")
|
||||
assert.Empty(t, clientPost.Metadata.Files, "should've populated Files")
|
||||
assert.Empty(t, clientPost.Metadata.Emojis, "should've populated Emojis")
|
||||
assert.Empty(t, clientPost.Metadata.Images, "should've populated Images")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -833,7 +833,7 @@ func TestGetViewUsersRestrictions(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.NotNil(t, restrictions)
|
||||
assert.Len(t, restrictions.Teams, 0)
|
||||
assert.Empty(t, restrictions.Teams)
|
||||
assert.NotNil(t, restrictions.Channels)
|
||||
assert.ElementsMatch(t, []string{team1townsquare.Id, team1offtopic.Id, team1channel1.Id, team1channel2.Id, team2townsquare.Id, team2offtopic.Id, team2channel1.Id}, restrictions.Channels)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user