Skip to content

Commit

Permalink
ExitWithError() - rest of the p files
Browse files Browse the repository at this point in the history
Followup to containers#22270: wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

This commit handles all remaining test/e2e/p*_test.go

Signed-off-by: Ed Santiago <santiago@redhat.com>
  • Loading branch information
edsantiago committed May 8, 2024
1 parent 092d040 commit 5b5e8d7
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 89 deletions.
49 changes: 23 additions & 26 deletions test/e2e/pause_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"
)

var _ = Describe("Podman pause", func() {
Expand Down Expand Up @@ -37,13 +36,13 @@ var _ = Describe("Podman pause", func() {
It("podman pause bogus container", func() {
session := podmanTest.Podman([]string{"pause", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, `no container with name or ID "foobar" found: no such container`))
})

It("podman unpause bogus container", func() {
session := podmanTest.Podman([]string{"unpause", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, `no container with name or ID "foobar" found: no such container`))
})

It("podman pause a created container by id", func() {
Expand All @@ -55,7 +54,7 @@ var _ = Describe("Podman pause", func() {
result := podmanTest.Podman([]string{"pause", cid})
result.WaitWithDefaultTimeout()

Expect(result).To(ExitWithError())
Expect(result).To(ExitWithError(125, `"created" is not running, can't pause: container state improper`))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(createdState))

Expand Down Expand Up @@ -107,7 +106,7 @@ var _ = Describe("Podman pause", func() {
result := podmanTest.Podman([]string{"unpause", cid})
result.WaitWithDefaultTimeout()

Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, fmt.Sprintf(`"%s" is not paused, can't unpause: container state improper`, cid)))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))

})
Expand All @@ -128,7 +127,7 @@ var _ = Describe("Podman pause", func() {
result = podmanTest.Podman([]string{"rm", cid})
result.WaitWithDefaultTimeout()

Expect(result).Should(Exit(2))
Expect(result).Should(ExitWithError(2, fmt.Sprintf("cannot remove container %s as it is paused - running or paused containers cannot be removed without force: container state improper", cid)))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(pausedState))

Expand Down Expand Up @@ -175,7 +174,7 @@ var _ = Describe("Podman pause", func() {
result = podmanTest.Podman([]string{"stop", cid})
result.WaitWithDefaultTimeout()

Expect(result).Should(Exit(125))
Expect(result).Should(ExitWithError(125, fmt.Sprintf("Error: container %s is running or paused, refusing to clean up: container state improper", cid)))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(strings.ToLower(podmanTest.GetContainerStatus())).To(ContainSubstring(pausedState))

Expand All @@ -186,7 +185,7 @@ var _ = Describe("Podman pause", func() {

result = podmanTest.Podman([]string{"rm", cid})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(2))
Expect(result).Should(ExitWithError(2, fmt.Sprintf("cannot remove container %s as it is running - running or paused containers cannot be removed without force: container state improper", cid)))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))

result = podmanTest.Podman([]string{"rm", "-t", "0", "-f", cid})
Expand Down Expand Up @@ -382,40 +381,38 @@ var _ = Describe("Podman pause", func() {
SkipIfRemote("--latest flag n/a")
result := podmanTest.Podman([]string{"pause", "--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{"pause", "--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{"pause", "--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{"pause", "--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 unpause invalid --latest and --cidfile and --all", func() {
SkipIfRemote("--latest flag n/a")
result := podmanTest.Podman([]string{"unpause", "--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{"unpause", "--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{"unpause", "--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{"unpause", "--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 pause --filter", func() {
Expand All @@ -437,11 +434,11 @@ var _ = Describe("Podman pause", func() {

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

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

session1 = podmanTest.Podman([]string{"pause", "-a", "--filter", "label=test=with,comma"})
session1.WaitWithDefaultTimeout()
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/pod_stats_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 pod stats", func() {
Expand All @@ -25,7 +24,7 @@ var _ = Describe("Podman pod stats", func() {
It("podman pod stats with a bogus pod", func() {
session := podmanTest.Podman([]string{"pod", "stats", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "unable to get list of pods: no pod with name or ID foobar found: no such pod"))
})

It("podman pod stats on a specific running pod", func() {
Expand Down Expand Up @@ -151,7 +150,7 @@ var _ = Describe("Podman pod stats", func() {
Expect(session).Should(ExitCleanly())
stats := podmanTest.Podman([]string{"pod", "stats", "-a", "--no-reset", "--no-stream", "--format", "\"table {{.ID}} \""})
stats.WaitWithDefaultTimeout()
Expect(stats).To(ExitWithError())
Expect(stats).To(ExitWithError(125, `template: stats:1:20: executing "stats" at <.ID>: can't evaluate field ID in type *types.PodStatsReport`))
})

It("podman pod stats on net=host post", func() {
Expand Down
8 changes: 6 additions & 2 deletions test/e2e/port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ var _ = Describe("Podman port", func() {
It("podman port all and latest", func() {
result := podmanTest.Podman([]string{"port", "-a", "-l"})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
if IsRemote() {
Expect(result).To(ExitWithError(125, "unknown shorthand flag: 'l' in -l"))
} else {
Expect(result).To(ExitWithError(125, "--all and --latest cannot be used together"))
}
})

It("podman port all and extra", func() {
result := podmanTest.Podman([]string{"port", "-a", "foobar"})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
Expect(result).To(ExitWithError(125, "no arguments are needed with --all"))
})

It("podman port -l nginx", func() {
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/prune_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 pruneImage = fmt.Sprintf(`
Expand Down Expand Up @@ -492,8 +491,7 @@ var _ = Describe("Podman prune", func() {
It("podman system prune --all --external fails", func() {
prune := podmanTest.Podman([]string{"system", "prune", "--all", "--external"})
prune.WaitWithDefaultTimeout()
Expect(prune).Should(Exit(125))
Expect(prune.ErrorToString()).To(ContainSubstring("--external cannot be combined with other options"))
Expect(prune).Should(ExitWithError(125, "--external cannot be combined with other options"))
})

It("podman system prune --external leaves referenced containers", func() {
Expand Down
9 changes: 4 additions & 5 deletions test/e2e/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ var _ = Describe("Podman ps", func() {
It("podman ps mutually exclusive flags", func() {
session := podmanTest.Podman([]string{"ps", "-aqs"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "quiet conflicts with size and namespace"))

session = podmanTest.Podman([]string{"ps", "-a", "--ns", "-s"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "size and namespace options conflict"))
})

It("podman --format by size", func() {
Expand Down Expand Up @@ -540,8 +540,7 @@ var _ = Describe("Podman ps", func() {
"run", "-p", "1000-2000:2000-3000", "-p", "1999-2999:3001-4001", ALPINE,
})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("conflicting port mappings for host port 1999"))
Expect(session).Should(ExitWithError(125, "conflicting port mappings for host port 1999 (protocol tcp)"))
})

It("podman ps test with multiple port range", func() {
Expand Down Expand Up @@ -666,7 +665,7 @@ var _ = Describe("Podman ps", func() {
session = podmanTest.Podman([]string{"run", "--name", "test2", "--label", "foo=1",
ALPINE, "ls", "/fail"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, "ls: /fail: No such file or directory"))

session = podmanTest.Podman([]string{"create", "--name", "test3", ALPINE, cid1})
session.WaitWithDefaultTimeout()
Expand Down
Loading

0 comments on commit 5b5e8d7

Please sign in to comment.