From d810f4187e32a410de8ae513a77a3e5df6182432 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Wed, 12 Jun 2024 11:04:28 -0600 Subject: [PATCH] ExitWithError() - more upgrades from Exit() Add error-message checks to pod_xxxx_test.go Signed-off-by: Ed Santiago --- test/e2e/pod_initcontainers_test.go | 13 ++++++------- test/e2e/pod_restart_test.go | 17 +++++++++++++---- test/e2e/pod_start_test.go | 23 ++++++++++++++++++----- test/e2e/pod_stop_test.go | 19 +++++++++++++++---- test/e2e/pod_top_test.go | 22 +++++++++++++++++----- 5 files changed, 69 insertions(+), 25 deletions(-) diff --git a/test/e2e/pod_initcontainers_test.go b/test/e2e/pod_initcontainers_test.go index 8c0e79b15a..5aa291ed6f 100644 --- a/test/e2e/pod_initcontainers_test.go +++ b/test/e2e/pod_initcontainers_test.go @@ -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))) }) diff --git a/test/e2e/pod_restart_test.go b/test/e2e/pod_restart_test.go index 839b5cc764..8a07533872 100644 --- a/test/e2e/pod_restart_test.go +++ b/test/e2e/pod_restart_test.go @@ -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)) }) }) diff --git a/test/e2e/pod_start_test.go b/test/e2e/pod_start_test.go index bc4a19a104..03a445d431 100644 --- a/test/e2e/pod_start_test.go +++ b/test/e2e/pod_start_test.go @@ -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() { diff --git a/test/e2e/pod_stop_test.go b/test/e2e/pod_stop_test.go index 9226d14619..d68621d3f2 100644 --- a/test/e2e/pod_stop_test.go +++ b/test/e2e/pod_stop_test.go @@ -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() { diff --git a/test/e2e/pod_top_test.go b/test/e2e/pod_top_test.go index 52b0917e5a..387422c497 100644 --- a/test/e2e/pod_top_test.go +++ b/test/e2e/pod_top_test.go @@ -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() {