Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rad group switch output #7488

Merged
merged 4 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 10 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,12 @@ func (r *Runner) Run(ctx context.Context) error {

return nil
})
return err

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line can be removed

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,
Copy link
Contributor

@rynowak rynowak Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an assert below to verify the output?

Here's an example you can borrow from: https://github.com/radius-project/radius/blob/main/pkg/cli/cmd/app/delete/delete_test.go#L280

}

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
Loading