diff --git a/docs/website/docs/command-reference/delete-namespace.md b/docs/website/docs/command-reference/delete-namespace.md index 9822cb48467..bfd7785113c 100644 --- a/docs/website/docs/command-reference/delete-namespace.md +++ b/docs/website/docs/command-reference/delete-namespace.md @@ -15,7 +15,7 @@ odo delete namespace [--wait] [--force] ```shell $ odo delete namespace mynamespace ? Are you sure you want to delete namespace "mynamespace"? Yes - ✓ Namespace "mynamespace" deleted + ✓ Namespace "mynamespace" will be deleted asynchronously ``` @@ -31,7 +31,7 @@ odo delete project [--wait] [--force] ```shell $ odo delete project myproject ? Are you sure you want to delete project "myproject"? Yes -✓ Project "myproject" deleted +✓ Project "myproject" will be deleted asynchronously ``` diff --git a/pkg/odo/cli/delete/namespace/namespace.go b/pkg/odo/cli/delete/namespace/namespace.go index 6605b1212e1..fae9ee14a3f 100644 --- a/pkg/odo/cli/delete/namespace/namespace.go +++ b/pkg/odo/cli/delete/namespace/namespace.go @@ -6,6 +6,8 @@ import ( "os" "github.com/spf13/cobra" + "golang.org/x/text/cases" + "golang.org/x/text/language" ktemplates "k8s.io/kubectl/pkg/util/templates" "github.com/redhat-developer/odo/pkg/log" @@ -14,8 +16,6 @@ import ( "github.com/redhat-developer/odo/pkg/odo/genericclioptions" "github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset" scontext "github.com/redhat-developer/odo/pkg/segment/context" - "golang.org/x/text/cases" - "golang.org/x/text/language" ) const RecommendedCommandName = "namespace" @@ -93,10 +93,12 @@ func (do *DeleteOptions) Run(ctx context.Context) error { } s.End(true) - caser := cases.Title(language.Und) - successMessage := fmt.Sprintf(`%s %q deleted`, - caser.String(do.commandName), do.namespaceName) - log.Successf(successMessage) + cmdNameTitled := cases.Title(language.Und).String(do.commandName) + msg := fmt.Sprintf("%s %q deleted", cmdNameTitled, do.namespaceName) + if !do.waitFlag { + msg = fmt.Sprintf("%s %q will be deleted asynchronously", cmdNameTitled, do.namespaceName) + } + log.Success(msg) return nil } diff --git a/tests/helper/helper_oc.go b/tests/helper/helper_oc.go index f9fe8ae9467..11bd2ba1197 100644 --- a/tests/helper/helper_oc.go +++ b/tests/helper/helper_oc.go @@ -341,8 +341,7 @@ func (oc OcRunner) SetProject(namespace string) string { // DeleteNamespaceProject deletes a specified project in oc cluster func (oc OcRunner) DeleteNamespaceProject(projectName string, wait bool) { fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName) - session := Cmd("odo", "delete", "project", projectName, "-f", "--wait="+strconv.FormatBool(wait)).ShouldPass().Out() - Expect(session).To(ContainSubstring(fmt.Sprintf("Project %q deleted", projectName))) + Cmd(oc.path, "delete", "project", projectName, "--wait="+strconv.FormatBool(wait)).ShouldPass() } func (oc OcRunner) GetAllPVCNames(namespace string) []string { diff --git a/tests/helper/odo_utils.go b/tests/helper/odo_utils.go index a0ad7a9c4e5..3e2ff61173f 100644 --- a/tests/helper/odo_utils.go +++ b/tests/helper/odo_utils.go @@ -46,7 +46,7 @@ func CreateRandProject() string { func DeleteProject(projectName string) { fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName) session := Cmd("odo", "delete", "project", projectName, "-f").ShouldPass().Out() - Expect(session).To(ContainSubstring(fmt.Sprintf("Project %q deleted", projectName))) + Expect(session).To(ContainSubstring(fmt.Sprintf("Project %q will be deleted asynchronously", projectName))) } // GetMetadataFromDevfile retrieves the metadata from devfile diff --git a/tests/integration/cmd_namespace_test.go b/tests/integration/cmd_namespace_test.go index aefd8a4a7c4..9e51c2eedd8 100644 --- a/tests/integration/cmd_namespace_test.go +++ b/tests/integration/cmd_namespace_test.go @@ -62,22 +62,25 @@ var _ = Describe("odo create/delete/list/set namespace/project tests", func() { Expect(commonVar.CliRunner.HasNamespaceProject(namespace)).To(BeTrue()) }) - checkNsDeletionFunc := func(additionalArgs []string, nsCheckerFunc func()) { + checkNsDeletionFunc := func(wait bool, nsCheckerFunc func()) { args := []string{"delete", commandName, namespace, "--force"} - if additionalArgs != nil { - args = append(args, additionalArgs...) + if wait { + args = append(args, "--wait") } out := helper.Cmd("odo", args...).ShouldPass().Out() if nsCheckerFunc != nil { nsCheckerFunc() } - caser := cases.Title(language.Und) - Expect(out).To( - ContainSubstring(fmt.Sprintf("%s %q deleted", caser.String(commandName), namespace))) + cmdTitled := cases.Title(language.Und).String(commandName) + if wait { + Expect(out).To(ContainSubstring(fmt.Sprintf("%s %q deleted", cmdTitled, namespace))) + } else { + Expect(out).To(ContainSubstring(fmt.Sprintf("%s %q will be deleted asynchronously", cmdTitled, namespace))) + } } It(fmt.Sprintf("should successfully delete the %s asynchronously", commandName), func() { - checkNsDeletionFunc(nil, func() { + checkNsDeletionFunc(false, func() { Eventually(func() bool { return commonVar.CliRunner.HasNamespaceProject(namespace) }, 60*time.Second).Should(BeFalse()) @@ -85,7 +88,7 @@ var _ = Describe("odo create/delete/list/set namespace/project tests", func() { }) It(fmt.Sprintf("should successfully delete the %s synchronously with --wait", commandName), func() { - checkNsDeletionFunc([]string{"--wait"}, func() { + checkNsDeletionFunc(true, func() { Expect(commonVar.CliRunner.HasNamespaceProject(namespace)).To(BeFalse()) }) })