Skip to content

Commit

Permalink
ExitWithError() - more upgrades from Exit()
Browse files Browse the repository at this point in the history
Add error-message checks to pod_xxxx_test.go

Signed-off-by: Ed Santiago <santiago@redhat.com>
  • Loading branch information
edsantiago committed Jun 21, 2024
1 parent 79f0f77 commit d810f41
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 25 deletions.
13 changes: 6 additions & 7 deletions test/e2e/pod_initcontainers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("Podman init containers", func() {

It("podman create init container without --pod should fail", func() {
session := podmanTest.Podman([]string{"create", "--init-ctr", "always", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "must specify pod value with init-ctr"))
})

It("podman create init container with bad init type should fail", func() {
session := podmanTest.Podman([]string{"create", "--init-ctr", "unknown", "--pod", "new:foobar", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "init-ctr value must be 'always' or 'once'"))
})

It("podman init containers should not degrade pod status", func() {
Expand Down Expand Up @@ -54,7 +53,7 @@ var _ = Describe("Podman init containers", func() {
// adding init-ctr to running pod should fail
session := podmanTest.Podman([]string{"create", "--init-ctr", "always", "--pod", "foobar", ALPINE, "date"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "cannot add init-ctr to a running pod"))
})

It("podman make sure init container runs before pod containers", func() {
Expand Down Expand Up @@ -91,8 +90,8 @@ var _ = Describe("Podman init containers", func() {
check := podmanTest.Podman([]string{"container", "exists", initContainerID})
check.WaitWithDefaultTimeout()
// Container was rm'd
// Expect(check).Should(Exit(1))
Expect(check.ExitCode()).To(Equal(1), "I dont understand why the other way does not work")
Expect(check).To(ExitWithError(1, ""))

// Let's double check with a stop and start
podmanTest.StopPod("foobar")
startPod := podmanTest.Podman([]string{"pod", "start", "foobar"})
Expand All @@ -102,7 +101,7 @@ var _ = Describe("Podman init containers", func() {
// Because no init was run, the file should not even exist
doubleCheck := podmanTest.Podman([]string{"exec", verify.OutputToString(), "cat", filename})
doubleCheck.WaitWithDefaultTimeout()
Expect(doubleCheck).Should(Exit(1))
Expect(doubleCheck).Should(ExitWithError(1, fmt.Sprintf("cat: can't open '%s': No such file or directory", filename)))

})

Expand Down
17 changes: 13 additions & 4 deletions test/e2e/pod_restart_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package integration

import (
"fmt"

. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("Podman pod restart", func() {

It("podman pod restart bogus pod", func() {
session := podmanTest.Podman([]string{"pod", "restart", "123"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
expect := "no pod with name or ID 123 found: no such pod"
if IsRemote() {
expect = `unable to find pod "123": no such pod`
}
Expect(session).Should(ExitWithError(125, expect))
})

It("podman pod restart single empty pod", func() {
Expand All @@ -21,7 +26,7 @@ var _ = Describe("Podman pod restart", func() {

session := podmanTest.Podman([]string{"pod", "restart", podid})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, fmt.Sprintf("no containers in pod %s have no dependencies, cannot start pod: no such container", podid)))
})

It("podman pod restart single pod by name", func() {
Expand Down Expand Up @@ -152,6 +157,10 @@ var _ = Describe("Podman pod restart", func() {

session = podmanTest.Podman([]string{"pod", "restart", podid1, "doesnotexist"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
expect := "no pod with name or ID doesnotexist found: no such pod"
if IsRemote() {
expect = `unable to find pod "doesnotexist": no such pod`
}
Expect(session).Should(ExitWithError(125, expect))
})
})
23 changes: 18 additions & 5 deletions test/e2e/pod_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("Podman pod start", func() {
It("podman pod start bogus pod", func() {
session := podmanTest.Podman([]string{"pod", "start", "123"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
expect := "no pod with name or ID 123 found: no such pod"
if IsRemote() {
expect = `unable to find pod "123": no such pod`
}
Expect(session).Should(ExitWithError(125, expect))
})

It("podman pod start single empty pod", func() {
Expand All @@ -26,7 +29,12 @@ var _ = Describe("Podman pod start", func() {

session := podmanTest.Podman([]string{"pod", "start", podid})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
expect := fmt.Sprintf("no containers in pod %s have no dependencies, cannot start pod: no such container", podid)
if IsRemote() {
// FIXME: #22989 no error message
expect = "Error:"
}
Expect(session).Should(ExitWithError(125, expect))
})

It("podman pod start single pod by name", func() {
Expand Down Expand Up @@ -94,7 +102,8 @@ var _ = Describe("Podman pod start", func() {

session = podmanTest.Podman([]string{"pod", "start", podid1, podid2})
session.WaitWithDefaultTimeout()
Expect(session).To(Exit(125))
// Different network backends emit different messages; check only the common part
Expect(session).To(ExitWithError(125, "ddress already in use"))
})

It("podman pod start all pods", func() {
Expand Down Expand Up @@ -153,7 +162,11 @@ var _ = Describe("Podman pod start", func() {

session = podmanTest.Podman([]string{"pod", "start", podid, "doesnotexist"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
expect := "no pod with name or ID doesnotexist found: no such pod"
if IsRemote() {
expect = `unable to find pod "doesnotexist": no such pod`
}
Expect(session).Should(ExitWithError(125, expect))
})

It("podman pod start single pod via --pod-id-file", func() {
Expand Down
19 changes: 15 additions & 4 deletions test/e2e/pod_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("Podman pod stop", func() {

It("podman pod stop bogus pod", func() {
session := podmanTest.Podman([]string{"pod", "stop", "123"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
expect := "no pod with name or ID 123 found: no such pod"
if IsRemote() {
expect = `unable to find pod "123": no such pod`
}
Expect(session).Should(ExitWithError(125, expect))
})

It("podman pod stop --ignore bogus pod", func() {
Expand All @@ -34,7 +37,11 @@ var _ = Describe("Podman pod stop", func() {

session = podmanTest.Podman([]string{"pod", "stop", "bogus", "test1"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
expect := "no pod with name or ID bogus found: no such pod"
if IsRemote() {
expect = `unable to find pod "bogus": no such pod`
}
Expect(session).Should(ExitWithError(125, expect))
})

It("podman stop --ignore bogus pod and a running pod", func() {
Expand Down Expand Up @@ -155,7 +162,11 @@ var _ = Describe("Podman pod stop", func() {

session = podmanTest.Podman([]string{"pod", "stop", podid1, "doesnotexist"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
expect := "no pod with name or ID doesnotexist found: no such pod"
if IsRemote() {
expect = `unable to find pod "doesnotexist": no such pod`
}
Expect(session).Should(ExitWithError(125, expect))
})

It("podman pod start/stop single pod via --pod-id-file", func() {
Expand Down
22 changes: 17 additions & 5 deletions test/e2e/pod_top_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("Podman top", func() {

It("podman pod top without pod name or id", func() {
result := podmanTest.Podman([]string{"pod", "top"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, "you must provide the name or id of a running pod"))
})

It("podman pod top on bogus pod", func() {
result := podmanTest.Podman([]string{"pod", "top", "1234"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
expect := "no pod with name or ID 1234 found: no such pod"
if !IsRemote() {
expect = "unable to look up requested container: " + expect
}
Expect(result).Should(ExitWithError(125, expect))
})

It("podman pod top on non-running pod", func() {
Expand All @@ -30,7 +33,11 @@ var _ = Describe("Podman top", func() {

result := podmanTest.Podman([]string{"top", podid})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
expect := fmt.Sprintf(`no container with name or ID "%s" found: no such container`, podid)
if !IsRemote() {
expect = "unable to look up requested container: " + expect
}
Expect(result).Should(ExitWithError(125, expect))
})

It("podman pod top on pod", func() {
Expand Down Expand Up @@ -78,7 +85,12 @@ var _ = Describe("Podman top", func() {
// the wrong input and still print the -ef output instead.
result := podmanTest.Podman([]string{"pod", "top", podid, "-eo", "invalid"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
if IsRemote() {
// FIXME: #22986
Expect(result).Should(ExitWithError(125, "unmarshalling into &handlers.PodTopOKBody{ContainerTopOKBody:container.ContainerTopOKBody"))
} else {
Expect(result).Should(ExitWithError(125, "Error: '-eo': unknown descriptor"))
}
})

It("podman pod top on pod with containers in same pid namespace", func() {
Expand Down

0 comments on commit d810f41

Please sign in to comment.