Skip to content

Commit

Permalink
Fix flaky behavior with "list namespaces/projects" integration tests (#…
Browse files Browse the repository at this point in the history
…6355)

For some reason, "odo list namespaces/projects" would contain
the current test namespace, but the subsequent
"odo list namespaces/projects -o json" would no longer
contain this namespace.
  • Loading branch information
rm3l authored Nov 29, 2022
1 parent 35e3cc3 commit 70c5bd5
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions tests/integration/cmd_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package integration
import (
"fmt"
"path/filepath"
"strings"
"time"

"github.com/tidwall/gjson"
Expand Down Expand Up @@ -185,19 +184,19 @@ ComponentSettings:
return out
}, 10*time.Second, 1*time.Second).Should(ContainSubstring(commonVar.Project))
})

It(fmt.Sprintf("should successfully list all the %ss in JSON format", commandName), func() {
Eventually(func() bool {
ns := helper.Cmd("odo", "list", commandName).ShouldPass().Out()
return strings.Contains(ns, commonVar.Project)
}).WithTimeout(10 * time.Second).Should(BeTrue())

out := helper.Cmd("odo", "list", commandName, "-o", "json").ShouldPass().Out()
Expect(helper.IsJSON(out)).To(BeTrue())
// check if the namespace/project created for this test is marked as active in the JSON output
gjsonStr := fmt.Sprintf("namespaces.#[name==%s].active", commonVar.Project)
Expect(gjson.Get(out, gjsonStr).String()).To(Equal("true"))
// ensure that some namespace is marked as "active: false"
Expect(gjson.Get(out, "namespaces.#[active==false]#.name").String()).ShouldNot(ContainSubstring(commonVar.Project))
Eventually(func(g Gomega) {
// NOTE: Make sure not to use the global Gomega expectations, as this would make the test fail.
// Use expectations on the Gomega argument passed to this function instead.
out := helper.Cmd("odo", "list", commandName, "-o", "json").ShouldRun().Out()
g.Expect(helper.IsJSON(out)).To(BeTrue())
// check if the namespace/project created for this test is marked as active in the JSON output
gjsonStr := fmt.Sprintf("namespaces.#[name==%s].active", commonVar.Project)
g.Expect(gjson.Get(out, gjsonStr).String()).To(Equal("true"))
// ensure that some namespace is marked as "active: false"
g.Expect(gjson.Get(out, "namespaces.#[active==false]#.name").String()).ShouldNot(ContainSubstring(commonVar.Project))
}).WithTimeout(10 * time.Second).Should(Succeed())
})
})
}
Expand Down

0 comments on commit 70c5bd5

Please sign in to comment.