[MM-63555] mmctl: Add compliance export show and cancel cmds (#30569)

* add compliance export cancel command and tests

- Introduced `ComplianceExportCancelCmd` to allow cancellation of compliance export jobs.
- Implemented unit tests for the cancellation command, covering successful cancellation, error handling for non-existent jobs, and cancellation in non-cancellable states.
- Added end-to-end tests to validate the command's functionality in the E2E test suite.

* mmctl docs

* clean up example text; remove unneeded getJob

* fix tests

* fix tests, again.

* prefer hyphen for command naming

* update docs
Этот коммит содержится в:
Christopher Poile
2025-06-24 12:26:43 -04:00
коммит произвёл GitHub
родитель 9399398e04
Коммит e60f878090
8 изменённых файлов: 256 добавлений и 17 удалений

Просмотреть файл

@@ -13,6 +13,7 @@ import (
func (s *MmctlUnitTestSuite) TestComplianceExportListCmdF() {
s.Run("list default pagination", func() {
s.SetupTest() // Reset mocks before test
printer.Clean()
var mockJobs []*model.Job
@@ -115,6 +116,7 @@ func (s *MmctlUnitTestSuite) TestComplianceExportListCmdF() {
func (s *MmctlUnitTestSuite) TestComplianceExportShowCmdF() {
s.Run("show job successfully", func() {
s.SetupTest() // Reset mocks before test
printer.Clean()
mockJob := &model.Job{
Id: model.NewId(),
@@ -137,6 +139,7 @@ func (s *MmctlUnitTestSuite) TestComplianceExportShowCmdF() {
})
s.Run("show job with error", func() {
s.SetupTest() // Reset mocks before test
printer.Clean()
mockError := &model.AppError{
Message: "failed to get job",
@@ -157,6 +160,70 @@ func (s *MmctlUnitTestSuite) TestComplianceExportShowCmdF() {
})
}
func (s *MmctlUnitTestSuite) TestComplianceExportCancelCmdF() {
s.Run("cancel job successfully", func() {
s.SetupTest() // Reset mocks before test
printer.Clean()
id := model.NewId()
s.client.
EXPECT().
CancelJob(context.TODO(), id).
Return(&model.Response{}, nil).
Times(1)
cmd := makeCmd()
err := complianceExportCancelCmdF(s.client, cmd, []string{id})
s.Require().Nil(err)
s.Len(printer.GetLines(), 0)
s.Len(printer.GetErrorLines(), 0)
})
s.Run("cancel job with get error", func() {
s.SetupTest() // Reset mocks before test
printer.Clean()
mockError := &model.AppError{
Message: "failed to get job",
}
s.client.
EXPECT().
CancelJob(context.TODO(), "invalid-job-id").
Return(&model.Response{}, mockError).
Times(1)
cmd := makeCmd()
err := complianceExportCancelCmdF(s.client, cmd, []string{"invalid-job-id"})
s.Require().NotNil(err)
s.EqualError(err, "failed to cancel compliance export job: failed to get job")
s.Len(printer.GetLines(), 0)
s.Len(printer.GetErrorLines(), 0)
})
s.Run("cancel job with cancel error", func() {
s.SetupTest() // Reset mocks before test
printer.Clean()
id := model.NewId()
mockError := &model.AppError{
Message: "failed to cancel job",
}
s.client.
EXPECT().
CancelJob(context.TODO(), id).
Return(&model.Response{}, mockError).
Times(1)
cmd := makeCmd()
err := complianceExportCancelCmdF(s.client, cmd, []string{id})
s.Require().NotNil(err)
s.EqualError(err, "failed to cancel compliance export job: failed to cancel job")
s.Len(printer.GetLines(), 0)
s.Len(printer.GetErrorLines(), 0)
})
}
func makeCmd() *cobra.Command {
cmd := &cobra.Command{}
cmd.Flags().Int("page", 0, "")