Skip to content

Commit

Permalink
Update emoji_test.go (fix errcheck issue) (mattermost#28440)
Browse files Browse the repository at this point in the history
Co-authored-by: Mattermost Build <build@mattermost.com>
  • Loading branch information
TheInvincibleRalph and mattermost-build authored Oct 8, 2024
1 parent 845159d commit 1d431e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
1 change: 0 additions & 1 deletion server/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ issues:
channels/api4/config_local.go|\
channels/api4/config_test.go|\
channels/api4/data_retention.go|\
channels/api4/emoji_test.go|\
channels/api4/export.go|\
channels/api4/export_test.go|\
channels/api4/file_test.go|\
Expand Down
32 changes: 21 additions & 11 deletions server/channels/api4/emoji_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ func TestDeleteEmoji(t *testing.T) {
th.RemovePermissionFromRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)
th.AddPermissionToRole(model.PermissionDeleteOthersEmojis.Id, model.SystemUserRoleId)

client.Logout(context.Background())
_, err = client.Logout(context.Background())
require.NoError(t, err)
th.LoginBasic2()

resp, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
Expand All @@ -439,7 +440,8 @@ func TestDeleteEmoji(t *testing.T) {
th.RemovePermissionFromRole(model.PermissionDeleteOthersEmojis.Id, model.SystemUserRoleId)
th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)

client.Logout(context.Background())
_, err = client.Logout(context.Background())
require.NoError(t, err)
th.LoginBasic()

//Try to delete other user's custom emoji without DELETE_OTHERS_EMOJIS permissions
Expand All @@ -451,14 +453,16 @@ func TestDeleteEmoji(t *testing.T) {
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
require.NoError(t, err)

client.Logout(context.Background())
_, err = client.Logout(context.Background())
require.NoError(t, err)
th.LoginBasic2()

resp, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
require.Error(t, err)
CheckForbiddenStatus(t, resp)

client.Logout(context.Background())
_, err = client.Logout(context.Background())
require.NoError(t, err)
th.LoginBasic()

//Try to delete other user's custom emoji with permissions
Expand All @@ -473,13 +477,15 @@ func TestDeleteEmoji(t *testing.T) {
th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)
th.AddPermissionToRole(model.PermissionDeleteOthersEmojis.Id, model.SystemUserRoleId)

client.Logout(context.Background())
_, err = client.Logout(context.Background())
require.NoError(t, err)
th.LoginBasic2()

_, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
require.NoError(t, err)

client.Logout(context.Background())
_, err = client.Logout(context.Background())
require.NoError(t, err)
th.LoginBasic()

//Try to delete my custom emoji with permissions at team level
Expand Down Expand Up @@ -508,7 +514,8 @@ func TestDeleteEmoji(t *testing.T) {
th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.TeamUserRoleId)
th.AddPermissionToRole(model.PermissionDeleteOthersEmojis.Id, model.TeamUserRoleId)

client.Logout(context.Background())
_, err = client.Logout(context.Background())
require.NoError(t, err)
th.LoginBasic2()

_, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
Expand Down Expand Up @@ -566,7 +573,8 @@ func TestGetEmojiByName(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.GetEmojiByName(context.Background(), newEmoji.Name)
require.Error(t, err)
CheckUnauthorizedStatus(t, resp)
Expand Down Expand Up @@ -742,7 +750,8 @@ func TestSearchEmoji(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.SearchEmoji(context.Background(), search)
require.Error(t, err)
CheckUnauthorizedStatus(t, resp)
Expand Down Expand Up @@ -775,7 +784,7 @@ func TestAutocompleteEmoji(t *testing.T) {
}

remojis, resp, err := client.AutocompleteEmoji(context.Background(), searchTerm1, "")
require.NoError(t, err)
require.NoErrorf(t, err, "AutocompleteEmoji failed with search term: %s", searchTerm1)
CheckOKStatus(t, resp)

found1 := false
Expand All @@ -797,7 +806,8 @@ func TestAutocompleteEmoji(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.AutocompleteEmoji(context.Background(), searchTerm1, "")
require.Error(t, err)
CheckUnauthorizedStatus(t, resp)
Expand Down

0 comments on commit 1d431e7

Please sign in to comment.