Skip to content

Commit

Permalink
Check for namespace/project existence with '{oc,kubectl} get {namespa…
Browse files Browse the repository at this point in the history
…ce,project} <name>'

For some reason, checking by listing all namespaces/projects could end up returning an outdated list.
  • Loading branch information
rm3l committed May 16, 2022
1 parent ba7248f commit c8f21e9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
5 changes: 4 additions & 1 deletion tests/helper/helper_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ type CliRunner interface {
DeletePod(podName string, projectName string)
GetAllNamespaceProjects() []string
GetNamespaceProject() string
CheckNamespaceProjectExists(name string) bool

// HasNamespaceProject returns whether the specified namespace or project exists in the cluster
HasNamespaceProject(name string) bool

GetActiveNamespace() string
GetEnvsDevFileDeployment(componentName, appName, projectName string) map[string]string
GetEnvRefNames(componentName, appName, projectName string) []string
Expand Down
6 changes: 4 additions & 2 deletions tests/helper/helper_kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,10 @@ func (kubectl KubectlRunner) GetNamespaceProject() string {
return Cmd(kubectl.path, "get", "namespace").ShouldPass().Out()
}

func (kubectl KubectlRunner) CheckNamespaceProjectExists(name string) bool {
return Cmd(kubectl.path, "get", "namespace", name).ShouldPass().pass
func (kubectl KubectlRunner) HasNamespaceProject(name string) bool {
out := Cmd(kubectl.path, "get", "namespace", name, "-o", "jsonpath={.metadata.name}").
ShouldRun().Out()
return strings.Contains(out, name)
}

func (kubectl KubectlRunner) GetActiveNamespace() string {
Expand Down
6 changes: 4 additions & 2 deletions tests/helper/helper_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,10 @@ func (oc OcRunner) GetNamespaceProject() string {
return Cmd(oc.path, "get", "project").ShouldPass().Out()
}

func (oc OcRunner) CheckNamespaceProjectExists(name string) bool {
return Cmd(oc.path, "get", "project", name).ShouldPass().pass
func (oc OcRunner) HasNamespaceProject(name string) bool {
out := Cmd(oc.path, "get", "project", name, "-o", "jsonpath={.metadata.name}").
ShouldRun().Out()
return strings.Contains(out, name)
}

func (oc OcRunner) GetActiveNamespace() string {
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/cmd_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var _ = Describe("odo create/delete/list/set namespace/project tests", func() {
defer func(ns string) {
commonVar.CliRunner.DeleteNamespaceProject(ns)
}(namespace)
Expect(commonVar.CliRunner.CheckNamespaceProjectExists(namespace)).To(BeTrue())
Expect(commonVar.CliRunner.HasNamespaceProject(namespace)).To(BeTrue())
Expect(commonVar.CliRunner.GetActiveNamespace()).To(Equal(namespace))
})

Expand All @@ -55,7 +55,7 @@ var _ = Describe("odo create/delete/list/set namespace/project tests", func() {

BeforeEach(func() {
namespace = helper.CreateRandProject()
Expect(commonVar.CliRunner.CheckNamespaceProjectExists(namespace)).To(BeTrue())
Expect(commonVar.CliRunner.HasNamespaceProject(namespace)).To(BeTrue())
})

checkNsDeletionFunc := func(additionalArgs []string, nsCheckerFunc func()) {
Expand All @@ -73,15 +73,15 @@ var _ = Describe("odo create/delete/list/set namespace/project tests", func() {

It(fmt.Sprintf("should successfully delete the %s asynchronously", commandName), func() {
checkNsDeletionFunc(nil, func() {
Eventually(func() []string {
return commonVar.CliRunner.GetAllNamespaceProjects()
}, 60*time.Second).ShouldNot(ContainElement(namespace))
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() {
Expect(commonVar.CliRunner.GetAllNamespaceProjects()).ShouldNot(ContainElement(namespace))
Expect(commonVar.CliRunner.HasNamespaceProject(namespace)).To(BeFalse())
})
})
})
Expand Down

0 comments on commit c8f21e9

Please sign in to comment.