Merge pull request #22987 from edsantiago/exitwitherror-yetmore

ExitWithError() - more upgrades from Exit()
This commit is contained in:
openshift-merge-bot[bot]
2024-06-24 11:06:57 +00:00
committed by GitHub
5 changed files with 69 additions and 25 deletions

View File

@ -8,7 +8,6 @@ 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() {
@ -16,13 +15,13 @@ 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() {
@ -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() {
@ -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"})
@ -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)))
})

View File

@ -1,10 +1,11 @@
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() {
@ -12,7 +13,11 @@ 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() {
@ -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() {
@ -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))
})
})

View File

@ -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() {
@ -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() {
@ -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() {
@ -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() {

View File

@ -6,7 +6,6 @@ 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() {
@ -14,7 +13,11 @@ 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() {
@ -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() {
@ -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() {

View File

@ -7,7 +7,6 @@ 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() {
@ -15,13 +14,17 @@ 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() {
@ -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() {
@ -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() {