Skip to content

Commit

Permalink
ExitWithError() - continued
Browse files Browse the repository at this point in the history
Convert Exit(N) to ExitWithError(N, "expected error")

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed Jun 6, 2024
1 parent 0e57573 commit f317eb2
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 39 deletions.
18 changes: 8 additions & 10 deletions test/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var _ = Describe("Podman build", func() {
It("podman build context directory a file", func() {
session := podmanTest.Podman([]string{"build", "--pull=never", "build/context_dir_a_file"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "context must be a directory:"))
})

// Check that builds with different values for the squash options
Expand Down Expand Up @@ -314,8 +314,7 @@ RUN printenv http_proxy`, CITEST_IMAGE)
// this tries to use the cache so we explicitly disable it
session = podmanTest.Podman([]string{"build", "--no-cache", "--pull-never", "--http-proxy=false", "--file", dockerfilePath, podmanTest.TempDir})
session.Wait(120)
Expect(session).Should(Exit(1))
Expect(session.ErrorToString()).To(ContainSubstring(`Error: building at STEP "RUN printenv http_proxy"`))
Expect(session).Should(ExitWithError(1, `Error: building at STEP "RUN printenv http_proxy"`))
})

It("podman build relay exit code to process", func() {
Expand All @@ -332,7 +331,7 @@ RUN exit 5`, CITEST_IMAGE)
Expect(err).ToNot(HaveOccurred())
session := podmanTest.Podman([]string{"build", "-t", "error-test", "--file", dockerfilePath, podmanTest.TempDir})
session.Wait(120)
Expect(session).Should(Exit(5))
Expect(session).Should(ExitWithError(5, `building at STEP "RUN exit 5": while running runtime: exit status 5`))
})

It("podman build and check identity", func() {
Expand Down Expand Up @@ -398,8 +397,7 @@ COPY /emptydir/* /dir`, CITEST_IMAGE)
// NOTE: Docker and buildah both should error when `COPY /* /dir` is done on emptydir
// as context. However buildkit simply ignores this so when buildah also starts ignoring
// for such case edit this test to return 0 and check that no `/dir` should be in the result.
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("can't make relative to"))
Expect(session).Should(ExitWithError(125, "can't make relative to"))
})

It("podman remote test container/docker file is not inside context dir", func() {
Expand Down Expand Up @@ -757,7 +755,7 @@ RUN grep CapEff /proc/self/status`
})
session.WaitWithDefaultTimeout()
// Then
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, `unrecognized isolation type "bogus"`))
})

It("podman build --timestamp flag", func() {
Expand Down Expand Up @@ -841,7 +839,7 @@ RUN ls /dev/fuse`, CITEST_IMAGE)
Expect(err).ToNot(HaveOccurred())
session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, `building at STEP "RUN ls /dev/fuse": while running runtime: exit status 1`))

session = podmanTest.Podman([]string{"build", "--pull-never", "--device", "/dev/fuse", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expand All @@ -857,7 +855,7 @@ RUN ls /dev/test1`, CITEST_IMAGE)
Expect(err).ToNot(HaveOccurred())
session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, `building at STEP "RUN ls /dev/test1": while running runtime: exit status 1`))

session = podmanTest.Podman([]string{"build", "--pull-never", "--device", "/dev/zero:/dev/test1", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -896,6 +894,6 @@ RUN ls /dev/test1`, CITEST_IMAGE)

session = podmanTest.Podman([]string{"build", "--pull-never", "--file", "build/cache/Dockerfilecacheread", "build/cache/"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, `building at STEP "RUN --mount=type=cache,target=/test,z cat /test/world": while running runtime: exit status 1`))
})
})
10 changes: 3 additions & 7 deletions test/e2e/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 container cleanup", func() {
Expand All @@ -16,8 +15,7 @@ var _ = Describe("Podman container cleanup", func() {
It("podman cleanup bogus container", func() {
session := podmanTest.Podman([]string{"container", "cleanup", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("no such container"))
Expect(session).Should(ExitWithError(125, `no container with name or ID "foobar" found: no such container`))
})

It("podman cleanup container by id", func() {
Expand Down Expand Up @@ -88,8 +86,7 @@ var _ = Describe("Podman container cleanup", func() {
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"container", "cleanup", "running"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("container state improper"))
Expect(session).Should(ExitWithError(125, "is running or paused, refusing to clean up: container state improper"))
})

It("podman cleanup paused container", func() {
Expand All @@ -102,8 +99,7 @@ var _ = Describe("Podman container cleanup", func() {
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"container", "cleanup", "paused"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("container state improper"))
Expect(session).Should(ExitWithError(125, "is running or paused, refusing to clean up: container state improper"))

// unpause so that the cleanup can stop the container,
// otherwise it fails with container state improper
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/create_staticmac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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 run with --mac-address flag", func() {
Expand All @@ -14,7 +13,7 @@ var _ = Describe("Podman run with --mac-address flag", func() {
result := podmanTest.Podman([]string{"run", "--mac-address", "92:d0:c6:0a:29:34", ALPINE, "ip", "addr"})
result.WaitWithDefaultTimeout()
if isRootless() {
Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, "invalid config provided: networks and static ip/mac address can only be used with Bridge mode networking"))
} else {
Expect(result).Should(ExitCleanly())
Expect(result.OutputToString()).To(ContainSubstring("92:d0:c6:0a:29:34"))
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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 diff", func() {
Expand All @@ -23,7 +22,7 @@ var _ = Describe("Podman diff", func() {
It("podman diff bogus image", func() {
session := podmanTest.Podman([]string{"diff", "1234"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "1234 not found: layer not known"))
})

It("podman diff image with json output", func() {
Expand Down Expand Up @@ -119,7 +118,7 @@ RUN echo test
It("podman image diff bogus image", func() {
session := podmanTest.Podman([]string{"image", "diff", "1234", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "1234 not found: 1234: image not known"))
})

It("podman image diff of the same image", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var _ = Describe("Podman exec", func() {

session := podmanTest.Podman([]string{"exec", "test1", "sh", "-c", "exit 100"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(100))
Expect(session).Should(ExitWithError(100, ""))
})

It("podman exec in keep-id container drops privileges", func() {
Expand Down
7 changes: 3 additions & 4 deletions test/e2e/exists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 image|container exists", func() {
Expand All @@ -22,7 +21,7 @@ var _ = Describe("Podman image|container exists", func() {
It("podman image does not exist in local storage", func() {
session := podmanTest.Podman([]string{"image", "exists", "alpine9999"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, ""))
})
It("podman container exists in local storage by name", func() {
setup := podmanTest.RunTopContainer("foobar")
Expand Down Expand Up @@ -56,7 +55,7 @@ var _ = Describe("Podman image|container exists", func() {
It("podman container does not exist in local storage", func() {
session := podmanTest.Podman([]string{"container", "exists", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, ""))
})

It("podman pod exists in local storage by name", func() {
Expand Down Expand Up @@ -90,6 +89,6 @@ var _ = Describe("Podman image|container exists", func() {
// The exit code for non-existing pod is incorrect (125 vs 1)
session := podmanTest.Podman([]string{"pod", "exists", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, ""))
})
})
6 changes: 2 additions & 4 deletions test/e2e/generate_systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,11 @@ var _ = Describe("Podman generate systemd", func() {
// Fail for the pod
session = podmanTest.Podman([]string{"generate", "systemd", "foo"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("cannot generate systemd units for init containers"))
Expect(session).Should(ExitWithError(125, "cannot generate systemd units for init containers"))
// Fail for the init container
session = podmanTest.Podman([]string{"generate", "systemd", "foo-init"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("cannot generate systemd units for init containers"))
Expect(session).Should(ExitWithError(125, "cannot generate systemd units for init containers"))
})

It("podman generate systemd pod --name --files", func() {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ WORKDIR /test
podmanTest.BuildImage(dockerfile, "foobar.com/before:latest", "false")
result := podmanTest.Podman([]string{"images", "-q", "-f", "dangling=true"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0), "dangling image output: %q", result.OutputToString())
Expect(result.OutputToStringArray()).Should(BeEmpty(), "dangling image output: %q", result.OutputToString())
Expect(result).Should(ExitCleanly())
Expect(result.OutputToStringArray()).Should(BeEmpty(), "dangling image output")
})

It("podman images filter intermediate", func() {
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ var _ = Describe("Podman Info", func() {
// make sure we get an error for bogus values
session := podmanTest.Podman([]string{"--db-backend", "bogus", "info", "--format", "{{.Host.DatabaseBackend}}"})
session.WaitWithDefaultTimeout()
Expect(session).To(Exit(125))
Expect(session.ErrorToString()).To(Equal("Error: unsupported database backend: \"bogus\""))
Expect(session).To(ExitWithError(125, `Error: unsupported database backend: "bogus"`))
})

It("Podman info: check desired storage driver", func() {
Expand Down
11 changes: 7 additions & 4 deletions test/e2e/init_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
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 init", func() {

It("podman init bogus container", func() {
session := podmanTest.Podman([]string{"start", "123456"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, `Error: no container with name or ID "123456" found: no such container`))
})

It("podman init with no arguments", func() {
session := podmanTest.Podman([]string{"start"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "Error: start requires at least one argument"))
})

It("podman init single container by ID", func() {
Expand Down Expand Up @@ -110,8 +111,10 @@ var _ = Describe("Podman init", func() {
session := podmanTest.Podman([]string{"run", "--name", "init_test", "-d", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
cid := session.OutputToString()

init := podmanTest.Podman([]string{"init", "init_test"})
init.WaitWithDefaultTimeout()
Expect(init).Should(Exit(125))
Expect(init).Should(ExitWithError(125, fmt.Sprintf("Error: container %s has already been created in runtime: container state improper", cid)))
})
})

0 comments on commit f317eb2

Please sign in to comment.