Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions pkg/cli/cmd/app/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (r *Runner) Run(ctx context.Context) error {

app, err := client.GetApplication(ctx, r.ApplicationName)
if clients.Is404Error(err) {
r.Output.LogInfo("Application '%s' does not exist or has already been deleted.", r.ApplicationName)
r.Output.LogInfo("Applications.Core/applications/%s not found", r.ApplicationName)
return nil
} else if err != nil {
return err
Expand Down Expand Up @@ -210,15 +210,15 @@ func (r *Runner) Run(ctx context.Context) error {
})
if err != nil {
if strings.Contains(err.Error(), "not found") {
r.Output.LogInfo("Application '%s' does not exist or has already been deleted.", r.ApplicationName)
r.Output.LogInfo("Applications.Core/applications/%s not found", r.ApplicationName)
return nil
}
return clierrors.Message("Failed to delete application '%s': %v", r.ApplicationName, err)
}
if deleted {
r.Output.LogInfo("Application %s deleted successfully", r.ApplicationName)
r.Output.LogInfo("Applications.Core/applications/%s deleted", r.ApplicationName)
} else {
r.Output.LogInfo("Application '%s' does not exist or has already been deleted.", r.ApplicationName)
r.Output.LogInfo("Applications.Core/applications/%s not found", r.ApplicationName)
return nil
}

Expand Down
72 changes: 67 additions & 5 deletions pkg/cli/cmd/app/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func Test_Delete(t *testing.T) {

expected := []any{
output.LogOutput{
Format: "Application %s deleted successfully",
Format: "Applications.Core/applications/%s deleted",
Params: []any{"test-app"},
},
}
Expand Down Expand Up @@ -240,7 +240,7 @@ func Test_Delete(t *testing.T) {

expected := []any{
output.LogOutput{
Format: "Application %s deleted successfully",
Format: "Applications.Core/applications/%s deleted",
Params: []any{"test-app"},
},
}
Expand Down Expand Up @@ -354,7 +354,7 @@ func Test_Delete(t *testing.T) {

expected := []any{
output.LogOutput{
Format: "Application '%s' does not exist or has already been deleted.",
Format: "Applications.Core/applications/%s not found",
Params: []any{"test-app"},
},
}
Expand Down Expand Up @@ -522,7 +522,69 @@ func Test_Delete(t *testing.T) {

expected := []any{
output.LogOutput{
Format: "Application '%s' does not exist or has already been deleted.",
Format: "Applications.Core/applications/%s not found",
Params: []any{"test-app"},
},
}

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

t.Run("Success: Delete Returns False (already gone)", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

appManagementClient := clients.NewMockApplicationsManagementClient(ctrl)
deleteMock := delete.NewMockInterface(ctrl)

appManagementClient.EXPECT().
GetApplication(gomock.Any(), "test-app").
Return(v20231001preview.ApplicationResource{
Properties: &v20231001preview.ApplicationProperties{
Environment: new("/planes/radius/local/resourceGroups/default/providers/Applications.Core/environments/default"),
},
}, nil).
Times(1)

progressText := fmt.Sprintf("Deleting application '%s' from environment '%s'...", "test-app", "default")
deleteMock.EXPECT().
DeleteApplicationWithProgress(
gomock.Any(),
appManagementClient,
clients.DeleteOptions{
ApplicationNameOrID: "test-app",
ProgressText: progressText,
},
).
Return(false, nil).
Times(1)

workspace := &workspaces.Workspace{
Connection: map[string]any{
"kind": "kubernetes",
"context": "kind-kind",
},
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{
Delete: deleteMock,
ConnectionFactory: &connections.MockFactory{ApplicationsManagementClient: appManagementClient},
Workspace: workspace,
Output: outputSink,
ApplicationName: "test-app",
EnvironmentName: "default",
Confirm: true,
}

err := runner.Run(context.Background())
require.NoError(t, err)

expected := []any{
output.LogOutput{
Format: "Applications.Core/applications/%s not found",
Params: []any{"test-app"},
},
}
Expand Down Expand Up @@ -591,6 +653,6 @@ func Test_Delete(t *testing.T) {
require.Contains(t, warningOutput.Format, "WARNING")
lastOutput, ok := outputSink.Writes[len(outputSink.Writes)-1].(output.LogOutput)
require.True(t, ok)
require.Equal(t, "Application %s deleted successfully", lastOutput.Format)
require.Equal(t, "Applications.Core/applications/%s deleted", lastOutput.Format)
})
}
4 changes: 1 addition & 3 deletions pkg/cli/cmd/env/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
// Run creates an environment in the specified resource group using the provided environment name and namespace, and
// returns an error if unsuccessful.
func (r *Runner) Run(ctx context.Context) error {
r.Output.LogInfo("Creating Environment...")

client, err := r.ConnectionFactory.CreateApplicationsManagementClient(ctx, *r.Workspace)
if err != nil {
return err
Expand All @@ -170,7 +168,7 @@ func (r *Runner) Run(ctx context.Context) error {
if err != nil {
return err
}
r.Output.LogInfo("Successfully created environment %q in resource group %q", r.EnvironmentName, r.ResourceGroupName)
r.Output.LogInfo("Applications.Core/environments/%s created", r.EnvironmentName)

return nil
}
14 changes: 2 additions & 12 deletions pkg/cli/cmd/env/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,9 @@ func Test_Run(t *testing.T) {

expectedOutput := []any{
output.LogOutput{
Format: "Creating Environment...",
},
output.LogOutput{
Format: "Successfully created environment %q in resource group %q",
Format: "Applications.Core/environments/%s created",
Params: []any{
"default",
"test-group",
},
},
}
Expand Down Expand Up @@ -247,16 +243,10 @@ func Test_Run(t *testing.T) {
ConfigFileInterface: configFileInterface,
}

expectedOutput := []any{
output.LogOutput{
Format: "Creating Environment...",
},
}

err := runner.Run(context.Background())
require.Error(t, err)
require.Equal(t, expectedError, err)
require.Equal(t, expectedOutput, outputSink.Writes)
require.Empty(t, outputSink.Writes)
})
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/cli/cmd/env/create/preview/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ func (r *Runner) Run(ctx context.Context) error {
r.RadiusCoreClientFactory = clientFactory
}

r.Output.LogInfo("Creating Radius Core Environment %q...", r.EnvironmentName)

// Ensure the default resource group exists before creating recipe pack in it.
mgmtClient, err := r.ConnectionFactory.CreateApplicationsManagementClient(ctx, *r.Workspace)
if err != nil {
Expand Down Expand Up @@ -185,6 +183,6 @@ func (r *Runner) Run(ctx context.Context) error {
return err
}

r.Output.LogInfo("Successfully created environment %q in resource group %q with default recipe pack.", r.EnvironmentName, r.ResourceGroupName)
return nil
r.Output.LogInfo("Radius.Core/environments/%s created", r.EnvironmentName)
return nil
}
19 changes: 10 additions & 9 deletions pkg/cli/cmd/env/create/preview/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,18 @@ func Test_Run(t *testing.T) {
ResourceGroupName: "test-resource-group",
}

expectedOutput := []any{
output.LogOutput{
Format: "Radius.Core/environments/%s created",
Params: []any{
"testenv",
},
},
}

err = runner.Run(context.Background())
require.NoError(t, err)

require.Contains(t, outputSink.Writes, output.LogOutput{
Format: "Creating Radius Core Environment %q...",
Params: []interface{}{"testenv"},
})
require.Contains(t, outputSink.Writes, output.LogOutput{
Format: "Successfully created environment %q in resource group %q with default recipe pack.",
Params: []interface{}{"testenv", "test-resource-group"},
})
require.Equal(t, expectedOutput, outputSink.Writes)
})

t.Run("creates default recipe pack when not found", func(t *testing.T) {
Expand Down
15 changes: 3 additions & 12 deletions pkg/cli/cmd/env/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ import (
)

const (
msgEnvironmentDeleted = "Environment deleted"
msgEnvironmentNotFound = "Environment '%s' does not exist or has already been deleted."
msgDeletingEnvironment = "Deleting environment %s...\n"
msgDeletingResourceCount = "Deleting %d resource(s) in environment %s...\n"
msgEnvironmentDeleted = "Applications.Core/environments/%s deleted"
msgEnvironmentNotFound = "Applications.Core/environments/%s not found"
)

// NewCommand creates an instance of the command and runner for the `rad env delete` command.
Expand Down Expand Up @@ -166,24 +164,17 @@ func (r *Runner) Run(ctx context.Context) error {
return err
}
if !confirmed {
r.Output.LogInfo("Environment %q NOT deleted", r.EnvironmentName)
return nil
}
}

// Show progress messages
if totalResourceCount > 0 {
r.Output.LogInfo(msgDeletingResourceCount, totalResourceCount, r.EnvironmentName)
}
r.Output.LogInfo(msgDeletingEnvironment, r.EnvironmentName)

deleted, err := client.DeleteEnvironment(ctx, r.EnvironmentName)
if err != nil {
return err
}

if deleted {
r.Output.LogInfo(msgEnvironmentDeleted)
r.Output.LogInfo(msgEnvironmentDeleted, r.EnvironmentName)
} else {
r.Output.LogInfo(msgEnvironmentNotFound, r.EnvironmentName)
}
Expand Down
42 changes: 6 additions & 36 deletions pkg/cli/cmd/env/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Test_CommandValidation(t *testing.T) {
}

const (
deleteConfirmationEmpty = "The environment %s is empty. Are you sure you want to delete the environment?"
deleteConfirmationEmpty = "The environment %s is empty. Are you sure you want to delete the environment?"
deleteConfirmationWithResources = "The environment %s contains %d deployed resource(s). Are you sure you want to delete the environment and its resources?"
)

Expand Down Expand Up @@ -145,12 +145,9 @@ func Test_Show(t *testing.T) {
require.NoError(t, err)

expected := []any{
output.LogOutput{
Format: msgDeletingEnvironment,
Params: []any{"test-env"},
},
output.LogOutput{
Format: msgEnvironmentDeleted,
Params: []any{"test-env"},
},
}

Expand Down Expand Up @@ -201,12 +198,9 @@ func Test_Show(t *testing.T) {
require.NoError(t, err)

expected := []any{
output.LogOutput{
Format: msgDeletingEnvironment,
Params: []any{"test-env"},
},
output.LogOutput{
Format: msgEnvironmentDeleted,
Params: []any{"test-env"},
},
}

Expand Down Expand Up @@ -260,16 +254,9 @@ func Test_Show(t *testing.T) {
require.NoError(t, err)

expected := []any{
output.LogOutput{
Format: msgDeletingResourceCount,
Params: []any{1, "test-env"},
},
output.LogOutput{
Format: msgDeletingEnvironment,
Params: []any{"test-env"},
},
output.LogOutput{
Format: msgEnvironmentDeleted,
Params: []any{"test-env"},
},
}

Expand Down Expand Up @@ -323,16 +310,9 @@ func Test_Show(t *testing.T) {
require.NoError(t, err)

expected := []any{
output.LogOutput{
Format: msgDeletingResourceCount,
Params: []any{1, "test-env"},
},
output.LogOutput{
Format: msgDeletingEnvironment,
Params: []any{"test-env"},
},
output.LogOutput{
Format: msgEnvironmentDeleted,
Params: []any{"test-env"},
},
}

Expand Down Expand Up @@ -376,13 +356,7 @@ func Test_Show(t *testing.T) {
err := runner.Run(context.Background())
require.NoError(t, err)

expected := []any{
output.LogOutput{
Format: "Environment %q NOT deleted",
Params: []any{"test-env"},
},
}
require.Equal(t, expected, outputSink.Writes)
require.Empty(t, outputSink.Writes)
})

// YES, this is a success case. Delete means "make it be gone", so if the environment is already
Expand Down Expand Up @@ -428,10 +402,6 @@ func Test_Show(t *testing.T) {
require.NoError(t, err)

expected := []any{
output.LogOutput{
Format: msgDeletingEnvironment,
Params: []any{"test-env"},
},
output.LogOutput{
Format: msgEnvironmentNotFound,
Params: []any{"test-env"},
Expand Down
Loading
Loading