Skip to content

Commit

Permalink
rad group switch output (#7488)
Browse files Browse the repository at this point in the history
# Description
rad cli group switch output to display success message when switching
output to a group

## Type of change
- This pull request fixes a bug in Radius and has an approved issue
(issue link required).

Fixes: #7395

---------

Signed-off-by: gpltaylor <gpltaylor@gmail.com>
  • Loading branch information
gpltaylor committed Apr 14, 2024
1 parent d4be47e commit 4c23622
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/cli/cmd/group/groupswitch/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/radius-project/radius/pkg/cli/cmd/commonflags"
"github.com/radius-project/radius/pkg/cli/connections"
"github.com/radius-project/radius/pkg/cli/framework"
"github.com/radius-project/radius/pkg/cli/output"
"github.com/radius-project/radius/pkg/cli/workspaces"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -62,6 +63,7 @@ func NewCommand(factory framework.Factory) (*cobra.Command, framework.Runner) {
type Runner struct {
ConfigHolder *framework.ConfigHolder
ConnectionFactory connections.Factory
Output output.Interface
Workspace *workspaces.Workspace
UCPResourceGroupName string
}
Expand All @@ -71,6 +73,7 @@ func NewRunner(factory framework.Factory) *Runner {
return &Runner{
ConnectionFactory: factory.GetConnectionFactory(),
ConfigHolder: factory.GetConfigHolder(),
Output: factory.GetOutput(),
}
}

Expand Down Expand Up @@ -128,6 +131,11 @@ func (r *Runner) Run(ctx context.Context) error {

return nil
})
return err
if err != nil {
return err
}

r.Output.LogInfo("Switched to resource group %q", r.UCPResourceGroupName)
return nil

}
13 changes: 13 additions & 0 deletions pkg/cli/cmd/group/groupswitch/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/radius-project/radius/pkg/cli/clierrors"
"github.com/radius-project/radius/pkg/cli/connections"
"github.com/radius-project/radius/pkg/cli/framework"
"github.com/radius-project/radius/pkg/cli/output"
"github.com/radius-project/radius/pkg/cli/workspaces"
"github.com/radius-project/radius/pkg/ucp/api/v20231001preview"
"github.com/radius-project/radius/test/radcli"
Expand Down Expand Up @@ -148,6 +149,7 @@ func Test_Run(t *testing.T) {
Scope: "/planes/radius/local/resourceGroups/b",
}

outputSink := &output.MockOutput{}
runner := &Runner{
ConfigHolder: &framework.ConfigHolder{
Config: config,
Expand All @@ -156,6 +158,7 @@ func Test_Run(t *testing.T) {
ConnectionFactory: &connections.MockFactory{ApplicationsManagementClient: appManagementClient},
Workspace: workspace,
UCPResourceGroupName: "a",
Output: outputSink,
}

err = runner.Run(context.Background())
Expand All @@ -164,6 +167,16 @@ func Test_Run(t *testing.T) {
actualConfig, err := cli.ReadWorkspaceSection(config)
require.NoError(t, err)
require.Equal(t, expectedConfig, actualConfig)

expected := []any{
output.LogOutput{
Format: "Switched to resource group %q",
Params: []any{"a"},
},
}

require.Equal(t, expected, outputSink.Writes)

})

t.Run("Switch (not existent)", func(t *testing.T) {
Expand Down

0 comments on commit 4c23622

Please sign in to comment.