ExitWithError() - v files

Followup to #22270: wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

This commit handles test/e2e/v*_test.go

Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
Ed Santiago
2024-05-06 05:58:13 -06:00
parent 07d8b327a0
commit 83ee16b9ba
3 changed files with 23 additions and 17 deletions

View File

@ -47,7 +47,7 @@ var _ = Describe("Podman volume create", func() {
session = podmanTest.Podman([]string{"volume", "create", "myvol"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "volume with name myvol already exists: volume already exists"))
})
It("podman create volume --ignore", func() {
@ -133,24 +133,21 @@ var _ = Describe("Podman volume create", func() {
session := podmanTest.Podman([]string{"volume", "import", "notfound", "notfound.tar"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("open notfound.tar: no such file or directory"))
Expect(session).To(ExitWithError(125, "open notfound.tar: no such file or directory"))
session = podmanTest.Podman([]string{"volume", "import", "notfound", "-"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("no such volume notfound"))
Expect(session).To(ExitWithError(125, "no such volume notfound"))
session = podmanTest.Podman([]string{"volume", "export", "notfound"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("no such volume notfound"))
Expect(session).To(ExitWithError(125, "no such volume notfound"))
})
It("podman create volume with bad volume option", func() {
session := podmanTest.Podman([]string{"volume", "create", "--opt", "badOpt=bad"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "invalid mount option badOpt for driver 'local': invalid argument"))
})
It("podman create volume with o=uid,gid", func() {

View File

@ -27,13 +27,13 @@ var _ = Describe("Podman volume plugins", func() {
It("volume create with nonexistent plugin errors", func() {
session := podmanTest.Podman([]string{"volume", "create", "--driver", "notexist", "test_volume_name"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "volume test_volume_name uses volume plugin notexist but it could not be retrieved: no volume plugin with name notexist available: required plugin missing"))
})
It("volume create with not-running plugin does not error", func() {
session := podmanTest.Podman([]string{"volume", "create", "--driver", "testvol0", "test_volume_name"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, `Error: volume test_volume_name uses volume plugin testvol0 but it could not be retrieved: cannot access plugin testvol0 socket "/run/docker/plugins/testvol0.sock": stat /run/docker/plugins/testvol0.sock: no such file or directory`))
})
It("volume create and remove with running plugin succeeds", func() {
@ -145,7 +145,7 @@ var _ = Describe("Podman volume plugins", func() {
// Remove should exit non-zero because missing plugin
remove := podmanTest.Podman([]string{"volume", "rm", volName})
remove.WaitWithDefaultTimeout()
Expect(remove).To(ExitWithError())
Expect(remove).To(ExitWithError(125, "cannot remove volume testVolume1 from plugin testvol3, but it has been removed from Podman: required plugin missing"))
// But the volume should still be gone
ls2 := podmanTest.Podman([]string{"volume", "ls", "-q"})

View File

@ -1,10 +1,11 @@
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 volume rm", func() {
@ -30,14 +31,13 @@ var _ = Describe("Podman volume rm", func() {
It("podman volume rm with --force flag", func() {
session := podmanTest.Podman([]string{"create", "-v", "myvol:/myvol", ALPINE, "ls"})
cid := session.OutputToString()
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
cid := session.OutputToString()
session = podmanTest.Podman([]string{"volume", "rm", "myvol"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(2))
Expect(session.ErrorToString()).To(ContainSubstring(cid))
Expect(session).Should(ExitWithError(2, fmt.Sprintf("volume myvol is being used by the following container(s): %s: volume is being used", cid)))
session = podmanTest.Podman([]string{"volume", "rm", "-t", "0", "-f", "myvol"})
session.WaitWithDefaultTimeout()
@ -52,7 +52,7 @@ var _ = Describe("Podman volume rm", func() {
It("podman volume remove bogus", func() {
session := podmanTest.Podman([]string{"volume", "rm", "bogus"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1, `no volume with name "bogus" found: no such volume`))
})
It("podman rm with --all flag", func() {
@ -100,7 +100,16 @@ var _ = Describe("Podman volume rm", func() {
session = podmanTest.Podman([]string{"volume", "rm", "myv"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
expect := "more than one result for volume name myv: volume already exists"
if podmanTest.DatabaseBackend == "boltdb" {
// boltdb issues volume name in quotes
expect = `more than one result for volume name "myv": volume already exists`
}
if IsRemote() {
// FIXME: #22616
expect = `unmarshalling error into &errorhandling.ErrorModel`
}
Expect(session).To(ExitWithError(125, expect))
session = podmanTest.Podman([]string{"volume", "ls"})
session.WaitWithDefaultTimeout()