diff --git a/test/e2e/import_test.go b/test/e2e/import_test.go index e22b819912..fb85182e8f 100644 --- a/test/e2e/import_test.go +++ b/test/e2e/import_test.go @@ -171,16 +171,10 @@ var _ = Describe("Podman import", func() { importImage := podmanTest.Podman([]string{"import", "-q", "--signature-policy", "/no/such/file", outfile}) importImage.WaitWithDefaultTimeout() - Expect(importImage).To(ExitWithError()) + Expect(importImage).To(ExitWithError(125, "open /no/such/file: no such file or directory")) result := podmanTest.Podman([]string{"import", "-q", "--signature-policy", "/etc/containers/policy.json", outfile}) result.WaitWithDefaultTimeout() - if IsRemote() { - Expect(result).To(ExitWithError()) - Expect(result.ErrorToString()).To(ContainSubstring("unknown flag")) - result := podmanTest.Podman([]string{"import", "-q", outfile}) - result.WaitWithDefaultTimeout() - } Expect(result).Should(ExitCleanly()) }) }) diff --git a/test/e2e/inspect_test.go b/test/e2e/inspect_test.go index 131fc29288..202ca036ae 100644 --- a/test/e2e/inspect_test.go +++ b/test/e2e/inspect_test.go @@ -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" "github.com/opencontainers/selinux/go-selinux" ) @@ -22,7 +23,7 @@ var _ = Describe("Podman inspect", func() { It("podman inspect bogus container", func() { session := podmanTest.Podman([]string{"inspect", "foobar4321"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, `no such object: "foobar4321"`)) }) It("podman inspect filter should work if result contains tab", func() { @@ -128,7 +129,7 @@ var _ = Describe("Podman inspect", func() { SkipIfRemote("--latest flag n/a") result := podmanTest.Podman([]string{"inspect", "-l", "1234foobar"}) result.WaitWithDefaultTimeout() - Expect(result).Should(Exit(125)) + Expect(result).Should(ExitWithError(125, "--latest and arguments cannot be used together")) }) It("podman inspect with mount filters", func() { @@ -173,7 +174,7 @@ var _ = Describe("Podman inspect", func() { session := podmanTest.Podman([]string{"inspect", "--latest"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, "no containers to inspect: no such container")) }) It("podman [image,container] inspect on image", func() { @@ -185,7 +186,11 @@ var _ = Describe("Podman inspect", func() { ctrInspect := podmanTest.Podman([]string{"container", "inspect", ALPINE}) ctrInspect.WaitWithDefaultTimeout() - Expect(ctrInspect).To(ExitWithError()) + if IsRemote() { + Expect(ctrInspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", ALPINE))) + } else { + Expect(ctrInspect).To(ExitWithError(125, fmt.Sprintf("no such container %s", ALPINE))) + } imageInspect := podmanTest.Podman([]string{"image", "inspect", ALPINE}) imageInspect.WaitWithDefaultTimeout() @@ -197,7 +202,7 @@ var _ = Describe("Podman inspect", func() { }) It("podman [image, container] inspect on container", func() { - ctrName := "testCtr" + ctrName := "testctr" create := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "sh"}) create.WaitWithDefaultTimeout() Expect(create).Should(ExitCleanly()) @@ -216,7 +221,7 @@ var _ = Describe("Podman inspect", func() { imageInspect := podmanTest.Podman([]string{"image", "inspect", ctrName}) imageInspect.WaitWithDefaultTimeout() - Expect(imageInspect).To(ExitWithError()) + Expect(imageInspect).To(ExitWithError(125, fmt.Sprintf("%s: image not known", ctrName))) Expect(baseJSON[0]).To(HaveField("ID", ctrJSON[0].ID)) }) @@ -224,7 +229,7 @@ var _ = Describe("Podman inspect", func() { It("podman inspect always produces a valid array", func() { baseInspect := podmanTest.Podman([]string{"inspect", "doesNotExist"}) baseInspect.WaitWithDefaultTimeout() - Expect(baseInspect).To(ExitWithError()) + Expect(baseInspect).To(ExitWithError(125, `no such object: "doesNotExist"`)) emptyJSON := baseInspect.InspectContainerToJSON() Expect(emptyJSON).To(BeEmpty()) }) @@ -237,7 +242,7 @@ var _ = Describe("Podman inspect", func() { baseInspect := podmanTest.Podman([]string{"inspect", ctrName, "doesNotExist"}) baseInspect.WaitWithDefaultTimeout() - Expect(baseInspect).To(ExitWithError()) + Expect(baseInspect).To(ExitWithError(125, `no such object: "doesNotExist"`)) baseJSON := baseInspect.InspectContainerToJSON() Expect(baseJSON).To(HaveLen(1)) Expect(baseJSON[0]).To(HaveField("Name", ctrName)) @@ -383,6 +388,7 @@ var _ = Describe("Podman inspect", func() { Expect(session).Should(ExitCleanly()) Expect(session.OutputToString()).To(Equal(volName)) }) + It("podman inspect --type container on a pod should fail", func() { podName := "testpod" create := podmanTest.Podman([]string{"pod", "create", "--name", podName}) @@ -391,7 +397,11 @@ var _ = Describe("Podman inspect", func() { inspect := podmanTest.Podman([]string{"inspect", "--type", "container", podName}) inspect.WaitWithDefaultTimeout() - Expect(inspect).To(ExitWithError()) + if IsRemote() { + Expect(inspect).To(ExitWithError(125, fmt.Sprintf("no such container %q", podName))) + } else { + Expect(inspect).To(ExitWithError(125, fmt.Sprintf("no such container %s", podName))) + } }) It("podman inspect --type network on a container should fail", func() { @@ -402,7 +412,7 @@ var _ = Describe("Podman inspect", func() { inspect := podmanTest.Podman([]string{"inspect", "--type", "network", ctrName}) inspect.WaitWithDefaultTimeout() - Expect(inspect).To(ExitWithError()) + Expect(inspect).To(ExitWithError(125, " network not found")) }) It("podman inspect --type pod on a container should fail", func() { @@ -413,7 +423,7 @@ var _ = Describe("Podman inspect", func() { inspect := podmanTest.Podman([]string{"inspect", "--type", "pod", ctrName}) inspect.WaitWithDefaultTimeout() - Expect(inspect).To(ExitWithError()) + Expect(inspect).To(ExitWithError(125, "no such pod ")) }) It("podman inspect --type volume on a container should fail", func() { @@ -424,7 +434,7 @@ var _ = Describe("Podman inspect", func() { inspect := podmanTest.Podman([]string{"inspect", "--type", "volume", ctrName}) inspect.WaitWithDefaultTimeout() - Expect(inspect).To(ExitWithError()) + Expect(inspect).To(ExitWithError(125, "no such volume ")) }) // Fixes https://github.com/containers/podman/issues/8444 @@ -573,13 +583,15 @@ var _ = Describe("Podman inspect", func() { Expect(session).Should(ExitCleanly()) Expect(session.OutputToString()).To(BeEmpty()) + commandNotFound := "OCI runtime attempted to invoke a command that was not found" session = podmanTest.Podman([]string{"start", cid}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) + Expect(session).Should(ExitWithError(125, commandNotFound)) + session = podmanTest.Podman([]string{"container", "inspect", cid, "-f", "'{{ .State.Error }}"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) - Expect(session.OutputToString()).ToNot(BeEmpty()) + Expect(session.OutputToString()).To(ContainSubstring(commandNotFound)) }) }) diff --git a/test/e2e/manifest_test.go b/test/e2e/manifest_test.go index 02f57d0f93..0c73d27b75 100644 --- a/test/e2e/manifest_test.go +++ b/test/e2e/manifest_test.go @@ -2,6 +2,7 @@ package integration import ( "encoding/json" + "fmt" "os" "path/filepath" "strings" @@ -83,13 +84,12 @@ var _ = Describe("Podman manifest", func() { session = podmanTest.Podman([]string{"manifest", "create", "foo"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + Expect(session).To(ExitWithError(125, `image name "localhost/foo:latest" is already associated with image `)) session = podmanTest.Podman([]string{"manifest", "push", "--all", "foo"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) - // Push should actually fail since its not valid registry - Expect(session.ErrorToString()).To(ContainSubstring("requested access to the resource is denied")) + // Push should actually fail since it's not valid registry + Expect(session).To(ExitWithError(125, "requested access to the resource is denied")) Expect(session.OutputToString()).To(Not(ContainSubstring("accepts 2 arg(s), received 1"))) session = podmanTest.Podman([]string{"manifest", "create", amend, "foo"}) @@ -341,8 +341,8 @@ add_compression = ["zstd"]`), 0o644) Expect(session).Should(ExitCleanly()) session = podmanTest.Podman([]string{"manifest", "add", "--annotation", "hoge", "foo", imageList}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) - Expect(session.ErrorToString()).To(ContainSubstring("no value given for annotation")) + Expect(session).Should(ExitWithError(125, "no value given for annotation")) + session = podmanTest.Podman([]string{"manifest", "add", "--annotation", "hoge=fuga", "--annotation", "key=val,withcomma", "foo", imageList}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) @@ -421,9 +421,18 @@ add_compression = ["zstd"]`), 0o644) session = podmanTest.Podman([]string{"manifest", "add", "foo", imageList}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) - session = podmanTest.Podman([]string{"manifest", "remove", "foo", "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}) + bogusID := "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" + session = podmanTest.Podman([]string{"manifest", "remove", "foo", bogusID}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) + + // FIXME-someday: figure out why message differs in podman-remote + expectMessage := "removing from manifest list foo: " + if IsRemote() { + expectMessage += "removing from manifest foo" + } else { + expectMessage += fmt.Sprintf(`no instance matching digest %q found in manifest list: file does not exist`, bogusID) + } + Expect(session).To(ExitWithError(125, expectMessage)) session = podmanTest.Podman([]string{"manifest", "rm", "foo"}) session.WaitWithDefaultTimeout() @@ -493,9 +502,7 @@ RUN touch /file tmpDir := filepath.Join(podmanTest.TempDir, "wrong-compression") session = podmanTest.Podman([]string{"manifest", "push", "--compression-format", "gzip", "--compression-level", "50", "foo", "oci:" + tmpDir}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) - output := session.ErrorToString() - Expect(output).To(ContainSubstring("invalid compression level")) + Expect(session).Should(ExitWithError(125, "invalid compression level")) dest := filepath.Join(podmanTest.TempDir, "pushed") err := os.MkdirAll(dest, os.ModePerm) @@ -564,7 +571,7 @@ RUN touch /file push := podmanTest.Podman([]string{"manifest", "push", "--all", "--tls-verify=false", "--remove-signatures", "foo", "localhost:7000/bogus"}) push.WaitWithDefaultTimeout() - Expect(push).Should(Exit(125)) + Expect(push).Should(ExitWithError(125, "Failed, retrying in 1s ... (1/3)")) Expect(push.ErrorToString()).To(MatchRegexp("Copying blob.*Failed, retrying in 1s \\.\\.\\. \\(1/3\\).*Copying blob.*Failed, retrying in 2s")) }) @@ -614,8 +621,7 @@ RUN touch /file push = podmanTest.Podman([]string{"manifest", "push", "--compression-format=gzip", "--compression-level=2", "--tls-verify=false", "--creds=podmantest:wrongpasswd", "foo", "localhost:" + registry.Port + "/credstest"}) push.WaitWithDefaultTimeout() - Expect(push).To(ExitWithError()) - Expect(push.ErrorToString()).To(ContainSubstring(": authentication required")) + Expect(push).To(ExitWithError(125, ": authentication required")) // push --rm after pull image (#15033) push = podmanTest.Podman([]string{"manifest", "push", "-q", "--rm", "--tls-verify=false", "--creds=" + registry.User + ":" + registry.Password, "foo", "localhost:" + registry.Port + "/rmtest"}) @@ -631,8 +637,7 @@ RUN touch /file It("push with error", func() { session := podmanTest.Podman([]string{"manifest", "push", "badsrcvalue", "baddestvalue"}) session.WaitWithDefaultTimeout() - Expect(session).Should(ExitWithError()) - Expect(session.ErrorToString()).To(ContainSubstring("retrieving local image from image name badsrcvalue: badsrcvalue: image not known")) + Expect(session).Should(ExitWithError(125, "retrieving local image from image name badsrcvalue: badsrcvalue: image not known")) }) It("push --rm to local directory", func() { @@ -654,8 +659,8 @@ RUN touch /file Expect(session).Should(ExitCleanly()) session = podmanTest.Podman([]string{"manifest", "push", "-p", "foo", "dir:" + dest}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) - Expect(session.ErrorToString()).To(ContainSubstring("retrieving local image from image name foo: foo: image not known")) + Expect(session).Should(ExitWithError(125, "retrieving local image from image name foo: foo: image not known")) + session = podmanTest.Podman([]string{"images", "-q", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) @@ -682,9 +687,9 @@ RUN touch /file session = podmanTest.Podman([]string{"manifest", "rm", "foo", "bar"}) session.WaitWithDefaultTimeout() - Expect(session).Should(ExitWithError()) - Expect(session.ErrorToString()).To(ContainSubstring("foo: image not known")) - Expect(session.ErrorToString()).To(ContainSubstring("bar: image not known")) + Expect(session).Should(ExitWithError(1, " 2 errors occurred:")) + Expect(session.ErrorToString()).To(ContainSubstring("* foo: image not known")) + Expect(session.ErrorToString()).To(ContainSubstring("* bar: image not known")) }) It("exists", func() { @@ -732,8 +737,7 @@ RUN touch /file // manifest rm should fail with `image is not a manifest list` session := podmanTest.Podman([]string{"manifest", "rm", ALPINE}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(125)) - Expect(session.ErrorToString()).To(ContainSubstring("image is not a manifest list")) + Expect(session).Should(ExitWithError(125, "image is not a manifest list")) manifestName := "testmanifest:sometag" session = podmanTest.Podman([]string{"manifest", "create", manifestName}) diff --git a/test/e2e/network_connect_disconnect_test.go b/test/e2e/network_connect_disconnect_test.go index cb3a1aae1d..3764b44bc7 100644 --- a/test/e2e/network_connect_disconnect_test.go +++ b/test/e2e/network_connect_disconnect_test.go @@ -1,11 +1,12 @@ package integration import ( + "fmt" + . "github.com/containers/podman/v5/test/utils" "github.com/containers/storage/pkg/stringid" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/onsi/gomega/gexec" "github.com/onsi/gomega/types" ) @@ -14,7 +15,7 @@ var _ = Describe("Podman network connect and disconnect", func() { It("bad network name in disconnect should result in error", func() { dis := podmanTest.Podman([]string{"network", "disconnect", "foobar", "test"}) dis.WaitWithDefaultTimeout() - Expect(dis).Should(ExitWithError()) + Expect(dis).Should(ExitWithError(125, `no container with name or ID "test" found: no such container`)) }) It("bad container name in network disconnect should result in error", func() { @@ -26,7 +27,7 @@ var _ = Describe("Podman network connect and disconnect", func() { dis := podmanTest.Podman([]string{"network", "disconnect", netName, "foobar"}) dis.WaitWithDefaultTimeout() - Expect(dis).Should(ExitWithError()) + Expect(dis).Should(ExitWithError(125, `no container with name or ID "foobar" found: no such container`)) }) It("network disconnect with net mode slirp4netns should result in error", func() { @@ -43,8 +44,7 @@ var _ = Describe("Podman network connect and disconnect", func() { con := podmanTest.Podman([]string{"network", "disconnect", netName, "test"}) con.WaitWithDefaultTimeout() - Expect(con).Should(ExitWithError()) - Expect(con.ErrorToString()).To(ContainSubstring(`"slirp4netns" is not supported: invalid network mode`)) + Expect(con).Should(ExitWithError(125, `"slirp4netns" is not supported: invalid network mode`)) }) It("podman network disconnect", func() { @@ -85,7 +85,7 @@ var _ = Describe("Podman network connect and disconnect", func() { exec = podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", "eth0"}) exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitWithError()) + Expect(exec).Should(ExitWithError(1, "ip: can't find device 'eth0'")) exec3 := podmanTest.Podman([]string{"exec", "test", "cat", "/etc/resolv.conf"}) exec3.WaitWithDefaultTimeout() @@ -99,9 +99,13 @@ var _ = Describe("Podman network connect and disconnect", func() { }) It("bad network name in connect should result in error", func() { - dis := podmanTest.Podman([]string{"network", "connect", "foobar", "test"}) + session := podmanTest.Podman([]string{"create", "--name", "testContainer", "--network", "bridge", ALPINE}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + + dis := podmanTest.Podman([]string{"network", "connect", "nonexistent-network", "testContainer"}) dis.WaitWithDefaultTimeout() - Expect(dis).Should(ExitWithError()) + Expect(dis).Should(ExitWithError(125, "unable to find network with name or ID nonexistent-network: network not found")) }) It("bad container name in network connect should result in error", func() { @@ -113,7 +117,7 @@ var _ = Describe("Podman network connect and disconnect", func() { dis := podmanTest.Podman([]string{"network", "connect", netName, "foobar"}) dis.WaitWithDefaultTimeout() - Expect(dis).Should(ExitWithError()) + Expect(dis).Should(ExitWithError(125, `no container with name or ID "foobar" found: no such container`)) }) It("network connect with net mode slirp4netns should result in error", func() { @@ -130,8 +134,7 @@ var _ = Describe("Podman network connect and disconnect", func() { con := podmanTest.Podman([]string{"network", "connect", netName, "test"}) con.WaitWithDefaultTimeout() - Expect(con).Should(ExitWithError()) - Expect(con.ErrorToString()).To(ContainSubstring(`"slirp4netns" is not supported: invalid network mode`)) + Expect(con).Should(ExitWithError(125, `"slirp4netns" is not supported: invalid network mode`)) }) It("podman connect on a container that already is connected to the network should error after init", func() { @@ -162,7 +165,11 @@ var _ = Describe("Podman network connect and disconnect", func() { con2 := podmanTest.Podman([]string{"network", "connect", netName, "test"}) con2.WaitWithDefaultTimeout() - Expect(con2).Should(ExitWithError()) + if podmanTest.DatabaseBackend == "boltdb" { + Expect(con2).Should(ExitWithError(125, fmt.Sprintf("container %s is already connected to network %q: network is already connected", cid, netName))) + } else { + Expect(con2).Should(ExitWithError(125, fmt.Sprintf("container %s is already connected to network %s: network is already connected", cid, netName))) + } }) It("podman network connect", func() { @@ -359,11 +366,12 @@ var _ = Describe("Podman network connect and disconnect", func() { exec := podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", "eth0"}) exec.WaitWithDefaultTimeout() - // because the network interface order is not guaranteed to be the same we have to check both eth0 and eth1 - // if eth0 did not exists eth1 has to exists - var exitMatcher types.GomegaMatcher = ExitWithError() + // because the network interface order is not guaranteed to be the same, we have to check both eth0 and eth1. + // if eth0 did not exist, eth1 has to exist. + var exitMatcher types.GomegaMatcher = ExitWithError(1, "ip: can't find device 'eth1'") if exec.ExitCode() > 0 { - exitMatcher = Exit(0) + Expect(exec).To(ExitWithError(1, "ip: can't find device 'eth0'")) + exitMatcher = ExitCleanly() } exec = podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", "eth1"}) @@ -402,6 +410,6 @@ var _ = Describe("Podman network connect and disconnect", func() { exec = podmanTest.Podman([]string{"exec", "test", "ip", "addr", "show", "eth0"}) exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitWithError()) + Expect(exec).Should(ExitWithError(1, "ip: can't find device 'eth0'")) }) }) diff --git a/test/e2e/network_create_test.go b/test/e2e/network_create_test.go index 28edc41be3..0ce6be1a52 100644 --- a/test/e2e/network_create_test.go +++ b/test/e2e/network_create_test.go @@ -2,6 +2,7 @@ package integration import ( "encoding/json" + "fmt" "net" "github.com/containers/common/libnetwork/types" @@ -395,7 +396,7 @@ var _ = Describe("Podman network create", func() { It("podman network create with invalid subnet", func() { nc := podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.12.0/17000", stringid.GenerateRandomID()}) nc.WaitWithDefaultTimeout() - Expect(nc).To(ExitWithError()) + Expect(nc).To(ExitWithError(125, "invalid CIDR address: 10.11.12.0/17000")) }) It("podman network create with ipv4 subnet and ipv6 flag", func() { @@ -426,16 +427,25 @@ var _ = Describe("Podman network create", func() { Expect(nc.OutputToString()).To(ContainSubstring(`.0/24`)) }) - It("podman network create with invalid IP", func() { - nc := podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.0/17000", stringid.GenerateRandomID()}) + It("podman network create with invalid IP arguments", func() { + nc := podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.12.0/24", "--ip-range", "10.11.12.345-10.11.12.999"}) nc.WaitWithDefaultTimeout() - Expect(nc).To(ExitWithError()) + Expect(nc).To(ExitWithError(125, `range start ip "10.11.12.345" is not a ip address`)) + + nc = podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.12.0/24", "--ip-range", "10.11.12.3-10.11.12.999"}) + nc.WaitWithDefaultTimeout() + Expect(nc).To(ExitWithError(125, `range end ip "10.11.12.999" is not a ip address`)) + + nc = podmanTest.Podman([]string{"network", "create", "--gateway", "10.11.12.256"}) + nc.WaitWithDefaultTimeout() + Expect(nc).To(ExitWithError(125, `invalid argument "10.11.12.256" for "--gateway" flag: invalid string being converted to IP address: 10.11.12.256`)) + }) It("podman network create with invalid gateway for subnet", func() { nc := podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.12.0/24", "--gateway", "192.168.1.1", stringid.GenerateRandomID()}) nc.WaitWithDefaultTimeout() - Expect(nc).To(ExitWithError()) + Expect(nc).To(ExitWithError(125, "gateway 192.168.1.1 not in subnet 10.11.12.0/24")) }) It("podman network create two networks with same name should fail", func() { @@ -447,7 +457,7 @@ var _ = Describe("Podman network create", func() { ncFail := podmanTest.Podman([]string{"network", "create", netName}) ncFail.WaitWithDefaultTimeout() - Expect(ncFail).To(ExitWithError()) + Expect(ncFail).To(ExitWithError(125, fmt.Sprintf("network name %s already used: network already exists", netName))) }) It("podman network create two networks with same subnet should fail", func() { @@ -461,7 +471,7 @@ var _ = Describe("Podman network create", func() { ncFail := podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.13.0/24", netName2}) ncFail.WaitWithDefaultTimeout() defer podmanTest.removeNetwork(netName2) - Expect(ncFail).To(ExitWithError()) + Expect(ncFail).To(ExitWithError(125, "subnet 10.11.13.0/24 is already used on the host or by another config")) }) It("podman network create two IPv6 networks with same subnet should fail", func() { @@ -475,13 +485,13 @@ var _ = Describe("Podman network create", func() { ncFail := podmanTest.Podman([]string{"network", "create", "--subnet", "fd00:4:4:4:4::/64", "--ipv6", netName2}) ncFail.WaitWithDefaultTimeout() defer podmanTest.removeNetwork(netName2) - Expect(ncFail).To(ExitWithError()) + Expect(ncFail).To(ExitWithError(125, "subnet fd00:4:4:4::/64 is already used on the host or by another config")) }) It("podman network create with invalid network name", func() { - nc := podmanTest.Podman([]string{"network", "create", "foo "}) + nc := podmanTest.Podman([]string{"network", "create", "2bad!"}) nc.WaitWithDefaultTimeout() - Expect(nc).To(ExitWithError()) + Expect(nc).To(ExitWithError(125, "network name 2bad! invalid: names must match [a-zA-Z0-9][a-zA-Z0-9_.-]*: invalid argument")) }) It("podman network create with mtu option", func() { @@ -515,7 +525,7 @@ var _ = Describe("Podman network create", func() { nc := podmanTest.Podman([]string{"network", "create", "--opt", "foo=bar", net}) nc.WaitWithDefaultTimeout() defer podmanTest.removeNetwork(net) - Expect(nc).To(ExitWithError()) + Expect(nc).To(ExitWithError(125, "unsupported bridge network option foo")) }) It("podman CNI network create with internal should not have dnsname", func() { @@ -559,8 +569,7 @@ var _ = Describe("Podman network create", func() { for _, name := range []string{"none", "host", "bridge", "private", "slirp4netns", "pasta", "container", "ns", "default"} { nc := podmanTest.Podman([]string{"network", "create", name}) nc.WaitWithDefaultTimeout() - Expect(nc).To(Exit(125)) - Expect(nc.ErrorToString()).To(ContainSubstring("cannot create network with name %q because it conflicts with a valid network mode", name)) + Expect(nc).To(ExitWithError(125, fmt.Sprintf("cannot create network with name %q because it conflicts with a valid network mode", name))) } }) @@ -632,15 +641,13 @@ var _ = Describe("Podman network create", func() { gw2 := "fd52:2a5a:747e:3acf::10" nc := podmanTest.Podman([]string{"network", "create", "--subnet", subnet1, "--gateway", gw1, "--gateway", gw2, name}) nc.WaitWithDefaultTimeout() - Expect(nc).To(Exit(125)) - Expect(nc.ErrorToString()).To(Equal("Error: cannot set more gateways than subnets")) + Expect(nc).To(ExitWithError(125, "cannot set more gateways than subnets")) range1 := "10.10.3.0/26" range2 := "10.10.3.0/28" nc = podmanTest.Podman([]string{"network", "create", "--subnet", subnet1, "--ip-range", range1, "--ip-range", range2, name}) nc.WaitWithDefaultTimeout() - Expect(nc).To(Exit(125)) - Expect(nc.ErrorToString()).To(Equal("Error: cannot set more ranges than subnets")) + Expect(nc).To(ExitWithError(125, "cannot set more ranges than subnets")) }) It("podman network create same name - fail", func() { @@ -654,7 +661,7 @@ var _ = Describe("Podman network create", func() { nc = podmanTest.Podman(networkCreateCommand) nc.WaitWithDefaultTimeout() - Expect(nc).To(Exit(125)) + Expect(nc).To(ExitWithError(125, fmt.Sprintf("network name %s already used: network already exists", name))) }) It("podman network create same name - succeed with ignore", func() { diff --git a/test/e2e/network_test.go b/test/e2e/network_test.go index 338d9b4d5b..13b0712d75 100644 --- a/test/e2e/network_test.go +++ b/test/e2e/network_test.go @@ -118,8 +118,7 @@ var _ = Describe("Podman network", func() { session = podmanTest.Podman([]string{"network", "ls", "--filter", "namr=ab"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) - Expect(session.ErrorToString()).To(ContainSubstring(`invalid filter "namr"`)) + Expect(session).To(ExitWithError(125, `invalid filter "namr"`)) }) It("podman network list --filter failure", func() { @@ -148,8 +147,7 @@ var _ = Describe("Podman network", func() { session = podmanTest.Podman([]string{"network", "ls", "--filter", "dangling=foo"}) session.WaitWithDefaultTimeout() - Expect(session).To(ExitWithError()) - Expect(session.ErrorToString()).To(ContainSubstring(`invalid dangling filter value "foo"`)) + Expect(session).To(ExitWithError(125, `invalid dangling filter value "foo"`)) }) It("podman network ID test", func() { @@ -192,8 +190,13 @@ var _ = Describe("Podman network", func() { session = podmanTest.Podman([]string{"network", "inspect", netID[1:]}) session.WaitWithDefaultTimeout() - Expect(session).Should(ExitWithError()) - Expect(session.ErrorToString()).To(ContainSubstring("network not found")) + expectMessage := fmt.Sprintf("network %s: ", netID[1:]) + // FIXME-someday: figure out why this part does not show up in remote + if !IsRemote() { + expectMessage += fmt.Sprintf("unable to find network with name or ID %s: ", netID[1:]) + } + expectMessage += "network not found" + Expect(session).Should(ExitWithError(125, expectMessage)) session = podmanTest.Podman([]string{"network", "rm", netID}) session.WaitWithDefaultTimeout() @@ -204,7 +207,7 @@ var _ = Describe("Podman network", func() { It(fmt.Sprintf("podman network %s no args", rm), func() { session := podmanTest.Podman([]string{"network", rm}) session.WaitWithDefaultTimeout() - Expect(session).Should(ExitWithError()) + Expect(session).Should(ExitWithError(125, "requires at least 1 arg(s), only received 0")) }) @@ -234,7 +237,7 @@ var _ = Describe("Podman network", func() { It("podman network inspect no args", func() { session := podmanTest.Podman([]string{"network", "inspect"}) session.WaitWithDefaultTimeout() - Expect(session).Should(ExitWithError()) + Expect(session).Should(ExitWithError(125, "requires at least 1 arg(s), only received 0")) }) It("podman network inspect", func() { @@ -395,7 +398,7 @@ var _ = Describe("Podman network", func() { It("podman network remove bogus", func() { session := podmanTest.Podman([]string{"network", "rm", "bogus"}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(1)) + Expect(session).Should(ExitWithError(1, "unable to find network with name or ID bogus: network not found")) }) It("podman network remove --force with pod", func() { @@ -416,7 +419,7 @@ var _ = Describe("Podman network", func() { session = podmanTest.Podman([]string{"network", "rm", netName}) session.WaitWithDefaultTimeout() - Expect(session).Should(Exit(2)) + Expect(session).Should(ExitWithError(2, fmt.Sprintf(`"%s" has associated containers with it. Use -f to forcibly delete containers and pods: network is being used`, netName))) session = podmanTest.Podman([]string{"network", "rm", "-t", "0", "--force", netName}) session.WaitWithDefaultTimeout() @@ -426,6 +429,7 @@ var _ = Describe("Podman network", func() { session = podmanTest.Podman([]string{"pod", "exists", podID}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(1)) + Expect(session.ErrorToString()).To(Equal("")) // check if net is deleted session = podmanTest.Podman([]string{"network", "ls"}) @@ -614,6 +618,7 @@ var _ = Describe("Podman network", func() { session = podmanTest.Podman([]string{"network", "exists", stringid.GenerateRandomID()}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(1)) + Expect(session.ErrorToString()).To(Equal("")) }) It("podman network create macvlan with network info and options", func() {