[MM-56074] mmctl job commands (#26855)
* add job list and update job status command to mmctl
Этот коммит содержится в:
@@ -102,6 +102,12 @@ func TestGetJobs(t *testing.T) {
|
||||
Type: jobType,
|
||||
CreateAt: t0 + 2,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: model.JobTypeLdapSync,
|
||||
CreateAt: t0 + 3,
|
||||
Status: model.JobStatusPending,
|
||||
},
|
||||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
@@ -110,21 +116,47 @@ func TestGetJobs(t *testing.T) {
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
received, _, err := th.SystemAdminClient.GetJobs(context.Background(), 0, 2)
|
||||
require.NoError(t, err)
|
||||
t.Run("Get 2 jobs", func(t *testing.T) {
|
||||
received, _, err := th.SystemAdminClient.GetJobs(context.Background(), "", "", 0, 2)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, received, 2, "received wrong number of jobs")
|
||||
require.Equal(t, jobs[2].Id, received[0].Id, "should've received newest job first")
|
||||
require.Equal(t, jobs[0].Id, received[1].Id, "should've received second newest job second")
|
||||
require.Len(t, received, 2, "received wrong number of jobs")
|
||||
require.Equal(t, jobs[3].Id, received[0].Id, "should've received newest job first")
|
||||
require.Equal(t, jobs[2].Id, received[1].Id, "should've received second newest job second")
|
||||
})
|
||||
|
||||
received, _, err = th.SystemAdminClient.GetJobs(context.Background(), 1, 2)
|
||||
require.NoError(t, err)
|
||||
t.Run("Get oldest job using paging", func(t *testing.T) {
|
||||
received, _, err := th.SystemAdminClient.GetJobs(context.Background(), "", "", 1, 3)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, jobs[1].Id, received[0].Id, "should've received oldest job last")
|
||||
})
|
||||
|
||||
require.Equal(t, jobs[1].Id, received[0].Id, "should've received oldest job last")
|
||||
t.Run("Return error fetching job without permissions", func(t *testing.T) {
|
||||
_, resp, err := th.Client.GetJobs(context.Background(), "", "", 0, 60)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
_, resp, err := th.Client.GetJobs(context.Background(), 0, 60)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
t.Run("Get job by type", func(t *testing.T) {
|
||||
received, _, err := th.SystemAdminClient.GetJobs(context.Background(), model.JobTypeLdapSync, "", 0, 3)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, received, 1, "received wrong number of jobs")
|
||||
require.Equal(t, jobs[3].Id, received[0].Id, "should've received the ldap sync job")
|
||||
})
|
||||
|
||||
t.Run("Get job by status", func(t *testing.T) {
|
||||
received, _, err := th.SystemAdminClient.GetJobs(context.Background(), "", model.JobStatusPending, 0, 3)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, received, 1, "received wrong number of jobs")
|
||||
require.Equal(t, jobs[3].Id, received[0].Id, "should've received the ldap sync job")
|
||||
})
|
||||
|
||||
t.Run("Get job by type and status", func(t *testing.T) {
|
||||
received, _, err := th.SystemAdminClient.GetJobs(context.Background(), model.JobTypeLdapSync, model.JobStatusPending, 0, 3)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, received, 1, "received wrong number of jobs")
|
||||
require.Equal(t, jobs[3].Id, received[0].Id, "should've received the ldap sync job")
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetJobsByType(t *testing.T) {
|
||||
@@ -336,3 +368,69 @@ func TestCancelJob(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestUpdateJobStatus(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
jobType := model.JobTypeDataRetention
|
||||
jobs := []*model.Job{
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
Status: model.JobStatusPending,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
Status: model.JobStatusInProgress,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
Status: model.JobStatusSuccess,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
Status: model.JobStatusPending,
|
||||
},
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
t.Run("Fail to update job status without permission", func(t *testing.T) {
|
||||
resp, err := th.Client.UpdateJobStatus(context.Background(), jobs[0].Id, model.JobStatusCancelRequested, false)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("Change a pending job to cancel requested without force with sysadmin client", func(t *testing.T) {
|
||||
_, err := th.SystemAdminClient.UpdateJobStatus(context.Background(), jobs[0].Id, model.JobStatusCancelRequested, false)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Change a pending job to cancel requested without force with local client", func(t *testing.T) {
|
||||
_, err := th.LocalClient.UpdateJobStatus(context.Background(), jobs[3].Id, model.JobStatusCancelRequested, false)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Fail to change a pending job to canceled without force", func(t *testing.T) {
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
resp, err := client.UpdateJobStatus(context.Background(), jobs[0].Id, model.JobStatusCanceled, false)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Change a pending job to canceled with force", func(t *testing.T) {
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, err := client.UpdateJobStatus(context.Background(), jobs[0].Id, model.JobStatusCanceled, true)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user