Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions app/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,21 @@ func (c *NamespaceClient) listNamespaces() error {
}
}

func (c *NamespaceClient) getNamespaceCloudApi(namespace string) (*cloudNamespace.Namespace, error) {
res, err := c.cloudAPIClient.GetNamespace(c.ctx, &cloudservice.GetNamespaceRequest{
Namespace: namespace,
})
if err != nil {
return nil, err
}
if res.Namespace == nil || res.Namespace.Namespace == "" {
// this should never happen, the server should return an error when the namespace is not found
return nil, fmt.Errorf("invalid namespace returned by server")
}
return res.Namespace, nil
}

// TODO: deprecate this and use getNamespaceCloudApi everywhere
func (c *NamespaceClient) getNamespace(namespace string) (*namespace.Namespace, error) {
res, err := c.client.GetNamespace(c.ctx, &namespaceservice.GetNamespaceRequest{
Namespace: namespace,
Expand Down Expand Up @@ -1812,6 +1827,28 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut,
},
},
},
{
Name: "capacity",
Usage: "Manage namespace capacity settings",
Aliases: []string{"cap"},
Subcommands: []*cli.Command{
{
Name: "get",
Usage: "Get namespace capacity settings",
Aliases: []string{"g"},
Flags: []cli.Flag{
NamespaceFlag,
},
Action: func(ctx *cli.Context) error {
n, err := c.getNamespaceCloudApi(ctx.String(NamespaceFlagName))
if err != nil {
return err
}
return PrintProto(n.GetCapacity())
},
},
},
},
}

// Export Related Command
Expand Down
59 changes: 58 additions & 1 deletion app/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import (

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/suite"
"github.com/urfave/cli/v2"

"github.com/temporalio/tcld/protogen/api/namespace/v1"
"github.com/temporalio/tcld/protogen/api/namespaceservice/v1"
"github.com/temporalio/tcld/protogen/api/request/v1"
authservicemock "github.com/temporalio/tcld/protogen/apimock/authservice/v1"
apimock "github.com/temporalio/tcld/protogen/apimock/cloudservice/v1"
namespaceservicemock "github.com/temporalio/tcld/protogen/apimock/namespaceservice/v1"
"github.com/urfave/cli/v2"
)

func TestNamespace(t *testing.T) {
Expand Down Expand Up @@ -3264,3 +3265,59 @@ func (s *NamespaceTestSuite) TestSetConnectivityRules() {
})
}
}

func (s *NamespaceTestSuite) TestGetNamespaceCapacity() {
tests := []struct {
name string
args []string
mock func()
expectErr bool
}{
{
name: "get namespace capacity - success",
args: []string{"namespace", "capacity", "get", "--namespace", "ns1"},
mock: func() {
s.mockCloudApiClient.EXPECT().
GetNamespace(gomock.Any(), &cloudservice.GetNamespaceRequest{
Namespace: "ns1",
}).Return(&cloudservice.GetNamespaceResponse{
Namespace: &cloudNamespace.Namespace{
Namespace: "ns1",
Capacity: &cloudNamespace.Capacity{
CurrentMode: &cloudNamespace.Capacity_Provisioned_{
Provisioned: &cloudNamespace.Capacity_Provisioned{
CurrentValue: 16.0,
},
},
},
},
}, nil).Times(1)
},
},
{
name: "get namespace capacity - fail",
args: []string{"namespace", "capacity", "get", "--namespace", "ns1"},
expectErr: true,
mock: func() {
s.mockCloudApiClient.EXPECT().
GetNamespace(gomock.Any(), &cloudservice.GetNamespaceRequest{
Namespace: "ns1",
}).Return(nil, errors.New("some error")).Times(1)
},
},
}

for _, tc := range tests {
s.Run(tc.name, func() {
if tc.mock != nil {
tc.mock()
}
err := s.RunCmd(tc.args...)
if tc.expectErr {
s.Error(err)
} else {
s.NoError(err)
}
})
}
}