Skip to content

Commit

Permalink
Use args for namespace name instead of global flag (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin authored Sep 14, 2022
1 parent 59795d0 commit 1bd642e
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 62 deletions.
42 changes: 30 additions & 12 deletions cli/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,25 @@ func (s *cliAppSuite) TestAppCommands() {

func (s *cliAppSuite) TestNamespaceRegister_LocalNamespace() {
s.frontendClient.EXPECT().RegisterNamespace(gomock.Any(), gomock.Any()).Return(nil, nil)
err := s.app.Run([]string{"", "--namespace", cliTestNamespace, "namespace", "register", "--global-namespace", "false"})
err := s.app.Run([]string{"", "namespace", "register", "--global-namespace", "false", cliTestNamespace})
s.NoError(err)
}

func (s *cliAppSuite) TestNamespaceRegister_GlobalNamespace() {
s.frontendClient.EXPECT().RegisterNamespace(gomock.Any(), gomock.Any()).Return(nil, nil)
err := s.app.Run([]string{"", "--namespace", cliTestNamespace, "namespace", "register", "--global-namespace", "true"})
err := s.app.Run([]string{"", "namespace", "register", "--global-namespace", "true", cliTestNamespace})
s.NoError(err)
}

func (s *cliAppSuite) TestNamespaceRegister_NamespaceExist() {
s.frontendClient.EXPECT().RegisterNamespace(gomock.Any(), gomock.Any()).Return(nil, serviceerror.NewNamespaceAlreadyExists(""))
errorCode := s.RunWithExitCode([]string{"", "--namespace", cliTestNamespace, "namespace", "register", "--global-namespace", "true"})
errorCode := s.RunWithExitCode([]string{"", "namespace", "register", "--global-namespace", "true", cliTestNamespace})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestNamespaceRegister_Failed() {
s.frontendClient.EXPECT().RegisterNamespace(gomock.Any(), gomock.Any()).Return(nil, serviceerror.NewInvalidArgument("faked error"))
errorCode := s.RunWithExitCode([]string{"", "--namespace", cliTestNamespace, "namespace", "register", "--global-namespace", "true"})
errorCode := s.RunWithExitCode([]string{"", "namespace", "register", "--global-namespace", "true", cliTestNamespace})
s.Equal(1, errorCode)
}

Expand Down Expand Up @@ -176,38 +176,38 @@ func (s *cliAppSuite) TestNamespaceUpdate() {
resp := describeNamespaceResponseServer
s.frontendClient.EXPECT().DescribeNamespace(gomock.Any(), gomock.Any()).Return(resp, nil).Times(2)
s.frontendClient.EXPECT().UpdateNamespace(gomock.Any(), gomock.Any()).Return(nil, nil).Times(2)
err := s.app.Run([]string{"", "--namespace", cliTestNamespace, "namespace", "update"})
err := s.app.Run([]string{"", "namespace", "update", cliTestNamespace})
s.Nil(err)
err = s.app.Run([]string{"", "--namespace", cliTestNamespace, "namespace", "update", "--description", "another desc", "--owner-email", "another@uber.com", "--retention", "1"})
err = s.app.Run([]string{"", "namespace", "update", "--description", "another desc", "--owner-email", "another@uber.com", "--retention", "1", cliTestNamespace})
s.Nil(err)
}

func (s *cliAppSuite) TestNamespaceUpdate_NamespaceNotExist() {
resp := describeNamespaceResponseServer
s.frontendClient.EXPECT().DescribeNamespace(gomock.Any(), gomock.Any()).Return(resp, nil)
s.frontendClient.EXPECT().UpdateNamespace(gomock.Any(), gomock.Any()).Return(nil, serviceerror.NewNamespaceNotFound("missing-namespace"))
errorCode := s.RunWithExitCode([]string{"", "--namespace", cliTestNamespace, "namespace", "update"})
errorCode := s.RunWithExitCode([]string{"", "namespace", "update", cliTestNamespace})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestNamespaceUpdate_ActiveClusterFlagNotSet_NamespaceNotExist() {
s.frontendClient.EXPECT().DescribeNamespace(gomock.Any(), gomock.Any()).Return(nil, serviceerror.NewNamespaceNotFound("missing-namespace"))
errorCode := s.RunWithExitCode([]string{"", "--namespace", cliTestNamespace, "namespace", "update"})
errorCode := s.RunWithExitCode([]string{"", "namespace", "update", cliTestNamespace})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestNamespaceUpdate_Failed() {
resp := describeNamespaceResponseServer
s.frontendClient.EXPECT().DescribeNamespace(gomock.Any(), gomock.Any()).Return(resp, nil)
s.frontendClient.EXPECT().UpdateNamespace(gomock.Any(), gomock.Any()).Return(nil, serviceerror.NewInvalidArgument("faked error"))
errorCode := s.RunWithExitCode([]string{"", "--namespace", cliTestNamespace, "namespace", "update"})
errorCode := s.RunWithExitCode([]string{"", "namespace", "update", cliTestNamespace})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestNamespaceDescribe() {
resp := describeNamespaceResponseServer
s.frontendClient.EXPECT().DescribeNamespace(gomock.Any(), &workflowservice.DescribeNamespaceRequest{Namespace: cliTestNamespace, Id: ""}).Return(resp, nil)
err := s.app.Run([]string{"", "--namespace", cliTestNamespace, "namespace", "describe"})
err := s.app.Run([]string{"", "namespace", "describe", cliTestNamespace})
s.Nil(err)
}

Expand All @@ -221,14 +221,32 @@ func (s *cliAppSuite) TestNamespaceDescribe_ById() {
func (s *cliAppSuite) TestNamespaceDescribe_NamespaceNotExist() {
resp := describeNamespaceResponseServer
s.frontendClient.EXPECT().DescribeNamespace(gomock.Any(), gomock.Any()).Return(resp, serviceerror.NewNamespaceNotFound("missing-namespace"))
errorCode := s.RunWithExitCode([]string{"", "--namespace", cliTestNamespace, "namespace", "describe"})
errorCode := s.RunWithExitCode([]string{"", "namespace", "describe", cliTestNamespace})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestNamespaceDescribe_Failed() {
resp := describeNamespaceResponseServer
s.frontendClient.EXPECT().DescribeNamespace(gomock.Any(), gomock.Any()).Return(resp, serviceerror.NewInvalidArgument("faked error"))
errorCode := s.RunWithExitCode([]string{"", "--namespace", cliTestNamespace, "namespace", "describe"})
errorCode := s.RunWithExitCode([]string{"", "namespace", "describe", cliTestNamespace})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestNamespaceDelete() {
s.operatorClient.EXPECT().DeleteNamespace(gomock.Any(), &operatorservice.DeleteNamespaceRequest{Namespace: cliTestNamespace}).Return(&operatorservice.DeleteNamespaceResponse{}, nil)
err := s.app.Run([]string{"", "namespace", "delete", "--yes", cliTestNamespace})
s.Nil(err)
}

func (s *cliAppSuite) TestNamespaceDelete_NamespaceNotExist() {
s.operatorClient.EXPECT().DeleteNamespace(gomock.Any(), gomock.Any()).Return(nil, serviceerror.NewNamespaceNotFound("missing-namespace"))
errorCode := s.RunWithExitCode([]string{"", "namespace", "delete", "--yes", cliTestNamespace})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestNamespaceDelete_Failed() {
s.operatorClient.EXPECT().DeleteNamespace(gomock.Any(), gomock.Any()).Return(nil, serviceerror.NewInvalidArgument("faked error"))
errorCode := s.RunWithExitCode([]string{"", "namespace", "delete", "--yes", cliTestNamespace})
s.Equal(1, errorCode)
}

Expand Down
4 changes: 2 additions & 2 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newConfigCommands() []*cli.Command {
Name: "get",
Usage: "Print the value of an env property",
Flags: []cli.Flag{},
ArgsUsage: "env.[ENV NAME].[PROPERTY NAME] or [PROPERTY NAME] for current env",
ArgsUsage: "[env.env_name.]property_name",
Action: func(c *cli.Context) error {
return EnvProperty(c)
},
Expand All @@ -47,7 +47,7 @@ func newConfigCommands() []*cli.Command {
Name: "set",
Usage: "Set the value of an env property",
Flags: []cli.Flag{},
ArgsUsage: `env.[ENV NAME].[PROPERTY NAME] [VALUE] or [PROPERTY NAME] [VALUE] for current env`,
ArgsUsage: "[env.env_name.]property_name value",
Action: func(c *cli.Context) error {
return SetEnvProperty(c)
},
Expand Down
6 changes: 3 additions & 3 deletions cli/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newEnvCommands() []*cli.Command {
{
Name: "show-env",
Usage: "Print environment properties",
ArgsUsage: " [ENV NAME]",
ArgsUsage: "env_name",
Flags: []cli.Flag{
&cli.StringFlag{
Name: output.FlagOutput,
Expand All @@ -63,7 +63,7 @@ func newEnvCommands() []*cli.Command {
Name: "use-env",
Usage: "Switch environment",
Flags: []cli.Flag{},
ArgsUsage: " [ENV NAME]",
ArgsUsage: "env_name",
Action: func(c *cli.Context) error {
return UseEnv(c)
},
Expand All @@ -72,7 +72,7 @@ func newEnvCommands() []*cli.Command {
Name: "remove-env",
Usage: "Remove environment",
Flags: []cli.Flag{},
ArgsUsage: " [ENV NAME]",
ArgsUsage: "env_name",
Action: func(c *cli.Context) error {
return RemoveEnv(c)
},
Expand Down
37 changes: 21 additions & 16 deletions cli/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

// by default we don't require any namespace data. But this can be overridden by calling SetRequiredNamespaceDataKeys()
var requiredNamespaceDataKeys = []string{}
var requiredNamespaceDataKeys []string

// SetRequiredNamespaceDataKeys will set requiredNamespaceDataKeys
func SetRequiredNamespaceDataKeys(keys []string) {
Expand Down Expand Up @@ -69,41 +69,46 @@ func parseNamespaceDataKVs(namespaceDataStr string) (map[string]string, error) {
func newNamespaceCommands() []*cli.Command {
return []*cli.Command{
{
Name: "describe",
Usage: "Describe a Namespace by name or Id",
Flags: describeNamespaceFlags,
Name: "describe",
Usage: "Describe a Namespace by name or Id",
Flags: describeNamespaceFlags,
ArgsUsage: "namespace_name",
Action: func(c *cli.Context) error {
return DescribeNamespace(c)
},
},
{
Name: "list",
Usage: "List all Namespaces",
Flags: listNamespacesFlags,
Name: "list",
Usage: "List all Namespaces",
Flags: listNamespacesFlags,
ArgsUsage: " ",
Action: func(c *cli.Context) error {
return ListNamespaces(c)
},
},
{
Name: "register",
Usage: "Register a new Namespace",
Flags: registerNamespaceFlags,
Name: "register",
Usage: "Register a new Namespace",
Flags: registerNamespaceFlags,
ArgsUsage: "namespace_name [cluster_name...]",
Action: func(c *cli.Context) error {
return RegisterNamespace(c)
},
},
{
Name: "update",
Usage: "Update a Namespace",
Flags: updateNamespaceFlags,
Name: "update",
Usage: "Update a Namespace",
Flags: updateNamespaceFlags,
ArgsUsage: "namespace_name [cluster_name...]",
Action: func(c *cli.Context) error {
return UpdateNamespace(c)
},
},
{
Name: "delete",
Usage: "Delete existing Namespace",
Flags: deleteNamespacesFlags,
Name: "delete",
Usage: "Delete existing Namespace",
Flags: deleteNamespacesFlags,
ArgsUsage: "namespace_name",
Action: func(c *cli.Context) error {
return DeleteNamespace(c)
},
Expand Down
Loading

0 comments on commit 1bd642e

Please sign in to comment.