Skip to content

Commit

Permalink
Improve confirmation message for namespace/project deletion (#6383)
Browse files Browse the repository at this point in the history
* Improve confirmation message for namespace/project deletion

* Update sample output in ´delete namespace/project' command reference

* Use oc binary instead of odo in DeleteNamespaceProject 'helper_oc' implementation

This way, we do not rely on some other odo command (odo delete project command) in unrelated tests

This also makes it more consistent with the implementation in 'helper_kubectl'
  • Loading branch information
rm3l authored Dec 7, 2022
1 parent 5570f4f commit 9815b60
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions docs/website/docs/command-reference/delete-namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ odo delete namespace <name> [--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
```
</details>

Expand All @@ -31,7 +31,7 @@ odo delete project <name> [--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
```
</details>

Expand Down
14 changes: 8 additions & 6 deletions pkg/odo/cli/delete/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions tests/helper/helper_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/helper/odo_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions tests/integration/cmd_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,33 @@ 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())
})
})

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())
})
})
Expand Down

0 comments on commit 9815b60

Please sign in to comment.