Skip to content

Commit

Permalink
Fix Delete application confirmation message points to the workspace b…
Browse files Browse the repository at this point in the history
…ut says environment radius-project#7089 (radius-project#7095)

Signed-off-by: Josh <[email protected]>

# Description

Parse out the environment name from the Workspace.Environment property
using the resources library.

## Type of change

This pull request fixes a bug in Radius and has an approved issue

Fixes: radius-project#7089

---------

Signed-off-by: Josh Handel <[email protected]>
Signed-off-by: Josh <[email protected]>
Signed-off-by: Josh [email protected]
Co-authored-by: Shalabh Mohan Shrivastava <[email protected]>
  • Loading branch information
jhandel and shalabhms authored Feb 1, 2024
1 parent 9c76f6d commit c1a8d16
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
14 changes: 13 additions & 1 deletion pkg/cli/cmd/app/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/radius-project/radius/pkg/cli/output"
"github.com/radius-project/radius/pkg/cli/prompt"
"github.com/radius-project/radius/pkg/cli/workspaces"
"github.com/radius-project/radius/pkg/ucp/resources"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -82,6 +83,7 @@ type Runner struct {
Output output.Interface

ApplicationName string
EnvironmentName string
Scope string
Confirm bool
Workspace *workspaces.Workspace
Expand Down Expand Up @@ -121,6 +123,16 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
return err
}

// Lookup the environment name for use in the confirmation prompt
if workspace.Environment != "" {
id, err := resources.ParseResource(workspace.Environment)
if err != nil {
return err
}

r.EnvironmentName = id.Name()
}

// Throw error if user specifies a Bicep filename or path instead of an application name
if strings.HasSuffix(r.ApplicationName, ".bicep") {
return clierrors.Message(bicepWarning, r.ApplicationName)
Expand All @@ -143,7 +155,7 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
func (r *Runner) Run(ctx context.Context) error {
// Prompt user to confirm deletion
if !r.Confirm {
confirmed, err := prompt.YesOrNoPrompt(fmt.Sprintf(deleteConfirmation, r.ApplicationName, r.Workspace.Name), prompt.ConfirmNo, r.InputPrompter)
confirmed, err := prompt.YesOrNoPrompt(fmt.Sprintf(deleteConfirmation, r.ApplicationName, r.EnvironmentName), prompt.ConfirmNo, r.InputPrompter)
if err != nil {
return err
}
Expand Down
35 changes: 22 additions & 13 deletions pkg/cli/cmd/app/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ func Test_Show(t *testing.T) {
"kind": "kubernetes",
"context": "kind-kind",
},
Name: "kind-kind",
Scope: "/planes/radius/local/resourceGroups/test-group",
Name: "kind-kind",
Scope: "/planes/radius/local/resourceGroups/test-group",
Environment: "/planes/radius/local/resourceGroups/default/providers/Applications.Core/environments/default",
}
outputSink := &output.MockOutput{}
runner := &Runner{
Expand Down Expand Up @@ -166,13 +167,14 @@ func Test_Show(t *testing.T) {
"kind": "kubernetes",
"context": "kind-kind",
},
Name: "kind-kind",
Scope: "/planes/radius/local/resourceGroups/test-group",
Name: "kind-kind",
Scope: "/planes/radius/local/resourceGroups/test-group",
Environment: "/planes/radius/local/resourceGroups/default/providers/Applications.Core/environments/default",
}

promptMock := prompt.NewMockInterface(ctrl)
promptMock.EXPECT().
GetListInput([]string{prompt.ConfirmNo, prompt.ConfirmYes}, fmt.Sprintf(deleteConfirmation, "test-app", workspace.Name)).
GetListInput([]string{prompt.ConfirmNo, prompt.ConfirmYes}, fmt.Sprintf(deleteConfirmation, "test-app", "default")).
Return(prompt.ConfirmYes, nil).
Times(1)

Expand All @@ -189,6 +191,7 @@ func Test_Show(t *testing.T) {
Workspace: workspace,
Output: outputSink,
ApplicationName: "test-app",
EnvironmentName: "default",
}

err := runner.Run(context.Background())
Expand All @@ -213,13 +216,14 @@ func Test_Show(t *testing.T) {
"kind": "kubernetes",
"context": "kind-kind",
},
Name: "kind-kind",
Scope: "/planes/radius/local/resourceGroups/test-group",
Name: "kind-kind",
Scope: "/planes/radius/local/resourceGroups/test-group",
Environment: "/planes/radius/local/resourceGroups/default/providers/Applications.Core/environments/default",
}

promptMock := prompt.NewMockInterface(ctrl)
promptMock.EXPECT().
GetListInput([]string{prompt.ConfirmNo, prompt.ConfirmYes}, fmt.Sprintf(deleteConfirmation, "test-app", workspace.Name)).
GetListInput([]string{prompt.ConfirmNo, prompt.ConfirmYes}, fmt.Sprintf(deleteConfirmation, "test-app", "default")).
Return(prompt.ConfirmNo, nil).
Times(1)

Expand All @@ -229,6 +233,7 @@ func Test_Show(t *testing.T) {
Workspace: workspace,
Output: outputSink,
ApplicationName: "test-app",
EnvironmentName: "default",
}

err := runner.Run(context.Background())
Expand All @@ -255,15 +260,17 @@ func Test_Show(t *testing.T) {
"kind": "kubernetes",
"context": "kind-kind",
},
Name: "kind-kind",
Scope: "/planes/radius/local/resourceGroups/test-group",
Name: "kind-kind",
Scope: "/planes/radius/local/resourceGroups/test-group",
Environment: "/planes/radius/local/resourceGroups/default/providers/Applications.Core/environments/default",
}
outputSink := &output.MockOutput{}
runner := &Runner{
ConnectionFactory: &connections.MockFactory{ApplicationsManagementClient: appManagementClient},
Workspace: workspace,
Output: outputSink,
ApplicationName: "test-app",
EnvironmentName: "default",
Confirm: true,
}

Expand All @@ -290,13 +297,14 @@ func Test_Show(t *testing.T) {
"kind": "kubernetes",
"context": "kind-kind",
},
Name: "kind-kind",
Scope: "/planes/radius/local/resourceGroups/test-group",
Name: "kind-kind",
Scope: "/planes/radius/local/resourceGroups/test-group",
Environment: "/planes/radius/local/resourceGroups/default/providers/Applications.Core/environments/default",
}

promptMock := prompt.NewMockInterface(ctrl)
promptMock.EXPECT().
GetListInput([]string{prompt.ConfirmNo, prompt.ConfirmYes}, fmt.Sprintf(deleteConfirmation, "test-app", workspace.Name)).
GetListInput([]string{prompt.ConfirmNo, prompt.ConfirmYes}, fmt.Sprintf(deleteConfirmation, "test-app", "default")).
Return("", &prompt.ErrExitConsole{}).
Times(1)

Expand All @@ -306,6 +314,7 @@ func Test_Show(t *testing.T) {
Output: outputSink,
Workspace: workspace,
ApplicationName: "test-app",
EnvironmentName: "default",
}

err := runner.Run(context.Background())
Expand Down

0 comments on commit c1a8d16

Please sign in to comment.