Skip to content

Commit

Permalink
Merge pull request #22489 from edsantiago/exitwitherror-yetmorelowhan…
Browse files Browse the repository at this point in the history
…gingfruit

ExitWithError() - yet more low-hanging fruit
  • Loading branch information
openshift-merge-bot[bot] authored Apr 25, 2024
2 parents 1526ebf + e4c9910 commit 0ccee4e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
26 changes: 11 additions & 15 deletions test/e2e/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ var _ = Describe("Podman logs", func() {
It("podman logs on not existent container", func() {
results := podmanTest.Podman([]string{"logs", "notexist"})
results.WaitWithDefaultTimeout()
Expect(results).To(Exit(125))
Expect(results.ErrorToString()).To(Equal(`Error: no container with name or ID "notexist" found: no such container`))
Expect(results).To(ExitWithError(125, `no container with name or ID "notexist" found: no such container`))
})

for _, log := range []string{"k8s-file", "journald", "json-file"} {
Expand Down Expand Up @@ -270,7 +269,11 @@ var _ = Describe("Podman logs", func() {

results := podmanTest.Podman([]string{"logs", "-l", "foobar"})
results.WaitWithDefaultTimeout()
Expect(results).To(ExitWithError())
if IsRemote() {
Expect(results).To(ExitWithError(125, "unknown shorthand flag: 'l' in -l"))
} else {
Expect(results).To(ExitWithError(125, "--latest and containers cannot be used together"))
}
})

It("two containers showing short container IDs: "+log, func() {
Expand Down Expand Up @@ -326,8 +329,7 @@ var _ = Describe("Podman logs", func() {

if log == "journald" && !isEventBackendJournald(podmanTest) {
// --follow + journald log-driver is only supported with journald events-backend(PR #10431)
Expect(results).To(Exit(125))
Expect(results.ErrorToString()).To(ContainSubstring("using --follow with the journald --log-driver but without the journald --events-backend"))
Expect(results).To(ExitWithError(125, "using --follow with the journald --log-driver but without the journald --events-backend"))
return
}

Expand Down Expand Up @@ -366,8 +368,7 @@ var _ = Describe("Podman logs", func() {
results.WaitWithDefaultTimeout()
if log == "journald" && !isEventBackendJournald(podmanTest) {
// --follow + journald log-driver is only supported with journald events-backend(PR #10431)
Expect(results).To(Exit(125))
Expect(results.ErrorToString()).To(ContainSubstring("using --follow with the journald --log-driver but without the journald --events-backend"))
Expect(results).To(ExitWithError(125, "using --follow with the journald --log-driver but without the journald --events-backend"))
return
}
Expect(results).To(ExitCleanly())
Expand Down Expand Up @@ -581,8 +582,7 @@ var _ = Describe("Podman logs", func() {

logs := podmanTest.Podman([]string{"logs", "-f", ctrName})
logs.WaitWithDefaultTimeout()
Expect(logs).To(Exit(125))
Expect(logs.ErrorToString()).To(ContainSubstring("this container is using the 'none' log driver, cannot read logs: this container is not logging output"))
Expect(logs).To(ExitWithError(125, "this container is using the 'none' log driver, cannot read logs: this container is not logging output"))
})

It("podman logs with non ASCII log tag fails without correct LANG", func() {
Expand All @@ -595,14 +595,10 @@ var _ = Describe("Podman logs", func() {
defer cleanup()
logc := podmanTest.Podman([]string{"run", "--log-driver", "journald", "--log-opt", "tag=äöüß", ALPINE, "echo", "podman"})
logc.WaitWithDefaultTimeout()
Expect(logc).To(Exit(126))
// FIXME-2023-09-26: conmon <2.1.8 logs to stdout; clean this up once >=2.1.8 is universal
errmsg := logc.ErrorToString() + logc.OutputToString()
Expect(logc).To(ExitWithError(126, "conmon failed: exit status 1"))
if !IsRemote() {
// Error is only seen on local client
Expect(errmsg).To(ContainSubstring("conmon: option parsing failed: Invalid byte sequence in conversion input"))
Expect(logc.ErrorToString()).To(ContainSubstring("conmon: option parsing failed: Invalid byte sequence in conversion input"))
}
Expect(errmsg).To(ContainSubstring("conmon failed: exit status 1"))
})

It("podman logs with non ASCII log tag succeeds with proper env", func() {
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/mount_rootless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ var _ = Describe("Podman mount", func() {

mount := podmanTest.Podman([]string{"mount", cid})
mount.WaitWithDefaultTimeout()
Expect(mount).To(ExitWithError())
Expect(mount.ErrorToString()).To(ContainSubstring("podman unshare"))
Expect(mount).To(ExitWithError(125, "must execute `podman unshare` first"))
})

It("podman unshare podman mount", func() {
Expand All @@ -48,8 +47,7 @@ var _ = Describe("Podman mount", func() {
podmanTest.AddImageToRWStore(ALPINE)
mount := podmanTest.Podman([]string{"image", "mount", ALPINE})
mount.WaitWithDefaultTimeout()
Expect(mount).To(ExitWithError())
Expect(mount.ErrorToString()).To(ContainSubstring("podman unshare"))
Expect(mount).To(ExitWithError(125, "must execute `podman unshare` first"))
})

It("podman unshare image podman mount", func() {
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ var _ = Describe("Podman mount", func() {
Expect(j).Should(ExitCleanly())
Expect(j.OutputToString()).To(BeValidJSON())

j = podmanTest.Podman([]string{"mount", "--format='{{.foobar}}'"})
j = podmanTest.Podman([]string{"mount", "--format={{.foobar}}"})
j.WaitWithDefaultTimeout()
Expect(j).To(ExitWithError())
Expect(j.ErrorToString()).To(ContainSubstring("unknown --format"))
Expect(j).To(ExitWithError(125, `unknown --format argument: "{{.foobar}}"`))

umount := podmanTest.Podman([]string{"umount", cid})
umount.WaitWithDefaultTimeout()
Expand Down
8 changes: 7 additions & 1 deletion test/e2e/negative_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package integration

import (
"fmt"

. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -11,6 +13,10 @@ var _ = Describe("Podman negative command-line", func() {
It("podman snuffleupagus exits non-zero", func() {
session := podmanTest.Podman([]string{"snuffleupagus"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
cmdName := "podman"
if IsRemote() {
cmdName += "-remote"
}
Expect(session).To(ExitWithError(125, fmt.Sprintf("unrecognized command `%s snuffleupagus`", cmdName)))
})
})

1 comment on commit 0ccee4e

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.