diff --git a/pkg/cli/cmd/app/delete/delete.go b/pkg/cli/cmd/app/delete/delete.go index f836033429..fe24fd169e 100644 --- a/pkg/cli/cmd/app/delete/delete.go +++ b/pkg/cli/cmd/app/delete/delete.go @@ -163,7 +163,7 @@ func (r *Runner) Run(ctx context.Context) error { } if deleted { - r.Output.LogInfo("Application deleted") + r.Output.LogInfo("Application %s deleted", r.ApplicationName) } else { r.Output.LogInfo("Application '%s' does not exist or has already been deleted.", r.ApplicationName) } diff --git a/pkg/cli/cmd/app/delete/delete_test.go b/pkg/cli/cmd/app/delete/delete_test.go index 2bb491260b..8ce34e89cf 100644 --- a/pkg/cli/cmd/app/delete/delete_test.go +++ b/pkg/cli/cmd/app/delete/delete_test.go @@ -149,7 +149,8 @@ func Test_Show(t *testing.T) { expected := []any{ output.LogOutput{ - Format: "Application deleted", + Format: "Application %s deleted", + Params: []any{"test-app"}, }, } @@ -195,7 +196,8 @@ func Test_Show(t *testing.T) { expected := []any{ output.LogOutput{ - Format: "Application deleted", + Format: "Application %s deleted", + Params: []any{"test-app"}, }, } diff --git a/test/functional/shared/cli/cli_test.go b/test/functional/shared/cli/cli_test.go index f3090d43dc..f675f9c6fa 100644 --- a/test/functional/shared/cli/cli_test.go +++ b/test/functional/shared/cli/cli_test.go @@ -534,6 +534,7 @@ func Test_CLI_Delete(t *testing.T) { options := shared.NewRPTestOptions(t) appName := "kubernetes-cli-with-resources" + appNameUnassociatedResources := "kubernetes-cli-with-unassociated-resources" appNameEmptyResources := "kubernetes-cli-empty-resources" cwd, err := os.Getwd() @@ -542,6 +543,9 @@ func Test_CLI_Delete(t *testing.T) { templateWithResources := "testdata/corerp-kubernetes-cli-with-resources.bicep" templateFilePathWithResources := filepath.Join(cwd, templateWithResources) + templateWithResourcesUnassociated := "testdata/corerp-kubernetes-cli-with-unassociated-resources.bicep" + templateFilePathWithResourcesUnassociated := filepath.Join(cwd, templateWithResourcesUnassociated) + templateEmptyResources := "testdata/corerp-kubernetes-cli-app-empty-resources.bicep" templateFilePathEmptyResources := filepath.Join(cwd, templateEmptyResources) @@ -584,34 +588,34 @@ func Test_CLI_Delete(t *testing.T) { t.Run("Validate rad app delete with resources not associated with any application", func(t *testing.T) { t.Logf("deploying from file %s", templateWithResources) - err := cli.Deploy(ctx, templateFilePathWithResources, "", appName, functional.GetMagpieImage()) - require.NoErrorf(t, err, "failed to deploy %s", appName) + err := cli.Deploy(ctx, templateFilePathWithResourcesUnassociated, "", appNameUnassociatedResources, functional.GetMagpieImage()) + require.NoErrorf(t, err, "failed to deploy %s", appNameUnassociatedResources) validation.ValidateObjectsRunning(ctx, t, options.K8sClient, options.DynamicClient, validation.K8sObjectSet{ Namespaces: map[string][]validation.K8sObject{ - "default-kubernetes-cli-with-resources": { - validation.NewK8sPodForResource(appName, "containera-app-with-resources"), - validation.NewK8sPodForResource(appName, "containerb-app-with-resources"), + "default-kubernetes-cli-with-unassociated-resources": { + validation.NewK8sPodForResource(appNameUnassociatedResources, "containerX"), + validation.NewK8sPodForResource(appNameUnassociatedResources, "containerY"), }, }, }) //ignore response for tests - _, err = options.ManagementClient.DeleteResource(ctx, "Applications.Core/containers", "containerb-app-with-resources") - require.NoErrorf(t, err, "failed to delete resource containerb-app-with-resources") - err = DeleteAppWithoutDeletingResources(t, ctx, options, appName) - require.NoErrorf(t, err, "failed to delete application %s", appName) + _, err = options.ManagementClient.DeleteResource(ctx, "Applications.Core/containers", "containerY") + require.NoErrorf(t, err, "failed to delete resource containerY") + err = DeleteAppWithoutDeletingResources(t, ctx, options, appNameUnassociatedResources) + require.NoErrorf(t, err, "failed to delete application %s", appNameUnassociatedResources) t.Logf("deploying from file %s", templateEmptyResources) - err = cli.Deploy(ctx, templateFilePathEmptyResources, "", appName) + err = cli.Deploy(ctx, templateFilePathEmptyResources, "", appNameEmptyResources) require.NoErrorf(t, err, "failed to deploy %s", appNameEmptyResources) err = cli.ApplicationDelete(ctx, appNameEmptyResources) require.NoErrorf(t, err, "failed to delete %s", appNameEmptyResources) //ignore response for tests - _, err = options.ManagementClient.DeleteResource(ctx, "Applications.Core/containers", "containera-app-with-resources") - require.NoErrorf(t, err, "failed to delete resource containera-app-with-resources") + _, err = options.ManagementClient.DeleteResource(ctx, "Applications.Core/containers", "containerX") + require.NoErrorf(t, err, "failed to delete resource containerX") }) } diff --git a/test/functional/shared/cli/testdata/corerp-kubernetes-cli-with-unassociated-resources.bicep b/test/functional/shared/cli/testdata/corerp-kubernetes-cli-with-unassociated-resources.bicep new file mode 100644 index 0000000000..7851aa4046 --- /dev/null +++ b/test/functional/shared/cli/testdata/corerp-kubernetes-cli-with-unassociated-resources.bicep @@ -0,0 +1,40 @@ +import radius as radius + +@description('Specifies the location for resources.') +param location string = 'global' + +@description('Specifies the environment for resources.') +param environment string = 'test' + +@description('Specifies the image to be deployed.') +param magpieimage string + +resource app 'Applications.Core/applications@2023-10-01-preview' = { + name: 'kubernetes-cli-with-unassociated-resources' + location: location + properties: { + environment: environment + } +} + +resource containerx 'Applications.Core/containers@2023-10-01-preview' = { + name: 'containerX' + location: location + properties: { + application: app.id + container: { + image: magpieimage + } + } +} + +resource containery 'Applications.Core/containers@2023-10-01-preview' = { + name: 'containerY' + location: location + properties: { + application: app.id + container: { + image: magpieimage + } + } +} diff --git a/test/validation/k8s.go b/test/validation/k8s.go index 6620202d3d..e612b9553f 100644 --- a/test/validation/k8s.go +++ b/test/validation/k8s.go @@ -340,8 +340,8 @@ func ValidateObjectsRunning(ctx context.Context, t *testing.T, k8s *kubernetes.C deployedResources, err = dynamic.Resource(mapping.Resource).List(ctx, metav1.ListOptions{}) } assert.NoErrorf(t, err, "could not list deployed resources of type %s in namespace %s", resourceGVR.GroupResource(), namespace) - - validated = validated && matchesActualLabels(expectedInNamespace, deployedResources.Items) + t.Logf("Listed %d deployed resources of type %s in namespace %s", len(deployedResources.Items), resourceGVR.GroupResource(), namespace) + validated = validated && matchesActualLabels(t, expectedInNamespace, deployedResources.Items) } case <-ctx.Done(): @@ -532,7 +532,7 @@ func logPods(t *testing.T, pods []corev1.Pod) { } } -func matchesActualLabels(expectedResources []K8sObject, actualResources []unstructured.Unstructured) bool { +func matchesActualLabels(t *testing.T, expectedResources []K8sObject, actualResources []unstructured.Unstructured) bool { remaining := []K8sObject{} for _, expectedResource := range expectedResources { @@ -552,6 +552,8 @@ func matchesActualLabels(expectedResources []K8sObject, actualResources []unstru resourceExists = true actualResources = append(actualResources[:idx], actualResources[idx+1:]...) break + } else { + t.Logf("Resource: %s Expected labels %v, got %v", actualResource.GetName(), expectedResource.Labels, actualResource.GetLabels()) } } }