mirror of
https://github.com/containers/podman.git
synced 2025-08-26 03:01:31 +08:00

e2e test failures are rife with messages like: Expected 1 to equal 0 These make me cry. They're anti-helpful, requiring the reader to dive into the source code to figure out what those numbers mean. Solution: Go tests have a '.Should(Exit(NNN))' mechanism. I don't know if it spits out a better diagnostic (I have no way to run e2e tests on my laptop), but I have to fantasize that it will, and given the state of our flakes I assume that at least one test will fail and give me the opportunity to see what the error message looks like. THIS IS NOT REVIEWABLE CODE. There is no way for a human to review it. Don't bother. Maybe look at a few random ones for sanity. If you want to really review, here is a reproducer of what I did: cd test/e2e ! positive assertions. The second is the same as the first, ! with the addition of (unnecessary) parentheses because ! some invocations were written that way. The third is BeZero(). perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Equal\((\d+)\)\)/Expect($1).Should(Exit($2))/' *_test.go perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(\(Equal\((\d+)\)\)\)/Expect($1).Should(Exit($2))/' *_test.go perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(BeZero\(\)\)/Expect($1).Should(Exit(0))/' *_test.go ! Same as above, but handles three non-numeric exit codes ! in run_exit_test.go perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Equal\((\S+)\)\)/Expect($1).Should(Exit($2))/' *_test.go ! negative assertions. Difference is the spelling of 'To(Not)', ! 'ToNot', and 'NotTo'. I assume those are all the same. perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Not\(Equal\((0)\)\)\)/Expect($1).To(ExitWithError())/' *_test.go perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.ToNot\(Equal\((0)\)\)/Expect($1).To(ExitWithError())/' *_test.go perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.NotTo\(Equal\((0)\)\)/Expect($1).To(ExitWithError())/' *_test.go ! negative, old use of BeZero() perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.ToNot\(BeZero\(\)\)/Expect($1).Should(ExitWithError())/' *_test.go Run those on a clean copy of main branch (at the same branch point as my PR, of course), then diff against a checked-out copy of my PR. There should be no differences. Then all you have to review is that my replacements above are sane. UPDATE: nope, that's not enough, you also need to add gomega/gexec to the files that don't have it: perl -pi -e '$_ .= "$1/gexec\"\n" if m!^(.*/onsi/gomega)"!' $(grep -L gomega/gexec $(git log -1 --stat | awk '$1 ~ /test\/e2e\// { print $1}')) UPDATE 2: hand-edit run_volume_test.go UPDATE 3: sigh, add WaitWithDefaultTimeout() to a couple of places UPDATE 4: skip a test due to bug #10935 (race condition) Signed-off-by: Ed Santiago <santiago@redhat.com>
382 lines
14 KiB
Go
382 lines
14 KiB
Go
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"sort"
|
|
|
|
. "github.com/containers/podman/v3/test/utils"
|
|
"github.com/containers/storage/pkg/stringid"
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
. "github.com/onsi/gomega/gexec"
|
|
)
|
|
|
|
var _ = Describe("Podman ps", func() {
|
|
var (
|
|
tempdir string
|
|
err error
|
|
podmanTest *PodmanTestIntegration
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
tempdir, err = CreateTempDirInTempDir()
|
|
if err != nil {
|
|
os.Exit(1)
|
|
}
|
|
podmanTest = PodmanTestCreate(tempdir)
|
|
podmanTest.Setup()
|
|
podmanTest.SeedImages()
|
|
})
|
|
|
|
AfterEach(func() {
|
|
podmanTest.Cleanup()
|
|
f := CurrentGinkgoTestDescription()
|
|
processTestResult(f)
|
|
|
|
})
|
|
|
|
It("podman pod ps no pods", func() {
|
|
session := podmanTest.Podman([]string{"pod", "ps"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
})
|
|
|
|
It("podman pod ps default", func() {
|
|
_, ec, podid := podmanTest.CreatePod(nil)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
session := podmanTest.RunTopContainerInPod("", podid)
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
|
|
result := podmanTest.Podman([]string{"pod", "ps"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(0))
|
|
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
|
|
})
|
|
|
|
It("podman pod ps quiet flag", func() {
|
|
_, ec, podid := podmanTest.CreatePod(nil)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
_, ec, _ = podmanTest.RunLsContainerInPod("", podid)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
result := podmanTest.Podman([]string{"pod", "ps", "-q"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).To(Exit(0))
|
|
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
|
|
Expect(podid).To(ContainSubstring(result.OutputToStringArray()[0]))
|
|
})
|
|
|
|
It("podman pod ps no-trunc", func() {
|
|
_, ec, podid := podmanTest.CreatePod(nil)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
_, ec2, _ := podmanTest.RunLsContainerInPod("", podid)
|
|
Expect(ec2).To(Equal(0))
|
|
|
|
result := podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(0))
|
|
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
|
|
Expect(podid).To(Equal(result.OutputToStringArray()[0]))
|
|
})
|
|
|
|
It("podman pod ps latest", func() {
|
|
SkipIfRemote("--latest flag n/a")
|
|
_, ec, podid1 := podmanTest.CreatePod(nil)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
_, ec2, podid2 := podmanTest.CreatePod(nil)
|
|
Expect(ec2).To(Equal(0))
|
|
|
|
result := podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--latest"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(0))
|
|
Expect(result.OutputToString()).To(ContainSubstring(podid2))
|
|
Expect(result.OutputToString()).To(Not(ContainSubstring(podid1)))
|
|
})
|
|
|
|
It("podman pod ps id filter flag", func() {
|
|
_, ec, podid := podmanTest.CreatePod(nil)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
result := podmanTest.Podman([]string{"pod", "ps", "--filter", fmt.Sprintf("id=%s", podid)})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(0))
|
|
})
|
|
|
|
It("podman pod ps filter name regexp", func() {
|
|
_, ec, podid := podmanTest.CreatePod(map[string][]string{"--name": {"mypod"}})
|
|
Expect(ec).To(Equal(0))
|
|
_, ec2, _ := podmanTest.CreatePod(map[string][]string{"--name": {"mypod1"}})
|
|
Expect(ec2).To(Equal(0))
|
|
|
|
result := podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "name=mypod"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(0))
|
|
|
|
output := result.OutputToStringArray()
|
|
Expect(len(output)).To(Equal(2))
|
|
|
|
result = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "name=mypod$"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result).Should(Exit(0))
|
|
|
|
output = result.OutputToStringArray()
|
|
Expect(len(output)).To(Equal(1))
|
|
Expect(output[0]).To(Equal(podid))
|
|
})
|
|
|
|
It("podman pod ps mutually exclusive flags", func() {
|
|
session := podmanTest.Podman([]string{"pod", "ps", "-q", "--format", "{{.ID}}"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).To(ExitWithError())
|
|
|
|
})
|
|
|
|
It("podman pod ps --sort by name", func() {
|
|
_, ec, _ := podmanTest.CreatePod(nil)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
_, ec2, _ := podmanTest.CreatePod(nil)
|
|
Expect(ec2).To(Equal(0))
|
|
|
|
_, ec3, _ := podmanTest.CreatePod(nil)
|
|
Expect(ec3).To(Equal(0))
|
|
|
|
session := podmanTest.Podman([]string{"pod", "ps", "--sort=name", "--format", "{{.Name}}"})
|
|
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
|
|
sortedArr := session.OutputToStringArray()
|
|
|
|
Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { return sortedArr[i] < sortedArr[j] })).To(BeTrue())
|
|
})
|
|
|
|
It("podman pod ps --ctr-names", func() {
|
|
SkipIfRootlessCgroupsV1("Not supported for rootless + CGroupsV1")
|
|
_, ec, podid := podmanTest.CreatePod(nil)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
session := podmanTest.RunTopContainerInPod("test1", podid)
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
|
|
_, ec, _ = podmanTest.RunLsContainerInPod("test2", podid)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "--format={{.ContainerNames}}", "--ctr-names"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring("test1"))
|
|
Expect(session.OutputToString()).To(ContainSubstring("test2"))
|
|
})
|
|
|
|
It("podman pod ps filter ctr attributes", func() {
|
|
_, ec, podid1 := podmanTest.CreatePod(nil)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
session := podmanTest.RunTopContainerInPod("test1", podid1)
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
|
|
_, ec2, podid2 := podmanTest.CreatePod(nil)
|
|
Expect(ec2).To(Equal(0))
|
|
|
|
_, ec3, cid := podmanTest.RunLsContainerInPod("test2", podid2)
|
|
Expect(ec3).To(Equal(0))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-names=test1"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid1))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid2)))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-names=test", "--filter", "ctr-status=running"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid1))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid2)))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", fmt.Sprintf("ctr-ids=%s", cid)})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid2))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid1)))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-ids=" + cid[:40], "--filter", "ctr-ids=" + cid + "$"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid2))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid1)))
|
|
|
|
_, ec3, podid3 := podmanTest.CreatePod(nil)
|
|
Expect(ec3).To(Equal(0))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-number=1"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid1))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid2))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid3)))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-number=1", "--filter", "ctr-number=0"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid1))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid2))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid3))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-status=running"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid1))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid2)))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid3)))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-status=exited"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid2))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid1)))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid3)))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-status=exited", "--filter", "ctr-status=running"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid1))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid2))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid3)))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-status=created"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(BeEmpty())
|
|
})
|
|
|
|
It("podman pod ps filter labels", func() {
|
|
s, _, podid1 := podmanTest.CreatePod(nil)
|
|
Expect(s).To(Exit(0))
|
|
|
|
s, _, podid2 := podmanTest.CreatePod(map[string][]string{
|
|
"--label": {"app=myapp", "io.podman.test.key=irrelevant-value"},
|
|
})
|
|
Expect(s).To(Exit(0))
|
|
|
|
s, _, podid3 := podmanTest.CreatePod(map[string][]string{"--label": {"app=test"}})
|
|
Expect(s).To(Exit(0))
|
|
|
|
session := podmanTest.Podman([]string{"pod", "ps", "--no-trunc", "--filter", "label=app", "--filter", "label=app=myapp"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).To(Exit(0))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid1)))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podid2))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid3)))
|
|
})
|
|
|
|
It("podman pod ps filter network", func() {
|
|
net := stringid.GenerateNonCryptoID()
|
|
session := podmanTest.Podman([]string{"network", "create", net})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
defer podmanTest.removeCNINetwork(net)
|
|
|
|
session = podmanTest.Podman([]string{"pod", "create", "--network", net})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
podWithNet := session.OutputToString()
|
|
|
|
session = podmanTest.Podman([]string{"pod", "create"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
podWithoutNet := session.OutputToString()
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "--no-trunc", "--filter", "network=" + net})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring(podWithNet))
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podWithoutNet)))
|
|
})
|
|
|
|
It("podman pod ps --format networks", func() {
|
|
session := podmanTest.Podman([]string{"pod", "create"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "--format", "{{ .Networks }}"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
if isRootless() {
|
|
// rootless container don't have a network by default
|
|
Expect(session.OutputToString()).To(Equal(""))
|
|
} else {
|
|
// default network name is podman
|
|
Expect(session.OutputToString()).To(Equal("podman"))
|
|
}
|
|
|
|
net1 := stringid.GenerateNonCryptoID()
|
|
session = podmanTest.Podman([]string{"network", "create", net1})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
defer podmanTest.removeCNINetwork(net1)
|
|
net2 := stringid.GenerateNonCryptoID()
|
|
session = podmanTest.Podman([]string{"network", "create", net2})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
defer podmanTest.removeCNINetwork(net2)
|
|
|
|
session = podmanTest.Podman([]string{"pod", "create", "--network", net1 + "," + net2})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
pid := session.OutputToString()
|
|
|
|
session = podmanTest.Podman([]string{"pod", "ps", "--format", "{{ .Networks }}", "--filter", "id=" + pid})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
// the output is not deterministic so check both possible orders
|
|
Expect(session.OutputToString()).To(Or(Equal(net1+","+net2), Equal(net2+","+net1)))
|
|
})
|
|
|
|
It("pod no infra should ps", func() {
|
|
session := podmanTest.Podman([]string{"pod", "create", "--infra=false"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
|
|
ps := podmanTest.Podman([]string{"pod", "ps"})
|
|
ps.WaitWithDefaultTimeout()
|
|
Expect(ps).Should(Exit(0))
|
|
|
|
infra := podmanTest.Podman([]string{"pod", "ps", "--format", "{{.InfraId}}"})
|
|
infra.WaitWithDefaultTimeout()
|
|
Expect(len(infra.OutputToString())).To(BeZero())
|
|
})
|
|
|
|
It("podman pod ps format with labels", func() {
|
|
_, ec, _ := podmanTest.CreatePod(nil)
|
|
Expect(ec).To(Equal(0))
|
|
|
|
_, ec1, _ := podmanTest.CreatePod(map[string][]string{"--label": {
|
|
"io.podman.test.label=value1",
|
|
"io.podman.test.key=irrelevant-value",
|
|
}})
|
|
Expect(ec1).To(Equal(0))
|
|
|
|
session := podmanTest.Podman([]string{"pod", "ps", "--format", "{{.Labels}}"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(ContainSubstring("value1"))
|
|
})
|
|
|
|
It("podman pod ps headers", func() {
|
|
session := podmanTest.Podman([]string{"pod", "ps", "--ctr-ids", "--ctr-names", "--ctr-status", "--ns"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(MatchRegexp(`^POD ID\s+NAME\s+STATUS\s+CREATED\s+INFRA ID\s+IDS\s+NAMES\s+STATUS\s+CGROUP\s+NAMESPACES$`))
|
|
})
|
|
|
|
})
|