Skip to content

Commit

Permalink
Merge pull request #23087 from edsantiago/exitwitherror-more
Browse files Browse the repository at this point in the history
ExitWithError(): continued
  • Loading branch information
openshift-merge-bot[bot] authored Jun 25, 2024
2 parents c0ec20b + f507346 commit ac4143a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 57 deletions.
19 changes: 9 additions & 10 deletions test/e2e/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("Podman restart", func() {
It("podman restart bogus container", func() {
session := podmanTest.Podman([]string{"start", "123"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, `no container with name or ID "123" found: no such container`))
})

It("podman restart stopped container by name", func() {
Expand Down Expand Up @@ -283,20 +283,19 @@ var _ = Describe("Podman restart", func() {
SkipIfRemote("--latest flag n/a")
result := podmanTest.Podman([]string{"restart", "--cidfile", "foobar", "--latest"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring("cannot be used together"))
Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together"))

result = podmanTest.Podman([]string{"restart", "--cidfile", "foobar", "--all"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring("cannot be used together"))
Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together"))

result = podmanTest.Podman([]string{"restart", "--cidfile", "foobar", "--all", "--latest"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring("cannot be used together"))
Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together"))

result = podmanTest.Podman([]string{"restart", "--latest", "--all"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring("cannot be used together"))
Expect(result).Should(ExitWithError(125, "--all and --latest cannot be used together"))
})

It("podman restart --filter", func() {
Expand All @@ -318,7 +317,7 @@ var _ = Describe("Podman restart", func() {

session1 = podmanTest.Podman([]string{"restart", cid1, "-f", "status=test"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(125))
Expect(session1).Should(ExitWithError(125, "--filter takes no arguments"))

session1 = podmanTest.Podman([]string{"restart", "-a", "--filter", fmt.Sprintf("id=%swrongid", shortCid3)})
session1.WaitWithDefaultTimeout()
Expand Down
34 changes: 11 additions & 23 deletions test/e2e/rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 rm", func() {
Expand All @@ -29,8 +28,7 @@ var _ = Describe("Podman rm", func() {

result := podmanTest.Podman([]string{"rm", cid})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(2))
Expect(result.ErrorToString()).To(ContainSubstring("containers cannot be removed without force"))
Expect(result).Should(ExitWithError(2, "containers cannot be removed without force"))
})

It("podman rm created container", func() {
Expand Down Expand Up @@ -169,23 +167,19 @@ var _ = Describe("Podman rm", func() {

result := podmanTest.Podman([]string{"rm", "--cidfile", "foobar", "--latest"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring("--all, --latest, and --cidfile cannot be used together"))
Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together"))

result = podmanTest.Podman([]string{"rm", "--cidfile", "foobar", "--all"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring("--all, --latest, and --cidfile cannot be used together"))
Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together"))

result = podmanTest.Podman([]string{"rm", "--cidfile", "foobar", "--all", "--latest"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring("--all, --latest, and --cidfile cannot be used together"))
Expect(result).Should(ExitWithError(125, "--all, --latest, and --cidfile cannot be used together"))

result = podmanTest.Podman([]string{"rm", "--latest", "--all"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring("--all and --latest cannot be used together"))
Expect(result).Should(ExitWithError(125, "--all and --latest cannot be used together"))
})

It("podman rm --all", func() {
Expand Down Expand Up @@ -214,8 +208,7 @@ var _ = Describe("Podman rm", func() {

session = podmanTest.Podman([]string{"rm", "bogus", cid})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session.ErrorToString()).To(ContainSubstring("\"bogus\" found: no such container"))
Expect(session).Should(ExitWithError(1, `no container with ID or name "bogus" found: no such container`))
if IsRemote() {
Expect(session.OutputToString()).To(BeEquivalentTo(cid))
}
Expand All @@ -232,8 +225,7 @@ var _ = Describe("Podman rm", func() {
It("podman rm bogus container", func() {
session := podmanTest.Podman([]string{"rm", "bogus"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session.ErrorToString()).To(ContainSubstring("\"bogus\" found: no such container"))
Expect(session).Should(ExitWithError(1, `no container with ID or name "bogus" found: no such container`))
})

It("podman rm bogus container and a running container", func() {
Expand All @@ -243,13 +235,11 @@ var _ = Describe("Podman rm", func() {

session = podmanTest.Podman([]string{"rm", "bogus", "test1"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session.ErrorToString()).To(ContainSubstring("\"bogus\" found: no such container"))
Expect(session).Should(ExitWithError(1, `no container with ID or name "bogus" found: no such container`))

session = podmanTest.Podman([]string{"rm", "test1", "bogus"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session.ErrorToString()).To(ContainSubstring("\"bogus\" found: no such container"))
Expect(session).Should(ExitWithError(1, `no container with ID or name "bogus" found: no such container`))
})

It("podman rm --ignore bogus container and a running container", func() {
Expand All @@ -259,8 +249,7 @@ var _ = Describe("Podman rm", func() {

session = podmanTest.Podman([]string{"rm", "--ignore", "test1", "bogus"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(2))
Expect(session.ErrorToString()).To(ContainSubstring("containers cannot be removed without force"))
Expect(session).Should(ExitWithError(2, "containers cannot be removed without force"))

session = podmanTest.Podman([]string{"rm", "-t", "0", "--force", "--ignore", "bogus", "test1"})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -292,8 +281,7 @@ var _ = Describe("Podman rm", func() {

session1 = podmanTest.Podman([]string{"rm", cid1, "-f", "--filter", "status=running"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(125))
Expect(session1.ErrorToString()).To(ContainSubstring("--filter takes no arguments"))
Expect(session1).Should(ExitWithError(125, "--filter takes no arguments"))

session1 = podmanTest.Podman([]string{"rm", "-a", "-f", "--filter", fmt.Sprintf("id=%swrongid", shortCid3)})
session1.WaitWithDefaultTimeout()
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/run_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

func createContainersConfFileWithDevices(pTest *PodmanTestIntegration, devices string) {
Expand Down Expand Up @@ -95,7 +94,7 @@ var _ = Describe("Podman run device", func() {
// verify --privileged is required
session2 := podmanTest.Podman([]string{"run", ALPINE, "test", "-c", "/dev/kmsg"})
session2.WaitWithDefaultTimeout()
Expect(session2).Should(Exit(1))
Expect(session2).Should(ExitWithError(1, ""))
Expect(session2.OutputToString()).To(BeEmpty())
})

Expand Down
8 changes: 3 additions & 5 deletions test/e2e/run_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 run", func() {
Expand Down Expand Up @@ -54,7 +53,7 @@ var _ = Describe("Podman run", func() {
session = podmanTest.Podman([]string{"run", "--rm", "--env", "FOO", ALPINE, "printenv", "FOO"})
session.WaitWithDefaultTimeout()
Expect(session.OutputToString()).To(BeEmpty())
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, ""))

session = podmanTest.Podman([]string{"run", "--rm", ALPINE, "printenv"})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -90,8 +89,7 @@ ENV hello=world
session.WaitWithDefaultTimeout()
if IsRemote() {
// podman-remote does not support --env-host
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("unknown flag: --env-host"))
Expect(session).Should(ExitWithError(125, "unknown flag: --env-host"))
return
}
Expect(session).Should(ExitCleanly())
Expand Down Expand Up @@ -125,7 +123,7 @@ ENV hello=world

session = podmanTest.Podman([]string{"run", "--http-proxy=false", ALPINE, "printenv", "http_proxy"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, ""))
Expect(session.OutputToString()).To(Equal(""))

session = podmanTest.Podman([]string{"run", "--env", "http_proxy=5.6.7.8", ALPINE, "printenv", "http_proxy"})
Expand Down
11 changes: 5 additions & 6 deletions test/e2e/run_exit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ 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 exit", func() {

It("podman run exit define.ExecErrorCodeGeneric", func() {
result := podmanTest.Podman([]string{"run", "--foobar", ALPINE, "ls", "$tmp"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(define.ExecErrorCodeGeneric))
Expect(result).Should(ExitWithError(define.ExecErrorCodeGeneric, "unknown flag: --foobar"))
})

It("podman run exit ExecErrorCodeCannotInvoke", func() {
result := podmanTest.Podman([]string{"run", ALPINE, "/etc"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(define.ExecErrorCodeCannotInvoke))
Expect(result).Should(ExitWithError(define.ExecErrorCodeCannotInvoke, "open executable: Operation not permitted: OCI permission denied"))
})

It("podman run exit ExecErrorCodeNotFound", func() {
result := podmanTest.Podman([]string{"run", ALPINE, "foobar"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(define.ExecErrorCodeNotFound))
Expect(result).Should(ExitWithError(define.ExecErrorCodeNotFound, "executable file `foobar` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found"))
})

It("podman run exit 0", func() {
Expand All @@ -39,12 +38,12 @@ var _ = Describe("Podman run exit", func() {
It("podman run exit 50", func() {
result := podmanTest.Podman([]string{"run", ALPINE, "sh", "-c", "exit 50"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(50))
Expect(result).Should(ExitWithError(50, ""))
})

It("podman run exit 125", func() {
result := podmanTest.Podman([]string{"run", ALPINE, "sh", "-c", fmt.Sprintf("exit %d", define.ExecErrorCodeGeneric)})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(define.ExecErrorCodeGeneric))
Expect(result).Should(ExitWithError(define.ExecErrorCodeGeneric, ""))
})
})
3 changes: 1 addition & 2 deletions test/e2e/run_selinux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"github.com/opencontainers/selinux/go-selinux"
)

Expand Down Expand Up @@ -124,7 +123,7 @@ var _ = Describe("Podman run", func() {

session = podmanTest.Podman([]string{"run", "--security-opt", "label=type:spc_t", "--security-opt", "label=filetype:foobar", fedoraMinimal, "ls", "-Z", "/dev"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(126))
Expect(session).Should(ExitWithError(126, "invalid argument"))
})

It("podman exec selinux check", func() {
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/run_userns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/containers/storage"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

func createContainersConfFileWithCustomUserns(pTest *PodmanTestIntegration, userns string) {
Expand Down Expand Up @@ -371,13 +370,11 @@ var _ = Describe("Podman UserNS support", func() {
It("podman --userns= conflicts with ui[dg]map and sub[ug]idname", func() {
session := podmanTest.Podman([]string{"run", "--userns=host", "--uidmap=0:1:500", "alpine", "true"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("--userns and --uidmap/--gidmap/--subuidname/--subgidname are mutually exclusive"))
Expect(session).Should(ExitWithError(125, "--userns and --uidmap/--gidmap/--subuidname/--subgidname are mutually exclusive"))

session = podmanTest.Podman([]string{"run", "--userns=host", "--gidmap=0:200:5000", "alpine", "true"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("--userns and --uidmap/--gidmap/--subuidname/--subgidname are mutually exclusive"))
Expect(session).Should(ExitWithError(125, "--userns and --uidmap/--gidmap/--subuidname/--subgidname are mutually exclusive"))

// with sub[ug]idname we don't check for the error output since the error message could be different, depending on the
// system configuration since the specified user could not be defined and cause a different earlier error.
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var _ = Describe("Podman run with volumes", func() {
Expect(err).ToNot(HaveOccurred())
session := podmanTest.Podman([]string{"run", "-v", mountPath + ":" + dest, "-v", "/tmp" + ":" + dest, ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, fmt.Sprintf("%s: duplicate mount destination", dest)))
})

It("podman run with conflict between image volume and user mount succeeds", func() {
Expand Down Expand Up @@ -430,7 +430,7 @@ var _ = Describe("Podman run with volumes", func() {

noCopySession := podmanTest.Podman([]string{"run", "--rm", "-v", "testvol4:/etc/apk:nocopy", ALPINE, "stat", "-c", "%h", "/etc/apk/arch"})
noCopySession.WaitWithDefaultTimeout()
Expect(noCopySession).Should(Exit(1))
Expect(noCopySession).Should(ExitWithError(1, "stat: can't stat '/etc/apk/arch': No such file or directory"))
})

It("podman named volume copyup symlink", func() {
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/run_working_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 run", func() {
Expand All @@ -23,7 +22,7 @@ var _ = Describe("Podman run", func() {
It("podman run a container using non existing --workdir", func() {
session := podmanTest.Podman([]string{"run", "--workdir", "/home/foobar", ALPINE, "pwd"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(126))
Expect(session).Should(ExitWithError(126, `workdir "/home/foobar" does not exist on container `))
})

It("podman run a container using a --workdir under a bind mount", func() {
Expand Down

0 comments on commit ac4143a

Please sign in to comment.