Skip to content

Commit

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

This commit handles only one file, test/e2e/rmi_test.go , because
my changes are significant enough to merit individual review.

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed May 9, 2024
1 parent ed4a36c commit 8e1d2c4
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions test/e2e/rmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ 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 rmi", func() {

It("podman rmi bogus image", func() {
session := podmanTest.Podman([]string{"rmi", "debian:6.0.10"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, "debian:6.0.10: image not known"))

})

Expand Down Expand Up @@ -72,10 +71,10 @@ var _ = Describe("Podman rmi", func() {

It("podman rmi image with tags by ID cannot be done without force", func() {
podmanTest.AddImageToRWStore(CIRROS_IMAGE)
setup := podmanTest.Podman([]string{"images", "-q", CIRROS_IMAGE})
setup := podmanTest.Podman([]string{"images", "-q", "--no-trunc", CIRROS_IMAGE})
setup.WaitWithDefaultTimeout()
Expect(setup).Should(ExitCleanly())
cirrosID := setup.OutputToString()
cirrosID := setup.OutputToString()[7:]

session := podmanTest.Podman([]string{"tag", "cirros", "foo:bar", "foo"})
session.WaitWithDefaultTimeout()
Expand All @@ -84,7 +83,7 @@ var _ = Describe("Podman rmi", func() {
// Trying without --force should fail
result := podmanTest.Podman([]string{"rmi", cirrosID})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
Expect(result).To(ExitWithError(125, fmt.Sprintf(`unable to delete image "%s" by ID with more than one tag ([localhost/foo:latest localhost/foo:bar %s]): please force removal`, cirrosID, CIRROS_IMAGE)))

// With --force it should work
resultForce := podmanTest.Podman([]string{"rmi", "-f", cirrosID})
Expand All @@ -93,7 +92,6 @@ var _ = Describe("Podman rmi", func() {
})

It("podman rmi image that is a parent of another image", func() {
Skip("I need help with this one. i don't understand what is going on")
podmanTest.AddImageToRWStore(CIRROS_IMAGE)
session := podmanTest.Podman([]string{"run", "--name", "c_test", CIRROS_IMAGE, "true"})
session.WaitWithDefaultTimeout()
Expand All @@ -110,22 +108,18 @@ var _ = Describe("Podman rmi", func() {
session = podmanTest.Podman([]string{"rmi", CIRROS_IMAGE})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())

session = podmanTest.Podman([]string{"images", "-q"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToStringArray()).To(HaveLen(12))
Expect(session.OutputToString()).To(Equal("Untagged: "+CIRROS_IMAGE))

session = podmanTest.Podman([]string{"images", "--sort", "created", "--format", "{{.Id}}", "--all"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToStringArray()).To(HaveLen(13),
"Output from 'podman images -q -a'")
Expect(session.OutputToStringArray()).To(HaveLen(len(CACHE_IMAGES)+1),
"Output from 'podman images'")
untaggedImg := session.OutputToStringArray()[1]

session = podmanTest.Podman([]string{"rmi", "-f", untaggedImg})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(2), "UntaggedImg is '%s'", untaggedImg)
Expect(session).Should(ExitWithError(125, fmt.Sprintf(`cannot remove read-only image "%s"`, untaggedImg)))
})

It("podman rmi image that is created from another named imaged", func() {
Expand Down Expand Up @@ -253,8 +247,7 @@ RUN find $LOCAL
It("podman image rm is the same as rmi", func() {
session := podmanTest.Podman([]string{"image", "rm"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(ContainSubstring("image name or ID must be specified"))
Expect(session).Should(ExitWithError(125, "image name or ID must be specified"))
})

It("podman image rm - concurrent with shared layers", func() {
Expand Down

0 comments on commit 8e1d2c4

Please sign in to comment.