From de58c5f29217740713471351eb462f191db23521 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Tue, 25 Jun 2024 09:12:28 -0600 Subject: [PATCH] ExitWithError() - more upgrades from Exit() Signed-off-by: Ed Santiago --- test/e2e/run_entrypoint_test.go | 3 +-- test/e2e/run_test.go | 40 +++++++++++------------------- test/e2e/secret_test.go | 3 +-- test/e2e/stop_test.go | 14 +++++------ test/e2e/system_dial_stdio_test.go | 4 +-- test/e2e/top_test.go | 16 ++++++------ test/e2e/unshare_test.go | 19 +++++--------- test/e2e/wait_test.go | 5 ++-- 8 files changed, 42 insertions(+), 62 deletions(-) diff --git a/test/e2e/run_entrypoint_test.go b/test/e2e/run_entrypoint_test.go index e39c377cce..687847c1f3 100644 --- a/test/e2e/run_entrypoint_test.go +++ b/test/e2e/run_entrypoint_test.go @@ -4,7 +4,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 run entrypoint", func() { @@ -17,7 +16,7 @@ CMD [] podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false") session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Or(Exit(126), Exit(127))) + Expect(session).Should(ExitWithError(126, "open executable: Operation not permitted: OCI permission denied")) }) It("podman run entrypoint == [\"\"]", func() { diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index 6fde7685c7..6fd7fb1334 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -232,8 +232,7 @@ var _ = Describe("Podman run", func() { run := podmanTest.Podman([]string{"run", pushedImage, "date"}) run.WaitWithDefaultTimeout() - Expect(run).Should(Exit(125)) - Expect(run.ErrorToString()).To(ContainSubstring("pinging container registry localhost:" + port)) + Expect(run).Should(ExitWithError(125, "pinging container registry localhost:"+port)) Expect(run.ErrorToString()).To(ContainSubstring("http: server gave HTTP response to HTTPS client")) run = podmanTest.Podman([]string{"run", "--tls-verify=false", pushedImage, "echo", "got here"}) @@ -393,8 +392,7 @@ var _ = Describe("Podman run", func() { if _, err := os.Stat(mask); err == nil { session = podmanTest.Podman([]string{"exec", "maskCtr", "touch", mask}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(1)) - Expect(session.ErrorToString()).To(Equal(fmt.Sprintf("touch: %s: Read-only file system", mask))) + Expect(session).Should(ExitWithError(1, fmt.Sprintf("touch: %s: Read-only file system", mask))) } } }) @@ -530,15 +528,13 @@ var _ = Describe("Podman run", func() { cmd = append(secOpts, cmd...) session = podmanTest.Podman(append([]string{"run"}, cmd...)) session.WaitWithDefaultTimeout() - Expect(session).To(Exit(1)) - Expect(session.ErrorToString()).To(ContainSubstring("ln: /linkNotAllowed: Operation not permitted")) + Expect(session).To(ExitWithError(1, "ln: /linkNotAllowed: Operation not permitted")) // ...even with --privileged cmd = append([]string{"--privileged"}, cmd...) session = podmanTest.Podman(append([]string{"run"}, cmd...)) session.WaitWithDefaultTimeout() - Expect(session).To(Exit(1)) - Expect(session.ErrorToString()).To(ContainSubstring("ln: /linkNotAllowed: Operation not permitted")) + Expect(session).To(ExitWithError(1, "ln: /linkNotAllowed: Operation not permitted")) }) It("podman run seccomp test --privileged no profile should be unconfined", func() { @@ -791,7 +787,7 @@ USER bin`, BB) // network sysctls should fail if --net=host is set session = podmanTest.Podman([]string{"run", "--net", "host", "--rm", "--sysctl", "net.core.somaxconn=65535", ALPINE, "sysctl", "net.core.somaxconn"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) + Expect(session).Should(ExitWithError(125, "sysctl net.core.somaxconn=65535 can't be set since Network Namespace set to host: invalid argument")) }) It("podman run blkio-weight test", func() { @@ -1126,19 +1122,19 @@ echo -n %s >%s It("podman run attach nonsense errors", func() { session := podmanTest.Podman([]string{"run", "--rm", "--attach", "asdfasdf", ALPINE, "ls", "/"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) + Expect(session).Should(ExitWithError(125, `invalid stream "asdfasdf" for --attach - must be one of stdin, stdout, or stderr: invalid argument`)) }) It("podman run exit code on failure to exec", func() { session := podmanTest.Podman([]string{"run", ALPINE, "/etc"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(126)) + Expect(session).Should(ExitWithError(126, "open executable: Operation not permitted: OCI permission denied")) }) It("podman run error on exec", func() { session := podmanTest.Podman([]string{"run", ALPINE, "sh", "-c", "exit 100"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(100)) + Expect(session).Should(ExitWithError(100, "")) }) It("podman run with named volume", func() { @@ -1222,8 +1218,7 @@ USER mail`, BB) // check that the read-only option works session = podmanTest.Podman([]string{"run", "--volumes-from", ctrID + ":ro", ALPINE, "touch", mountpoint + "abc.txt"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(1)) - Expect(session.ErrorToString()).To(ContainSubstring("Read-only file system")) + Expect(session).Should(ExitWithError(1, "Read-only file system")) // check that both z and ro options work session = podmanTest.Podman([]string{"run", "--volumes-from", ctrID + ":ro,z", ALPINE, "cat", mountpoint + filename}) @@ -1234,14 +1229,12 @@ USER mail`, BB) // check that multiple ro/rw are not working session = podmanTest.Podman([]string{"run", "--volumes-from", ctrID + ":ro,rw", ALPINE, "cat", mountpoint + filename}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) - Expect(session.ErrorToString()).To(ContainSubstring("cannot set ro or rw options more than once")) + Expect(session).Should(ExitWithError(125, "cannot set ro or rw options more than once")) // check that multiple z options are not working session = podmanTest.Podman([]string{"run", "--volumes-from", ctrID + ":z,z,ro", ALPINE, "cat", mountpoint + filename}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) - Expect(session.ErrorToString()).To(ContainSubstring("cannot set :z more than once in mount options")) + Expect(session).Should(ExitWithError(125, "cannot set :z more than once in mount options")) // create new read-only volume session = podmanTest.Podman([]string{"create", "--volume", vol + ":" + mountpoint + ":ro", ALPINE, "cat", mountpoint + filename}) @@ -1252,8 +1245,7 @@ USER mail`, BB) // check if the original volume was mounted as read-only that --volumes-from also mount it as read-only session = podmanTest.Podman([]string{"run", "--volumes-from", ctrID, ALPINE, "touch", mountpoint + "abc.txt"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(1)) - Expect(session.ErrorToString()).To(ContainSubstring("Read-only file system")) + Expect(session).Should(ExitWithError(1, "Read-only file system")) }) It("podman run --volumes-from flag with built-in volumes", func() { @@ -1699,8 +1691,7 @@ VOLUME %s`, ALPINE, volPath, volPath) // Make sure we error out with --name. session := podmanTest.Podman([]string{"create", "--replace", ALPINE, "/bin/sh"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) - Expect(session.ErrorToString()).To(ContainSubstring("cannot replace container without --name being set")) + Expect(session).Should(ExitWithError(125, "cannot replace container without --name being set")) // Run and replace 5 times in a row the "same" container. ctrName := "testCtr" @@ -1852,7 +1843,7 @@ WORKDIR /madethis`, BB) It("podman run a container with --pull never should fail if no local store", func() { session := podmanTest.Podman([]string{"run", "--pull", "never", "docker.io/library/debian:latest", "ls"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) + Expect(session).Should(ExitWithError(125, "Error: docker.io/library/debian:latest: image not known")) }) It("podman run container with --pull missing and only pull once", func() { @@ -2180,8 +2171,7 @@ WORKDIR /madethis`, BB) // Must fail without --decryption-key session = podmanTest.Podman([]string{"run", "--tls-verify=false", imgPath}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) - Expect(session.ErrorToString()).To(ContainSubstring("Trying to pull " + imgPath)) + Expect(session).Should(ExitWithError(125, "Trying to pull "+imgPath)) Expect(session.ErrorToString()).To(ContainSubstring("invalid tar header")) // With diff --git a/test/e2e/secret_test.go b/test/e2e/secret_test.go index 1f5cee9463..71d5fc34bf 100644 --- a/test/e2e/secret_test.go +++ b/test/e2e/secret_test.go @@ -9,7 +9,6 @@ import ( "github.com/containers/storage/pkg/stringid" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/onsi/gomega/gexec" ) var _ = Describe("Podman secret", func() { @@ -430,6 +429,6 @@ var _ = Describe("Podman secret", func() { exists := podmanTest.Podman([]string{"secret", "exists", secretName}) exists.WaitWithDefaultTimeout() - Expect(exists).Should(Exit(1)) + Expect(exists).Should(ExitWithError(1, "")) }) }) diff --git a/test/e2e/stop_test.go b/test/e2e/stop_test.go index bdce8368ed..74b2b63d2c 100644 --- a/test/e2e/stop_test.go +++ b/test/e2e/stop_test.go @@ -16,7 +16,7 @@ var _ = Describe("Podman stop", func() { It("podman stop bogus container", func() { session := podmanTest.Podman([]string{"stop", "foobar"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) + Expect(session).Should(ExitWithError(125, `no container with name or ID "foobar" found: no such container`)) }) It("podman stop --ignore bogus container", func() { @@ -307,19 +307,19 @@ var _ = Describe("Podman stop", func() { result := podmanTest.Podman([]string{"stop", "--cidfile", "foobar", "--latest"}) result.WaitWithDefaultTimeout() - Expect(result).Should(Exit(125)) + Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together")) result = podmanTest.Podman([]string{"stop", "--cidfile", "foobar", "--all"}) result.WaitWithDefaultTimeout() - Expect(result).Should(Exit(125)) + Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together")) result = podmanTest.Podman([]string{"stop", "--cidfile", "foobar", "--all", "--latest"}) result.WaitWithDefaultTimeout() - Expect(result).Should(Exit(125)) + Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together")) result = podmanTest.Podman([]string{"stop", "--latest", "--all"}) result.WaitWithDefaultTimeout() - Expect(result).Should(Exit(125)) + Expect(result).Should(ExitWithError(125, "--all and --latest cannot be used together")) }) It("podman stop --all", func() { @@ -348,7 +348,7 @@ var _ = Describe("Podman stop", func() { session = podmanTest.Podman([]string{"stop", "bogus", cid}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) + Expect(session).Should(ExitWithError(125, `no container with name or ID "bogus" found: no such container`)) session = podmanTest.Podman([]string{"stop", "--ignore", "bogus", cid}) session.WaitWithDefaultTimeout() @@ -384,7 +384,7 @@ var _ = Describe("Podman stop", func() { session1 = podmanTest.Podman([]string{"stop", cid1, "-f", "status=running"}) session1.WaitWithDefaultTimeout() - Expect(session1).Should(Exit(125)) + Expect(session1).Should(ExitWithError(125, "--filter takes no arguments")) session1 = podmanTest.Podman([]string{"stop", "-a", "--filter", fmt.Sprintf("id=%swrongid", shortCid3)}) session1.WaitWithDefaultTimeout() diff --git a/test/e2e/system_dial_stdio_test.go b/test/e2e/system_dial_stdio_test.go index 43cf47773e..35dfd5efee 100644 --- a/test/e2e/system_dial_stdio_test.go +++ b/test/e2e/system_dial_stdio_test.go @@ -4,7 +4,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 system dial-stdio", func() { @@ -22,7 +21,6 @@ var _ = Describe("podman system dial-stdio", func() { } session := podmanTest.Podman([]string{"system", "dial-stdio"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) - Expect(session.ErrorToString()).To(ContainSubstring("Error: failed to open connection to podman")) + Expect(session).Should(ExitWithError(125, "Error: failed to open connection to podman")) }) }) diff --git a/test/e2e/top_test.go b/test/e2e/top_test.go index 4726934c36..d67c607735 100644 --- a/test/e2e/top_test.go +++ b/test/e2e/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 top without container name or id", func() { result := podmanTest.Podman([]string{"top"}) result.WaitWithDefaultTimeout() - Expect(result).Should(Exit(125)) + Expect(result).Should(ExitWithError(125, "you must provide the name or id of a running container")) }) It("podman top on bogus container", func() { result := podmanTest.Podman([]string{"top", "1234"}) result.WaitWithDefaultTimeout() - Expect(result).Should(Exit(125)) + expect := `no container with name or ID "1234" found: no such container` + if !IsRemote() { + expect = `unable to look up requested container: ` + expect + } + Expect(result).Should(ExitWithError(125, expect)) }) It("podman top on non-running container", func() { @@ -29,7 +32,7 @@ var _ = Describe("Podman top", func() { Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"top", cid}) result.WaitWithDefaultTimeout() - Expect(result).Should(Exit(125)) + Expect(result).Should(ExitWithError(125, "top can only be used on running containers")) }) It("podman top on container", func() { @@ -115,8 +118,7 @@ var _ = Describe("Podman top", func() { // Because the image does not contain this must fail and we know we use the correct podman exec fallback. exec := podmanTest.Podman([]string{"top", session.OutputToString(), "aux"}) exec.WaitWithDefaultTimeout() - Expect(exec).Should(Exit(125)) - Expect(exec.ErrorToString()).Should(ContainSubstring("OCI runtime attempted to invoke a command that was not found")) + Expect(exec).Should(ExitWithError(125, "OCI runtime attempted to invoke a command that was not found")) }) It("podman top with comma-separated options", func() { @@ -142,7 +144,7 @@ var _ = Describe("Podman top", func() { // the wrong input and still print the -ef output instead. result := podmanTest.Podman([]string{"top", cid, "-eo", "invalid"}) result.WaitWithDefaultTimeout() - Expect(result).Should(Exit(125)) + Expect(result).Should(ExitWithError(125, `Error: ps(1) failed with exit code 1: error: unknown user-defined format specifier "invalid"`)) }) It("podman top on privileged container", func() { diff --git a/test/e2e/unshare_test.go b/test/e2e/unshare_test.go index b004fe2800..9fc5c6d79a 100644 --- a/test/e2e/unshare_test.go +++ b/test/e2e/unshare_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 unshare", func() { @@ -33,40 +32,34 @@ var _ = Describe("Podman unshare", func() { SkipIfRemote("podman-remote unshare is not supported") session := podmanTest.Podman([]string{"unshare", "false"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(1)) + Expect(session).Should(ExitWithError(1, "")) Expect(session.OutputToString()).Should(Equal("")) - Expect(session.ErrorToString()).Should(Equal("")) session = podmanTest.Podman([]string{"unshare", "/usr/bin/bogus"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(127)) + Expect(session).Should(ExitWithError(127, "no such file or directory")) Expect(session.OutputToString()).Should(Equal("")) - Expect(session.ErrorToString()).Should(ContainSubstring("no such file or directory")) session = podmanTest.Podman([]string{"unshare", "bogus"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(127)) + Expect(session).Should(ExitWithError(127, "executable file not found in $PATH")) Expect(session.OutputToString()).Should(Equal("")) - Expect(session.ErrorToString()).Should(ContainSubstring("executable file not found in $PATH")) session = podmanTest.Podman([]string{"unshare", "/usr"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(126)) + Expect(session).Should(ExitWithError(126, "permission denied")) Expect(session.OutputToString()).Should(Equal("")) - Expect(session.ErrorToString()).Should(ContainSubstring("permission denied")) session = podmanTest.Podman([]string{"unshare", "--bogus"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) + Expect(session).Should(ExitWithError(125, "unknown flag: --bogus")) Expect(session.OutputToString()).Should(Equal("")) - Expect(session.ErrorToString()).Should(ContainSubstring("unknown flag: --bogus")) }) It("podman unshare check remote error", func() { SkipIfNotRemote("check for podman-remote unshare error") session := podmanTest.Podman([]string{"unshare"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) - Expect(session.ErrorToString()).To(Equal(`Error: cannot use command "podman-remote unshare" with the remote podman client`)) + Expect(session).Should(ExitWithError(125, `Error: cannot use command "podman-remote unshare" with the remote podman client`)) }) }) diff --git a/test/e2e/wait_test.go b/test/e2e/wait_test.go index 7d84a88d14..205c4d33dd 100644 --- a/test/e2e/wait_test.go +++ b/test/e2e/wait_test.go @@ -4,7 +4,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 wait", func() { @@ -12,7 +11,7 @@ var _ = Describe("Podman wait", func() { It("podman wait on bogus container", func() { session := podmanTest.Podman([]string{"wait", "1234"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) + Expect(session).Should(ExitWithError(125, `no container with name or ID "1234" found: no such container`)) }) @@ -86,7 +85,7 @@ var _ = Describe("Podman wait", func() { Expect(session).Should(ExitCleanly()) session = podmanTest.Podman([]string{"container", "wait", "--interval", "100days", session.OutputToString()}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) + Expect(session).Should(ExitWithError(125, `time: unknown unit "days" in duration "100days"`)) }) It("podman wait on three containers", func() {