Skip to content

Commit

Permalink
Check if all Pods are running in odo logs tests (redhat-developer#5851)
Browse files Browse the repository at this point in the history
* Check if all Pods are running in odo logs tests

Signed-off-by: Dharmit Shah <[email protected]>

* Use strings.Trim instead of using index
  • Loading branch information
dharmit authored Jun 22, 2022
1 parent b8164cf commit 47caa79
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions tests/integration/devfile/cmd_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package devfile

import (
"path/filepath"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -12,6 +13,19 @@ var _ = Describe("odo logs command tests", func() {
var componentName string
var commonVar helper.CommonVar

areAllPodsRunning := func() bool {
allPodsRunning := true
status := string(commonVar.CliRunner.Run("get", "pods", "-n", commonVar.Project, "-o", "jsonpath=\"{.items[*].status.phase}\"").Out.Contents())
status = strings.Trim(status, "\"")
split := strings.Split(status, " ")
for i := 0; i < len(split); i++ {
if split[i] != "Running" {
allPodsRunning = false
}
}
return allPodsRunning
}

var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
componentName = helper.RandString(6)
Expand Down Expand Up @@ -71,9 +85,9 @@ var _ = Describe("odo logs command tests", func() {
When("running in Deploy mode", func() {
BeforeEach(func() {
helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass()
Eventually(func() string {
return string(commonVar.CliRunner.Run("get", "pods", "-n", commonVar.Project).Out.Contents())
}).Should(Not(ContainSubstring("ContainerCreating")))
Eventually(func() bool {
return areAllPodsRunning()
}).Should(Equal(true))
})
It("should successfully show logs of the running component", func() {
// `odo logs`
Expand All @@ -97,9 +111,9 @@ var _ = Describe("odo logs command tests", func() {
devSession, _, _, _, err = helper.StartDevMode()
Expect(err).ToNot(HaveOccurred())
helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass()
Eventually(func() string {
return string(commonVar.CliRunner.Run("get", "pods", "-n", commonVar.Project).Out.Contents())
}).Should(Not(ContainSubstring("ContainerCreating")))
Eventually(func() bool {
return areAllPodsRunning()
}).Should(Equal(true))
})
AfterEach(func() {
devSession.Kill()
Expand Down

0 comments on commit 47caa79

Please sign in to comment.