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())