From c1a8d16b9eeb0f064064730b05741fbf5099f234 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 1 Feb 2024 15:36:31 -0600 Subject: [PATCH] Fix Delete application confirmation message points to the workspace but says environment #7089 (#7095) Signed-off-by: Josh # 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: #7089 --------- Signed-off-by: Josh Handel Signed-off-by: Josh Signed-off-by: Josh josh@liveoak.ws Co-authored-by: Shalabh Mohan Shrivastava --- pkg/cli/cmd/app/delete/delete.go | 14 ++++++++++- pkg/cli/cmd/app/delete/delete_test.go | 35 +++++++++++++++++---------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/pkg/cli/cmd/app/delete/delete.go b/pkg/cli/cmd/app/delete/delete.go index a271f5dbc1..6450bcd716 100644 --- a/pkg/cli/cmd/app/delete/delete.go +++ b/pkg/cli/cmd/app/delete/delete.go @@ -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" ) @@ -82,6 +83,7 @@ type Runner struct { Output output.Interface ApplicationName string + EnvironmentName string Scope string Confirm bool Workspace *workspaces.Workspace @@ -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) @@ -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 } diff --git a/pkg/cli/cmd/app/delete/delete_test.go b/pkg/cli/cmd/app/delete/delete_test.go index 8ce34e89cf..a0084092b1 100644 --- a/pkg/cli/cmd/app/delete/delete_test.go +++ b/pkg/cli/cmd/app/delete/delete_test.go @@ -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{ @@ -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) @@ -189,6 +191,7 @@ func Test_Show(t *testing.T) { Workspace: workspace, Output: outputSink, ApplicationName: "test-app", + EnvironmentName: "default", } err := runner.Run(context.Background()) @@ -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) @@ -229,6 +233,7 @@ func Test_Show(t *testing.T) { Workspace: workspace, Output: outputSink, ApplicationName: "test-app", + EnvironmentName: "default", } err := runner.Run(context.Background()) @@ -255,8 +260,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{ @@ -264,6 +270,7 @@ func Test_Show(t *testing.T) { Workspace: workspace, Output: outputSink, ApplicationName: "test-app", + EnvironmentName: "default", Confirm: true, } @@ -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) @@ -306,6 +314,7 @@ func Test_Show(t *testing.T) { Output: outputSink, Workspace: workspace, ApplicationName: "test-app", + EnvironmentName: "default", } err := runner.Run(context.Background())