[MM-62408] Server Code Coverage with Fully Parallel Tests (#30078)
* TestPool * Store infra * Store tests updates * Bump maximum concurrent postgres connections * More infra * channels/jobs * channels/app * channels/api4 * Protect i18n from concurrent access * Replace some use of os.Setenv * Remove debug * Lint fixes * Fix more linting * Fix test * Remove use of Setenv in drafts tests * Fix flaky TestWebHubCloseConnOnDBFail * Fix merge * [MM-62408] Add CI job to generate test coverage (#30284) * Add CI job to generate test coverage * Remove use of Setenv in drafts tests * Fix flaky TestWebHubCloseConnOnDBFail * Fix more Setenv usage * Fix more potential flakyness * Remove parallelism from flaky test * Remove conflicting env var * Fix * Disable parallelism * Test atomic covermode * Disable parallelism * Enable parallelism * Add upload coverage step * Fix codecov.yml * Add codecov.yml * Remove redundant workspace field * Add Parallel() util methods and refactor * Fix formatting * More formatting fixes * Fix reporting
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1cf2f08108
Коммит
611b2a8e79
@@ -14,6 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCreateIncomingWebhook(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
@@ -108,6 +109,7 @@ func TestCreateIncomingWebhook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateIncomingWebhook_BypassTeamPermissions(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -145,6 +147,7 @@ func TestCreateIncomingWebhook_BypassTeamPermissions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetIncomingWebhooks(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
@@ -223,6 +226,7 @@ func TestGetIncomingWebhooks(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetIncomingWebhooksListByUser(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
BasicClient := th.Client
|
||||
@@ -258,7 +262,7 @@ func TestGetIncomingWebhooksListByUser(t *testing.T) {
|
||||
assert.Equal(t, 2, len(adminHooks))
|
||||
})
|
||||
|
||||
//Re-check basic user that has no MANAGE_OTHERS permission
|
||||
// Re-check basic user that has no MANAGE_OTHERS permission
|
||||
filteredHooks, _, err := BasicClient.GetIncomingWebhooks(context.Background(), 0, 1000, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(filteredHooks))
|
||||
@@ -266,6 +270,7 @@ func TestGetIncomingWebhooksListByUser(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetIncomingWebhooksByTeam(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
BasicClient := th.Client
|
||||
@@ -300,7 +305,7 @@ func TestGetIncomingWebhooksByTeam(t *testing.T) {
|
||||
assert.Equal(t, 2, len(adminHooks))
|
||||
})
|
||||
|
||||
//Re-check basic user that has no MANAGE_OTHERS permission
|
||||
// Re-check basic user that has no MANAGE_OTHERS permission
|
||||
filteredHooks, _, err := BasicClient.GetIncomingWebhooksForTeam(context.Background(), th.BasicTeam.Id, 0, 1000, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(filteredHooks))
|
||||
@@ -308,6 +313,7 @@ func TestGetIncomingWebhooksByTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetIncomingWebhooksWithCount(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
BasicClient := th.Client
|
||||
@@ -362,6 +368,7 @@ func TestGetIncomingWebhooksWithCount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetIncomingWebhook(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -398,13 +405,14 @@ func TestGetIncomingWebhook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteIncomingWebhook(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||
|
||||
//var rhook *model.IncomingWebhook
|
||||
//var hook *model.IncomingWebhook
|
||||
// var rhook *model.IncomingWebhook
|
||||
// var hook *model.IncomingWebhook
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
resp, err := client.DeleteIncomingWebhook(context.Background(), "abc")
|
||||
@@ -449,6 +457,7 @@ func TestDeleteIncomingWebhook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateOutgoingWebhook(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
@@ -533,6 +542,7 @@ func TestCreateOutgoingWebhook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOutgoingWebhooks(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -632,6 +642,7 @@ func TestGetOutgoingWebhooks(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOutgoingWebhooksByTeam(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -665,7 +676,7 @@ func TestGetOutgoingWebhooksByTeam(t *testing.T) {
|
||||
assert.Equal(t, 2, len(adminHooks))
|
||||
})
|
||||
|
||||
//Re-check basic user that has no MANAGE_OTHERS permission
|
||||
// Re-check basic user that has no MANAGE_OTHERS permission
|
||||
filteredHooks, _, err := th.Client.GetOutgoingWebhooksForTeam(context.Background(), th.BasicTeam.Id, 0, 1000, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(filteredHooks))
|
||||
@@ -673,6 +684,7 @@ func TestGetOutgoingWebhooksByTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOutgoingWebhooksByChannel(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -706,7 +718,7 @@ func TestGetOutgoingWebhooksByChannel(t *testing.T) {
|
||||
assert.Equal(t, 2, len(adminHooks))
|
||||
})
|
||||
|
||||
//Re-check basic user that has no MANAGE_OTHERS permission
|
||||
// Re-check basic user that has no MANAGE_OTHERS permission
|
||||
filteredHooks, _, err := th.Client.GetOutgoingWebhooksForChannel(context.Background(), th.BasicChannel.Id, 0, 1000, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(filteredHooks))
|
||||
@@ -714,6 +726,7 @@ func TestGetOutgoingWebhooksByChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOutgoingWebhooksListByUser(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
th.LoginBasic()
|
||||
@@ -748,7 +761,7 @@ func TestGetOutgoingWebhooksListByUser(t *testing.T) {
|
||||
assert.Equal(t, 2, len(adminHooks))
|
||||
})
|
||||
|
||||
//Re-check basic user that has no MANAGE_OTHERS permission
|
||||
// Re-check basic user that has no MANAGE_OTHERS permission
|
||||
filteredHooks, _, err := th.Client.GetOutgoingWebhooks(context.Background(), 0, 1000, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(filteredHooks))
|
||||
@@ -756,6 +769,7 @@ func TestGetOutgoingWebhooksListByUser(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOutgoingWebhook(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -791,6 +805,7 @@ func TestGetOutgoingWebhook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateIncomingHook(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -834,7 +849,7 @@ func TestUpdateIncomingHook(t *testing.T) {
|
||||
require.Empty(t, updatedHook.Username, "Hook username was incorrectly updated")
|
||||
require.Empty(t, updatedHook.IconURL, "Hook icon was incorrectly updated")
|
||||
|
||||
//updatedHook, _ = th.App.GetIncomingWebhook(createdHook.Id)
|
||||
// updatedHook, _ = th.App.GetIncomingWebhook(createdHook.Id)
|
||||
assert.Equal(t, updatedHook.ChannelId, createdHook.ChannelId)
|
||||
}, "UpdateIncomingHook, overrides disabled")
|
||||
|
||||
@@ -862,7 +877,7 @@ func TestUpdateIncomingHook(t *testing.T) {
|
||||
require.Exactly(t, "username", updatedHook.Username, "Hook username is not updated")
|
||||
require.Exactly(t, "icon", updatedHook.IconURL, "Hook icon is not updated")
|
||||
|
||||
//updatedHook, _ = th.App.GetIncomingWebhook(createdHook.Id)
|
||||
// updatedHook, _ = th.App.GetIncomingWebhook(createdHook.Id)
|
||||
assert.Equal(t, updatedHook.ChannelId, createdHook.ChannelId)
|
||||
}, "UpdateIncomingHook")
|
||||
|
||||
@@ -993,6 +1008,7 @@ func TestUpdateIncomingHook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateIncomingWebhook_BypassTeamPermissions(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -1030,6 +1046,7 @@ func TestUpdateIncomingWebhook_BypassTeamPermissions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRegenOutgoingHookToken(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
@@ -1044,7 +1061,7 @@ func TestRegenOutgoingHookToken(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
//investigate why is act weird on jenkins
|
||||
// investigate why is act weird on jenkins
|
||||
// _, resp,_ = th.SystemAdminClient.RegenOutgoingHookToken(context.Background(), "")
|
||||
// CheckNotFoundStatus(t, resp)
|
||||
|
||||
@@ -1063,6 +1080,7 @@ func TestRegenOutgoingHookToken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateOutgoingHook(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -1074,8 +1092,10 @@ func TestUpdateOutgoingHook(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamAdminRoleId)
|
||||
th.RemovePermissionFromRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId)
|
||||
|
||||
createdHook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"cats"}}
|
||||
createdHook := &model.OutgoingWebhook{
|
||||
ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"cats"},
|
||||
}
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
rcreatedHook, _, err := th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), createdHook)
|
||||
@@ -1112,8 +1132,10 @@ func TestUpdateOutgoingHook(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
hook2 := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats"}}
|
||||
hook2 := &model.OutgoingWebhook{
|
||||
ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats"},
|
||||
}
|
||||
|
||||
createdHook2, _, err := th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), hook2)
|
||||
require.NoError(t, err)
|
||||
@@ -1145,8 +1167,10 @@ func TestUpdateOutgoingHook(t *testing.T) {
|
||||
}, "ModifyUpdateAt")
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
nonExistentHook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats"}}
|
||||
nonExistentHook := &model.OutgoingWebhook{
|
||||
ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats"},
|
||||
}
|
||||
|
||||
_, resp, err := client.UpdateOutgoingWebhook(context.Background(), nonExistentHook)
|
||||
require.Error(t, err)
|
||||
@@ -1168,8 +1192,10 @@ func TestUpdateOutgoingHook(t *testing.T) {
|
||||
})
|
||||
|
||||
th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId)
|
||||
hook2 := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats2"}}
|
||||
hook2 := &model.OutgoingWebhook{
|
||||
ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats2"},
|
||||
}
|
||||
|
||||
createdHook2, _, err := th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), hook2)
|
||||
require.NoError(t, err)
|
||||
@@ -1195,13 +1221,17 @@ func TestUpdateOutgoingHook(t *testing.T) {
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
firstHook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://someurl"}, TriggerWords: []string{"first"}}
|
||||
firstHook := &model.OutgoingWebhook{
|
||||
ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://someurl"}, TriggerWords: []string{"first"},
|
||||
}
|
||||
firstHook, _, err = th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), firstHook)
|
||||
require.NoError(t, err)
|
||||
|
||||
baseHook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://someurl"}, TriggerWords: []string{"base"}}
|
||||
baseHook := &model.OutgoingWebhook{
|
||||
ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://someurl"}, TriggerWords: []string{"base"},
|
||||
}
|
||||
baseHook, _, err = th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), baseHook)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1273,6 +1303,7 @@ func TestUpdateOutgoingHook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateOutgoingWebhook_BypassTeamPermissions(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -1284,8 +1315,10 @@ func TestUpdateOutgoingWebhook_BypassTeamPermissions(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamAdminRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId)
|
||||
|
||||
hook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats2"}}
|
||||
hook := &model.OutgoingWebhook{
|
||||
ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats2"},
|
||||
}
|
||||
|
||||
rhook, _, err := th.Client.CreateOutgoingWebhook(context.Background(), hook)
|
||||
require.NoError(t, err)
|
||||
@@ -1308,6 +1341,7 @@ func TestUpdateOutgoingWebhook_BypassTeamPermissions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteOutgoingHook(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -1326,8 +1360,10 @@ func TestDeleteOutgoingHook(t *testing.T) {
|
||||
}, "WhenHookDoesNotExist")
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
hook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"cats"}}
|
||||
hook := &model.OutgoingWebhook{
|
||||
ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"cats"},
|
||||
}
|
||||
rhook, _, err := th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), hook)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1342,8 +1378,10 @@ func TestDeleteOutgoingHook(t *testing.T) {
|
||||
}, "WhenHookExists")
|
||||
|
||||
t.Run("WhenUserDoesNotHavePermissions", func(t *testing.T) {
|
||||
hook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"dogs"}}
|
||||
hook := &model.OutgoingWebhook{
|
||||
ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
|
||||
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"dogs"},
|
||||
}
|
||||
rhook, _, err := th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), hook)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user