Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky behavior with "list namespaces/projects -o json" integration tests #6355

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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