Skip to content

Commit

Permalink
fix: role test errcheck issues (mattermost#28545)
Browse files Browse the repository at this point in the history
Co-authored-by: Mattermost Build <build@mattermost.com>
  • Loading branch information
RS-labhub and mattermost-build authored Oct 14, 2024
1 parent 0668df0 commit abf6042
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
4 changes: 3 additions & 1 deletion server/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ issues:
channels/api4/preference_test.go|\
channels/api4/reaction_test.go|\
channels/api4/remote_cluster.go|\
channels/api4/role_test.go|\
channels/api4/role.go|\
channels/api4/saml.go|\
channels/api4/scheme.go|\
channels/api4/scheme_test.go|\
channels/api4/shared_channel.go|\
channels/api4/status.go|\
Expand Down
40 changes: 32 additions & 8 deletions server/channels/api4/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ func TestGetRole(t *testing.T) {

role, err := th.App.Srv().Store().Role().Save(role)
require.NoError(t, err)
defer th.App.Srv().Store().Job().Delete(role.Id)
defer func() {
_, err := th.App.Srv().Store().Job().Delete(role.Id)
require.NoError(t, err)
}()

th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
received, _, err := client.GetRole(context.Background(), role.Id)
Expand Down Expand Up @@ -91,7 +94,10 @@ func TestGetRoleByName(t *testing.T) {

role, err := th.App.Srv().Store().Role().Save(role)
assert.NoError(t, err)
defer th.App.Srv().Store().Job().Delete(role.Id)
defer func() {
_, err := th.App.Srv().Store().Job().Delete(role.Id)
require.NoError(t, err)
}()

th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
received, _, err := client.GetRoleByName(context.Background(), role.Name)
Expand Down Expand Up @@ -144,15 +150,24 @@ func TestGetRolesByNames(t *testing.T) {

role1, err := th.App.Srv().Store().Role().Save(role1)
assert.NoError(t, err)
defer th.App.Srv().Store().Job().Delete(role1.Id)
defer func() {
_, err = th.App.Srv().Store().Job().Delete(role1.Id)
require.NoError(t, err)
}()

role2, err = th.App.Srv().Store().Role().Save(role2)
assert.NoError(t, err)
defer th.App.Srv().Store().Job().Delete(role2.Id)
defer func() {
_, err = th.App.Srv().Store().Job().Delete(role2.Id)
require.NoError(t, err)
}()

role3, err = th.App.Srv().Store().Role().Save(role3)
assert.NoError(t, err)
defer th.App.Srv().Store().Job().Delete(role3.Id)
defer func() {
_, err = th.App.Srv().Store().Job().Delete(role3.Id)
require.NoError(t, err)
}()

th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
// Check all three roles can be found.
Expand Down Expand Up @@ -213,7 +228,10 @@ func TestPatchRole(t *testing.T) {

role, err2 := th.App.Srv().Store().Role().Save(role)
assert.NoError(t, err2)
defer th.App.Srv().Store().Job().Delete(role.Id)
defer func() {
_, err := th.App.Srv().Store().Job().Delete(role.Id)
require.NoError(t, err)
}()

patch := &model.RolePatch{
Permissions: &[]string{"create_direct_channel", "create_public_channel", "manage_incoming_webhooks", "manage_outgoing_webhooks"},
Expand All @@ -223,7 +241,10 @@ func TestPatchRole(t *testing.T) {
// Cannot edit a system admin
adminRole, err := th.App.Srv().Store().Role().GetByName(context.Background(), "system_admin")
assert.NoError(t, err)
defer th.App.Srv().Store().Job().Delete(adminRole.Id)
defer func() {
_, err = th.App.Srv().Store().Job().Delete(adminRole.Id)
require.NoError(t, err)
}()

_, resp, err := client.PatchRole(context.Background(), adminRole.Id, patch)
require.Error(t, err)
Expand All @@ -232,7 +253,10 @@ func TestPatchRole(t *testing.T) {
// Cannot give other roles read / write to system roles or manage roles because only system admin can do these actions
systemManager, err := th.App.Srv().Store().Role().GetByName(context.Background(), "system_manager")
assert.NoError(t, err)
defer th.App.Srv().Store().Job().Delete(systemManager.Id)
defer func() {
_, err = th.App.Srv().Store().Job().Delete(systemManager.Id)
require.NoError(t, err)
}()

patchWriteSystemRoles := &model.RolePatch{
Permissions: &[]string{model.PermissionSysconsoleWriteUserManagementSystemRoles.Id},
Expand Down

0 comments on commit abf6042

Please sign in to comment.