Skip to content

Commit

Permalink
Update domain deprecation command to fail if workflow exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddoll committed Apr 13, 2021
1 parent 1fd6a57 commit 0b1448c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tools/cli/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,47 @@ func (s *cliAppSuite) TestDomainUpdate_Failed() {
}

func (s *cliAppSuite) TestDomainDeprecate() {
s.clientFrontendClient.EXPECT().ListClosedWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListClosedWorkflowExecutionsResponse{}, nil)
s.clientFrontendClient.EXPECT().ListOpenWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListOpenWorkflowExecutionsResponse{}, nil)
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(nil)
err := s.app.Run([]string{"", "--do", domainName, "domain", "deprecate"})
s.Nil(err)
}

func (s *cliAppSuite) TestDomainDeprecate_DomainNotExist() {
s.clientFrontendClient.EXPECT().ListClosedWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListClosedWorkflowExecutionsResponse{}, nil)
s.clientFrontendClient.EXPECT().ListOpenWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListOpenWorkflowExecutionsResponse{}, nil)
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(&types.EntityNotExistsError{})
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "domain", "deprecate"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDomainDeprecate_Failed() {
s.clientFrontendClient.EXPECT().ListClosedWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListClosedWorkflowExecutionsResponse{}, nil)
s.clientFrontendClient.EXPECT().ListOpenWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListOpenWorkflowExecutionsResponse{}, nil)
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(&types.BadRequestError{"faked error"})
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "domain", "deprecate"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDomainDeprecate_Force() {
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(nil)
err := s.app.Run([]string{"", "--do", domainName, "domain", "deprecate", "--force"})
s.Nil(err)
}

func (s *cliAppSuite) TestDomainDeprecate_DomainNotExist_Force() {
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(&types.EntityNotExistsError{})
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "domain", "deprecate", "--force"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDomainDeprecate_Failed_Force() {
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(&types.BadRequestError{"faked error"})
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "domain", "deprecate", "--force"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDomainDescribe() {
resp := describeDomainResponseServer
s.serverFrontendClient.EXPECT().DescribeDomain(gomock.Any(), gomock.Any()).Return(resp, nil)
Expand Down
12 changes: 12 additions & 0 deletions tools/cli/domainCommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,22 @@ func (d *domainCLIImpl) UpdateDomain(c *cli.Context) {
func (d *domainCLIImpl) DeprecateDomain(c *cli.Context) {
domainName := getRequiredGlobalOption(c, FlagDomain)
securityToken := c.String(FlagSecurityToken)
force := c.Bool(FlagForce)

ctx, cancel := newContext(c)
defer cancel()

if !force {
// check if there is any workflow in this domain, if exists, do not deprecate
wfs, _ := listClosedWorkflow(getWorkflowClient(c), 1, 0, time.Now().UnixNano(), "", "", workflowStatusNotSet, nil, c)
if len(wfs) > 0 {
ErrorAndExit("Operation DeprecateDomain failed.", errors.New("Workflow history not cleared in this domain."))
}
wfs, _ = listOpenWorkflow(getWorkflowClient(c), 1, 0, time.Now().UnixNano(), "", "", nil, c)
if len(wfs) > 0 {
ErrorAndExit("Operation DeprecateDomain failed.", errors.New("Workflow still running in this domain."))
}
}
err := d.deprecateDomain(ctx, &types.DeprecateDomainRequest{
Name: domainName,
SecurityToken: securityToken,
Expand Down
4 changes: 4 additions & 0 deletions tools/cli/domainUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ var (
Name: FlagSecurityTokenWithAlias,
Usage: "Optional token for security check",
},
cli.BoolFlag{
Name: FlagForce,
Usage: "Deprecate domain regardless of domain history.",
},
}

describeDomainFlags = []cli.Flag{
Expand Down
1 change: 1 addition & 0 deletions tools/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const (
FlagAllWithAlias = FlagAll + ", a"
FlagDeprecated = "deprecated"
FlagDeprecatedWithAlias = FlagDeprecated + ", dep"
FlagForce = "force"
FlagPageSize = "pagesize"
FlagPageSizeWithAlias = FlagPageSize + ", ps"
FlagEarliestTime = "earliest_time"
Expand Down

0 comments on commit 0b1448c

Please sign in to comment.