Skip to content

Commit

Permalink
ExitWithError() - s 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 test/e2e/s*_test.go

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed May 13, 2024
1 parent 0c09421 commit 0c22de7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 50 deletions.
12 changes: 5 additions & 7 deletions test/e2e/save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var _ = Describe("Podman save", func() {

save := podmanTest.Podman([]string{"save", "-q", "-o", outfile, "FOOBAR"})
save.WaitWithDefaultTimeout()
Expect(save).To(ExitWithError())
Expect(save).To(ExitWithError(125, "repository name must be lowercase"))
})

It("podman save to directory with oci format", func() {
Expand Down Expand Up @@ -102,13 +102,11 @@ var _ = Describe("Podman save", func() {

save := podmanTest.Podman([]string{"save", "-q", "--compress", "--format", "docker-archive", "-o", outdir, ALPINE})
save.WaitWithDefaultTimeout()
// should not be 0
Expect(save).To(ExitWithError())
Expect(save).To(ExitWithError(125, "--compress can only be set when --format is 'docker-dir'"))

save = podmanTest.Podman([]string{"save", "-q", "--compress", "--format", "oci-archive", "-o", outdir, ALPINE})
save.WaitWithDefaultTimeout()
// should not be 0
Expect(save).To(ExitWithError())
Expect(save).To(ExitWithError(125, "--compress can only be set when --format is 'docker-dir'"))

})

Expand All @@ -117,7 +115,7 @@ var _ = Describe("Podman save", func() {

save := podmanTest.Podman([]string{"save", "-q", "--compress", "--format", "docker-dir", "-o", outdir, ALPINE})
save.WaitWithDefaultTimeout()
Expect(save).To(ExitWithError())
Expect(save).To(ExitWithError(125, fmt.Sprintf(`invalid filename (should not contain ':') "%s"`, outdir)))
})

It("podman save remove signature", func() {
Expand Down Expand Up @@ -199,7 +197,7 @@ default-docker:
outfile := filepath.Join(podmanTest.TempDir, "temp.tar")
save := podmanTest.Podman([]string{"save", "-q", "remove-signatures=true", "-o", outfile, pushedImage})
save.WaitWithDefaultTimeout()
Expect(save).To(ExitWithError())
Expect(save).To(ExitWithError(125, "invalid reference format"))
}
})

Expand Down
18 changes: 6 additions & 12 deletions test/e2e/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

type endpoint struct {
Expand Down Expand Up @@ -314,9 +313,8 @@ registries = []`
search := podmanTest.Podman([]string{"search", image, "--tls-verify=true"})
search.WaitWithDefaultTimeout()

Expect(search).Should(Exit(125))
Expect(search).Should(ExitWithError(125, fmt.Sprintf(`couldn't search registry "localhost:%d": pinging container registry localhost:%d: Get "https://localhost:%d/v2/": http: server gave HTTP response to HTTPS client`, port, port, port)))
Expect(search.OutputToString()).Should(BeEmpty())
Expect(search.ErrorToString()).To(ContainSubstring("http: server gave HTTP response to HTTPS client"))

// cleanup
resetRegistriesConfigEnv()
Expand Down Expand Up @@ -359,9 +357,8 @@ registries = []`
search := podmanTest.Podman([]string{"search", image})
search.WaitWithDefaultTimeout()

Expect(search).Should(Exit(125))
Expect(search).Should(ExitWithError(125, fmt.Sprintf(`couldn't search registry "localhost:%d": pinging container registry localhost:%d: Get "https://localhost:%d/v2/": http: server gave HTTP response to HTTPS client`, port, port, port)))
Expect(search.OutputToString()).Should(BeEmpty())
Expect(search.ErrorToString()).To(ContainSubstring("http: server gave HTTP response to HTTPS client"))

// cleanup
resetRegistriesConfigEnv()
Expand All @@ -371,7 +368,7 @@ registries = []`
It("podman search fail with nonexistent --authfile", func() {
search := podmanTest.Podman([]string{"search", "--authfile", "/tmp/nonexistent", ALPINE})
search.WaitWithDefaultTimeout()
Expect(search).To(ExitWithError())
Expect(search).To(ExitWithError(125, "credential file is not accessible: faccessat /tmp/nonexistent: no such file or directory"))
})

// Registry is unreliable (#18484), this is another super-common flake
Expand All @@ -395,22 +392,19 @@ registries = []`

search = podmanTest.Podman([]string{"search", "--filter=is-official", "--list-tags", "quay.io/podman/stable"})
search.WaitWithDefaultTimeout()
Expect(search).To(Exit(125))
Expect(search.ErrorToString()).To(ContainSubstring("filters are not applicable to list tags result"))
Expect(search).To(ExitWithError(125, "filters are not applicable to list tags result"))

// With trailing slash
search = podmanTest.Podman([]string{"search", "--list-tags", "quay.io/podman/"})
search.WaitWithDefaultTimeout()
Expect(search).To(Exit(125))
Expect(search).To(ExitWithError(125, `reference "podman/" must be a docker reference`))
Expect(search.OutputToStringArray()).To(BeEmpty())
Expect(search.ErrorToString()).To(ContainSubstring("must be a docker reference"))

// No trailing slash
search = podmanTest.Podman([]string{"search", "--list-tags", "quay.io/podman"})
search.WaitWithDefaultTimeout()
Expect(search).To(Exit(125))
Expect(search).To(ExitWithError(125, "getting repository tags: fetching tags list: StatusCode: 404"))
Expect(search.OutputToStringArray()).To(BeEmpty())
Expect(search.ErrorToString()).To(ContainSubstring("fetching tags list: StatusCode: 404"))
})

It("podman search with limit over 100", func() {
Expand Down
16 changes: 6 additions & 10 deletions test/e2e/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ var _ = Describe("Podman secret", func() {

session = podmanTest.Podman([]string{"secret", "create", "-d", "file", "--driver-opts", "opt1=val1", "a", secretFilePath})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session.ErrorToString()).To(Equal("Error: a: secret name in use"))
Expect(session).Should(ExitWithError(125, "Error: a: secret name in use"))

session = podmanTest.Podman([]string{"secret", "create", "-d", "file", "--driver-opts", "opt1=val1", "--replace", "a", secretFilePath})
session.WaitWithDefaultTimeout()
Expand All @@ -49,8 +48,7 @@ var _ = Describe("Podman secret", func() {

inspect = podmanTest.Podman([]string{"secret", "inspect", "-f", "{{.Spec.Driver.Options}}", secrID})
inspect.WaitWithDefaultTimeout()
Expect(inspect).To(ExitWithError())
Expect(inspect.ErrorToString()).To(ContainSubstring(fmt.Sprintf("Error: inspecting secret: no secret with name or id %q: no such secret", secrID)))
Expect(inspect).To(ExitWithError(125, fmt.Sprintf("Error: inspecting secret: no secret with name or id %q: no such secret", secrID)))

inspect = podmanTest.Podman([]string{"secret", "inspect", "-f", "{{.Spec.Driver.Options}}", "a"})
inspect.WaitWithDefaultTimeout()
Expand All @@ -66,14 +64,12 @@ var _ = Describe("Podman secret", func() {
badName := "foo/bar"
session := podmanTest.Podman([]string{"secret", "create", badName, secretFilePath})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(Equal(fmt.Sprintf("Error: secret name %q can not include '=', '/', ',', or the '\\0' (NULL) and be between 1 and 253 characters: invalid secret name", badName)))
Expect(session).To(ExitWithError(125, fmt.Sprintf("Error: secret name %q can not include '=', '/', ',', or the '\\0' (NULL) and be between 1 and 253 characters: invalid secret name", badName)))

badName = "foo=bar"
session = podmanTest.Podman([]string{"secret", "create", badName, secretFilePath})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(Equal(fmt.Sprintf("Error: secret name %q can not include '=', '/', ',', or the '\\0' (NULL) and be between 1 and 253 characters: invalid secret name", badName)))
Expect(session).To(ExitWithError(125, fmt.Sprintf("Error: secret name %q can not include '=', '/', ',', or the '\\0' (NULL) and be between 1 and 253 characters: invalid secret name", badName)))
})

It("podman secret inspect", func() {
Expand Down Expand Up @@ -164,7 +160,7 @@ var _ = Describe("Podman secret", func() {

inspect := podmanTest.Podman([]string{"secret", "inspect", "bogus"})
inspect.WaitWithDefaultTimeout()
Expect(inspect).To(ExitWithError())
Expect(inspect).To(ExitWithError(125, `inspecting secret: no secret with name or id "bogus": no such secret`))
})

It("podman secret ls", func() {
Expand Down Expand Up @@ -352,7 +348,7 @@ var _ = Describe("Podman secret", func() {
// no env variable set, should fail
session := podmanTest.Podman([]string{"secret", "create", "--env", "a", "MYENVVAR"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "cannot create store secret data: environment variable MYENVVAR is not set"))

os.Setenv("MYENVVAR", "somedata")
if IsRemote() {
Expand Down
27 changes: 13 additions & 14 deletions test/e2e/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,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 start", func() {

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

It("podman start single container by id", func() {
Expand All @@ -37,10 +36,10 @@ var _ = Describe("Podman start", func() {
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"start", "test"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "not found in $PATH"))
session = podmanTest.Podman([]string{"container", "exists", "test"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(1))
})

It("podman start --rm --attach removed on failure", func() {
Expand All @@ -50,10 +49,10 @@ var _ = Describe("Podman start", func() {
cid := session.OutputToString()
session = podmanTest.Podman([]string{"start", "--attach", cid})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "not found in $PATH"))
session = podmanTest.Podman([]string{"container", "exists", cid})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(1))
})

It("podman container start single container by id", func() {
Expand Down Expand Up @@ -98,7 +97,7 @@ var _ = Describe("Podman start", func() {
session = podmanTest.Podman([]string{"start", "--attach", cid})
session.WaitWithDefaultTimeout()
// It should forward the signal
Expect(session).Should(Exit(1))
Expect(session).Should(ExitWithError(1))
})

It("podman start multiple containers", func() {
Expand All @@ -119,7 +118,7 @@ var _ = Describe("Podman start", func() {
cid1 := session.OutputToString()
session = podmanTest.Podman([]string{"start", cid1, "doesnotexist"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, `no container with name or ID "doesnotexist" found: no such container`))
})

It("podman multiple containers -- attach should fail", func() {
Expand All @@ -131,7 +130,7 @@ var _ = Describe("Podman start", func() {
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"start", "-a", "foobar1", "foobar2"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "you cannot start and attach multiple containers at once"))
})

It("podman failed to start with --rm should delete the container", func() {
Expand All @@ -144,7 +143,7 @@ var _ = Describe("Podman start", func() {

wait := podmanTest.Podman([]string{"wait", "test1"})
wait.WaitWithDefaultTimeout()
Expect(wait).To(ExitWithError())
Expect(wait).To(ExitWithError(125, `no container with name or ID "test1" found: no such container`))

Eventually(podmanTest.NumberOfContainers, defaultWaitTimeout, 3.0).Should(BeZero())
})
Expand All @@ -156,19 +155,19 @@ var _ = Describe("Podman start", func() {

start := podmanTest.Podman([]string{"start", session.OutputToString()})
start.WaitWithDefaultTimeout()
Expect(start).To(ExitWithError())
Expect(start).To(ExitWithError(125, "not found in $PATH"))

Eventually(podmanTest.NumberOfContainers, defaultWaitTimeout, 3.0).Should(Equal(1))
})

It("podman start --sig-proxy should not work without --attach", func() {
session := podmanTest.Podman([]string{"create", ALPINE, "ls"})
session := podmanTest.Podman([]string{"create", "--name", "sigproxyneedsattach", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())

session = podmanTest.Podman([]string{"start", "-l", "--sig-proxy"})
session = podmanTest.Podman([]string{"start", "--sig-proxy", "sigproxyneedsattach"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "you cannot use sig-proxy without --attach: invalid argument"))
})

It("podman start container with special pidfile", func() {
Expand Down
14 changes: 9 additions & 5 deletions test/e2e/stats_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"
)

// TODO: we need to check the output. Currently, we only check the exit codes
Expand All @@ -25,7 +24,12 @@ var _ = Describe("Podman stats", func() {
It("podman stats with bogus container", func() {
session := podmanTest.Podman([]string{"stats", "--no-stream", "123"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
expect := `unable to get list of containers: unable to look up container 123: no container with name or ID "123" found: no such container`
// FIXME: #22612
if IsRemote() {
expect = "types.ContainerStatsReport.Error: decode non empty interface: can not unmarshal into nil, error found in #9 byte"
}
Expect(session).Should(ExitWithError(125, expect))
})

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

It("podman stats with negative interval", func() {
Expand All @@ -90,7 +94,7 @@ var _ = Describe("Podman stats", func() {
Expect(session).Should(ExitCleanly())
stats := podmanTest.Podman([]string{"stats", "-a", "--no-reset", "--no-stream", "--interval=-1"})
stats.WaitWithDefaultTimeout()
Expect(stats).To(ExitWithError())
Expect(stats).To(ExitWithError(125, "invalid interval, must be a positive number greater zero"))
})

It("podman stats with zero interval", func() {
Expand All @@ -99,7 +103,7 @@ var _ = Describe("Podman stats", func() {
Expect(session).Should(ExitCleanly())
stats := podmanTest.Podman([]string{"stats", "-a", "--no-reset", "--no-stream", "--interval=0"})
stats.WaitWithDefaultTimeout()
Expect(stats).To(ExitWithError())
Expect(stats).To(ExitWithError(125, "invalid interval, must be a positive number greater zero"))
})

It("podman stats with interval", func() {
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/system_df_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ var _ = Describe("podman system df", func() {
It("podman system df --format with --verbose", func() {
session := podmanTest.Podman([]string{"system", "df", "--format", "json", "--verbose"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(Equal("Error: cannot combine --format and --verbose flags"))
Expect(session).To(ExitWithError(125, "Error: cannot combine --format and --verbose flags"))
})

It("podman system df --format json", func() {
Expand Down

0 comments on commit 0c22de7

Please sign in to comment.