mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
fix: Scheme test errcheck issues (#28553)
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
This commit is contained in:
parent
b1cde33d2c
commit
df925a3e6b
2 changed files with 54 additions and 30 deletions
|
|
@ -82,7 +82,6 @@ issues:
|
|||
channels/api4/role.go|\
|
||||
channels/api4/saml.go|\
|
||||
channels/api4/scheme.go|\
|
||||
channels/api4/scheme_test.go|\
|
||||
channels/api4/shared_channel.go|\
|
||||
channels/api4/system.go|\
|
||||
channels/api4/system_local.go|\
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ func TestCreateScheme(t *testing.T) {
|
|||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
err := th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Basic test of creating a team scheme.
|
||||
scheme1 := &model.Scheme{
|
||||
|
|
@ -175,7 +176,8 @@ func TestCreateScheme(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
err = th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.LoginSystemAdmin()
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
|
@ -204,7 +206,8 @@ func TestGetScheme(t *testing.T) {
|
|||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
err := th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -234,11 +237,13 @@ func TestGetScheme(t *testing.T) {
|
|||
_, r4, _ := th.SystemAdminClient.GetScheme(context.Background(), "12345")
|
||||
CheckBadRequestStatus(t, r4)
|
||||
|
||||
th.SystemAdminClient.Logout(context.Background())
|
||||
_, err = th.SystemAdminClient.Logout(context.Background())
|
||||
require.NoError(t, err)
|
||||
_, r5, _ := th.SystemAdminClient.GetScheme(context.Background(), s1.Id)
|
||||
CheckUnauthorizedStatus(t, r5)
|
||||
|
||||
th.SystemAdminClient.Login(context.Background(), th.SystemAdminUser.Username, th.SystemAdminUser.Password)
|
||||
_, _, err = th.SystemAdminClient.Login(context.Background(), th.SystemAdminUser.Username, th.SystemAdminUser.Password)
|
||||
require.NoError(t, err)
|
||||
th.App.Srv().SetLicense(nil)
|
||||
_, _, err = th.SystemAdminClient.GetScheme(context.Background(), s1.Id)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -247,7 +252,8 @@ func TestGetScheme(t *testing.T) {
|
|||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, r7)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
err = th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, r8, _ := th.SystemAdminClient.GetScheme(context.Background(), s1.Id)
|
||||
CheckNotImplementedStatus(t, r8)
|
||||
|
|
@ -273,9 +279,10 @@ func TestGetSchemes(t *testing.T) {
|
|||
Scope: model.SchemeScopeChannel,
|
||||
}
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
err := th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
_, _, err = th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.SystemAdminClient.CreateScheme(context.Background(), scheme2)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -302,16 +309,19 @@ func TestGetSchemes(t *testing.T) {
|
|||
_, r6, _ := th.SystemAdminClient.GetSchemes(context.Background(), "asdf", 0, 100)
|
||||
CheckBadRequestStatus(t, r6)
|
||||
|
||||
th.Client.Logout(context.Background())
|
||||
_, err = th.Client.Logout(context.Background())
|
||||
require.NoError(t, err)
|
||||
_, r7, _ := th.Client.GetSchemes(context.Background(), "", 0, 100)
|
||||
CheckUnauthorizedStatus(t, r7)
|
||||
|
||||
th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, _, err = th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
require.NoError(t, err)
|
||||
_, r8, err := th.Client.GetSchemes(context.Background(), "", 0, 100)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, r8)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
err = th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, r9, _ := th.SystemAdminClient.GetSchemes(context.Background(), "", 0, 100)
|
||||
CheckNotImplementedStatus(t, r9)
|
||||
|
|
@ -323,7 +333,8 @@ func TestGetTeamsForScheme(t *testing.T) {
|
|||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
err := th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
scheme1 := &model.Scheme{
|
||||
DisplayName: model.NewId(),
|
||||
|
|
@ -331,7 +342,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
|||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
scheme1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
scheme1, _, err = th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
||||
team1 := &model.Team{
|
||||
|
|
@ -383,11 +394,13 @@ func TestGetTeamsForScheme(t *testing.T) {
|
|||
_, ri2, _ := th.SystemAdminClient.GetTeamsForScheme(context.Background(), "", 0, 100)
|
||||
CheckBadRequestStatus(t, ri2)
|
||||
|
||||
th.Client.Logout(context.Background())
|
||||
_, err = th.Client.Logout(context.Background())
|
||||
require.NoError(t, err)
|
||||
_, ri3, _ := th.Client.GetTeamsForScheme(context.Background(), model.NewId(), 0, 100)
|
||||
CheckUnauthorizedStatus(t, ri3)
|
||||
|
||||
th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, _, err = th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
require.NoError(t, err)
|
||||
_, ri4, err := th.Client.GetTeamsForScheme(context.Background(), model.NewId(), 0, 100)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, ri4)
|
||||
|
|
@ -404,7 +417,8 @@ func TestGetTeamsForScheme(t *testing.T) {
|
|||
_, ri5, _ := th.SystemAdminClient.GetTeamsForScheme(context.Background(), scheme2.Id, 0, 100)
|
||||
CheckBadRequestStatus(t, ri5)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
err = th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, ri6, _ := th.SystemAdminClient.GetTeamsForScheme(context.Background(), scheme1.Id, 0, 100)
|
||||
CheckNotImplementedStatus(t, ri6)
|
||||
|
|
@ -416,7 +430,8 @@ func TestGetChannelsForScheme(t *testing.T) {
|
|||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
err := th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
scheme1 := &model.Scheme{
|
||||
DisplayName: model.NewId(),
|
||||
|
|
@ -424,7 +439,7 @@ func TestGetChannelsForScheme(t *testing.T) {
|
|||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeChannel,
|
||||
}
|
||||
scheme1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
scheme1, _, err = th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel1 := &model.Channel{
|
||||
|
|
@ -478,11 +493,13 @@ func TestGetChannelsForScheme(t *testing.T) {
|
|||
_, ri2, _ := th.SystemAdminClient.GetChannelsForScheme(context.Background(), "", 0, 100)
|
||||
CheckBadRequestStatus(t, ri2)
|
||||
|
||||
th.Client.Logout(context.Background())
|
||||
_, err = th.Client.Logout(context.Background())
|
||||
require.NoError(t, err)
|
||||
_, ri3, _ := th.Client.GetChannelsForScheme(context.Background(), model.NewId(), 0, 100)
|
||||
CheckUnauthorizedStatus(t, ri3)
|
||||
|
||||
th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, _, err = th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
require.NoError(t, err)
|
||||
_, ri4, err := th.Client.GetChannelsForScheme(context.Background(), model.NewId(), 0, 100)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, ri4)
|
||||
|
|
@ -499,7 +516,8 @@ func TestGetChannelsForScheme(t *testing.T) {
|
|||
_, ri5, _ := th.SystemAdminClient.GetChannelsForScheme(context.Background(), scheme2.Id, 0, 100)
|
||||
CheckBadRequestStatus(t, ri5)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
err = th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, ri6, _ := th.SystemAdminClient.GetChannelsForScheme(context.Background(), scheme1.Id, 0, 100)
|
||||
CheckNotImplementedStatus(t, ri6)
|
||||
|
|
@ -511,7 +529,8 @@ func TestPatchScheme(t *testing.T) {
|
|||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
err := th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Basic test of creating a team scheme.
|
||||
scheme1 := &model.Scheme{
|
||||
|
|
@ -622,7 +641,8 @@ func TestPatchScheme(t *testing.T) {
|
|||
_, _, err = th.SystemAdminClient.PatchScheme(context.Background(), s6.Id, schemePatch)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
err = th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.LoginSystemAdmin()
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
|
@ -638,7 +658,8 @@ func TestDeleteScheme(t *testing.T) {
|
|||
t.Run("ValidTeamScheme", func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
err := th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a team scheme.
|
||||
scheme1 := &model.Scheme{
|
||||
|
|
@ -716,7 +737,8 @@ func TestDeleteScheme(t *testing.T) {
|
|||
t.Run("ValidChannelScheme", func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
err := th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a channel scheme.
|
||||
scheme1 := &model.Scheme{
|
||||
|
|
@ -776,7 +798,8 @@ func TestDeleteScheme(t *testing.T) {
|
|||
t.Run("FailureCases", func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
err := th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
scheme1 := &model.Scheme{
|
||||
DisplayName: model.NewId(),
|
||||
|
|
@ -836,7 +859,8 @@ func TestDeleteScheme(t *testing.T) {
|
|||
_, err = th.SystemAdminClient.DeleteScheme(context.Background(), s2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
err = th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
|
|
@ -851,7 +875,8 @@ func TestUpdateTeamSchemeWithTeamMembers(t *testing.T) {
|
|||
defer th.TearDown()
|
||||
|
||||
t.Run("Correctly invalidates team member cache", func(t *testing.T) {
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
err := th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
team := th.CreateTeam()
|
||||
_, _, appErr := th.App.AddUserToTeam(th.Context, team.Id, th.BasicUser.Id, th.SystemAdminUser.Id)
|
||||
|
|
@ -867,7 +892,7 @@ func TestUpdateTeamSchemeWithTeamMembers(t *testing.T) {
|
|||
|
||||
th.LoginBasic()
|
||||
|
||||
_, _, err := th.Client.CreateChannel(context.Background(), &model.Channel{DisplayName: "Test API Name", Name: GenerateTestChannelName(), Type: model.ChannelTypeOpen, TeamId: team.Id})
|
||||
_, _, err = th.Client.CreateChannel(context.Background(), &model.Channel{DisplayName: "Test API Name", Name: GenerateTestChannelName(), Type: model.ChannelTypeOpen, TeamId: team.Id})
|
||||
require.NoError(t, err)
|
||||
|
||||
team.SchemeId = &teamScheme.Id
|
||||
|
|
|
|||
Loading…
Reference in a new issue