[GH-28399] Errcheck jobtest (#28689)
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
@@ -70,7 +70,6 @@ issues:
|
||||
channels/api4/config_local.go|\
|
||||
channels/api4/config_test.go|\
|
||||
channels/api4/data_retention.go|\
|
||||
channels/api4/job_test.go|\
|
||||
channels/api4/post_test.go|\
|
||||
channels/api4/preference_test.go|\
|
||||
channels/api4/reaction_test.go|\
|
||||
|
||||
@@ -36,7 +36,10 @@ func TestCreateJob(t *testing.T) {
|
||||
t.Run("valid job as user with permissions", func(t *testing.T) {
|
||||
received, _, err := th.SystemAdminClient.CreateJob(context.Background(), job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(received.Id)
|
||||
defer func() {
|
||||
result, appErr := th.App.Srv().Store().Job().Delete(received.Id)
|
||||
require.NoErrorf(t, appErr, "Failed to delete job (result: %v): %v", result, appErr)
|
||||
}()
|
||||
})
|
||||
|
||||
t.Run("invalid job type as user without permissions", func(t *testing.T) {
|
||||
@@ -58,7 +61,10 @@ func TestGetJob(t *testing.T) {
|
||||
_, err := th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
defer func() {
|
||||
result, appErr := th.App.Srv().Store().Job().Delete(job.Id)
|
||||
require.NoError(t, appErr, "Failed to delete job (result: %v)", result)
|
||||
}()
|
||||
|
||||
received, _, err := th.SystemAdminClient.GetJob(context.Background(), job.Id)
|
||||
require.NoError(t, err)
|
||||
@@ -113,7 +119,11 @@ func TestGetJobs(t *testing.T) {
|
||||
for _, job := range jobs {
|
||||
_, err := th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
|
||||
defer func(jobId string) {
|
||||
result, appErr := th.App.Srv().Store().Job().Delete(jobId)
|
||||
require.NoError(t, appErr, "Failed to delete job (result: %v)", result)
|
||||
}(job.Id)
|
||||
}
|
||||
|
||||
t.Run("Get 2 jobs", func(t *testing.T) {
|
||||
@@ -192,7 +202,11 @@ func TestGetJobsByType(t *testing.T) {
|
||||
for _, job := range jobs {
|
||||
_, err := th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
|
||||
defer func(jobId string) {
|
||||
result, appErr := th.App.Srv().Store().Job().Delete(jobId)
|
||||
require.NoError(t, appErr, "Failed to delete job (result: %v)", result)
|
||||
}(job.Id)
|
||||
}
|
||||
|
||||
received, _, err := th.SystemAdminClient.GetJobsByType(context.Background(), jobType, 0, 2)
|
||||
@@ -261,18 +275,25 @@ func TestDownloadJob(t *testing.T) {
|
||||
// as a system admin, we should get a not found status.
|
||||
_, err = th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
defer func() {
|
||||
_, delErr := th.App.Srv().Store().Job().Delete(job.Id)
|
||||
require.NoError(t, delErr, "Failed to delete job %s", job.Id)
|
||||
}()
|
||||
|
||||
filePath := "./data/export/" + job.Id + "/testdat.txt"
|
||||
mkdirAllErr := os.MkdirAll(filepath.Dir(filePath), 0770)
|
||||
require.NoError(t, mkdirAllErr)
|
||||
os.Create(filePath)
|
||||
|
||||
_, createErr := os.Create(filePath)
|
||||
require.NoError(t, createErr)
|
||||
|
||||
// Normal user cannot download the results of these job (not the right permission)
|
||||
_, resp, err = th.Client.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
th.SystemManagerClient.DownloadJob(context.Background(), job.Id)
|
||||
_, resp, err = th.SystemManagerClient.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
// System manager with default permissions cannot download the results of these job (Doesn't have correct permissions)
|
||||
_, resp, err = th.SystemManagerClient.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
@@ -296,7 +317,9 @@ func TestDownloadJob(t *testing.T) {
|
||||
filePath = "./data/export/" + job.Id + ".zip"
|
||||
mkdirAllErr = os.MkdirAll(filepath.Dir(filePath), 0770)
|
||||
require.NoError(t, mkdirAllErr)
|
||||
os.Create(filePath)
|
||||
|
||||
_, createErr = os.Create(filePath)
|
||||
require.NoError(t, createErr)
|
||||
|
||||
_, _, err = th.SystemAdminClient.DownloadJob(context.Background(), job.Id)
|
||||
require.NoError(t, err)
|
||||
@@ -313,7 +336,10 @@ func TestDownloadJob(t *testing.T) {
|
||||
}
|
||||
_, err = th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
defer func() {
|
||||
_, delErr := th.App.Srv().Store().Job().Delete(job.Id)
|
||||
require.NoError(t, delErr, "Failed to delete job %s", job.Id)
|
||||
}()
|
||||
|
||||
// System admin shouldn't be able to download since the job type is not message export
|
||||
_, resp, err = th.SystemAdminClient.DownloadJob(context.Background(), job.Id)
|
||||
@@ -347,9 +373,11 @@ func TestCancelJob(t *testing.T) {
|
||||
for _, job := range jobs {
|
||||
_, err := th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
defer func(jobId string) {
|
||||
_, delErr := th.App.Srv().Store().Job().Delete(jobId)
|
||||
require.NoError(t, delErr, "Failed to delete job %s", jobId)
|
||||
}(job.Id)
|
||||
}
|
||||
|
||||
resp, err := th.Client.CancelJob(context.Background(), jobs[0].Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
@@ -400,7 +428,10 @@ func TestUpdateJobStatus(t *testing.T) {
|
||||
for _, job := range jobs {
|
||||
_, err := th.App.Srv().Store().Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
defer func(jobID string) {
|
||||
_, delErr := th.App.Srv().Store().Job().Delete(jobID)
|
||||
require.NoError(t, delErr, "Failed to delete job %s", jobID)
|
||||
}(job.Id)
|
||||
}
|
||||
|
||||
t.Run("Fail to update job status without permission", func(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user