summaryrefslogtreecommitdiff
path: root/test/e2e/search_test.go
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2021-07-14 13:55:00 -0600
committerEd Santiago <santiago@redhat.com>2021-07-15 05:06:33 -0600
commit547fff27033a294d1639ee3f9125f775032f39f5 (patch)
tree056f808343188229738ada44c71432babdcbe391 /test/e2e/search_test.go
parent61245884abb181ee4dd46280a56dec5f25d2432d (diff)
downloadpodman-547fff27033a294d1639ee3f9125f775032f39f5.tar.gz
podman-547fff27033a294d1639ee3f9125f775032f39f5.tar.bz2
podman-547fff27033a294d1639ee3f9125f775032f39f5.zip
e2e tests: use Should(Exit()) and ExitWithError()
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>
Diffstat (limited to 'test/e2e/search_test.go')
-rw-r--r--test/e2e/search_test.go79
1 files changed, 40 insertions, 39 deletions
diff --git a/test/e2e/search_test.go b/test/e2e/search_test.go
index 8c388d0ee..b0faabf6c 100644
--- a/test/e2e/search_test.go
+++ b/test/e2e/search_test.go
@@ -12,6 +12,7 @@ import (
. "github.com/containers/podman/v3/test/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
+ . "github.com/onsi/gomega/gexec"
)
type endpoint struct {
@@ -87,7 +88,7 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search", func() {
search := podmanTest.Podman([]string{"search", "alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray())).To(BeNumerically(">", 1))
Expect(search.LineInOutputContains("docker.io/library/alpine")).To(BeTrue())
})
@@ -95,14 +96,14 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search single registry flag", func() {
search := podmanTest.Podman([]string{"search", "quay.io/skopeo/stable:latest"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(search.LineInOutputContains("quay.io/skopeo/stable")).To(BeTrue())
})
It("podman search image with description", func() {
search := podmanTest.Podman([]string{"search", "quay.io/libpod/whalesay"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
output := string(search.Out.Contents())
match, _ := regexp.MatchString(`(?m)^quay.io\s+quay.io/libpod/whalesay\s+Static image used for automated testing.+$`, output)
Expect(match).To(BeTrue())
@@ -111,7 +112,7 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search format flag", func() {
search := podmanTest.Podman([]string{"search", "--format", "table {{.Index}} {{.Name}}", "alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray())).To(BeNumerically(">", 1))
Expect(search.LineInOutputContains("docker.io/library/alpine")).To(BeTrue())
})
@@ -119,7 +120,7 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search format json", func() {
search := podmanTest.Podman([]string{"search", "--format", "json", "alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(search.IsJSONOutputValid()).To(BeTrue())
Expect(search.OutputToString()).To(ContainSubstring("docker.io/library/alpine"))
})
@@ -127,7 +128,7 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search format json list tags", func() {
search := podmanTest.Podman([]string{"search", "--list-tags", "--format", "json", "alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(search.IsJSONOutputValid()).To(BeTrue())
Expect(search.OutputToString()).To(ContainSubstring("docker.io/library/alpine"))
Expect(search.OutputToString()).To(ContainSubstring("3.10"))
@@ -137,7 +138,7 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search no-trunc flag", func() {
search := podmanTest.Podman([]string{"search", "--no-trunc", "alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray())).To(BeNumerically(">", 1))
Expect(search.LineInOutputContains("docker.io/library/alpine")).To(BeTrue())
Expect(search.LineInOutputContains("...")).To(BeFalse())
@@ -146,24 +147,24 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search limit flag", func() {
search := podmanTest.Podman([]string{"search", "docker.io/alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray())).To(Equal(26))
search = podmanTest.Podman([]string{"search", "--limit", "3", "docker.io/alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray())).To(Equal(4))
search = podmanTest.Podman([]string{"search", "--limit", "30", "docker.io/alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray())).To(Equal(31))
})
It("podman search with filter stars", func() {
search := podmanTest.Podman([]string{"search", "--filter", "stars=10", "--format", "{{.Stars}}", "alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
output := search.OutputToStringArray()
for i := 0; i < len(output); i++ {
Expect(strconv.Atoi(output[i])).To(BeNumerically(">=", 10))
@@ -173,7 +174,7 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search with filter is-official", func() {
search := podmanTest.Podman([]string{"search", "--filter", "is-official", "--format", "{{.Official}}", "alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
output := search.OutputToStringArray()
for i := 0; i < len(output); i++ {
Expect(output[i]).To(Equal("[OK]"))
@@ -183,7 +184,7 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search with filter is-automated", func() {
search := podmanTest.Podman([]string{"search", "--filter", "is-automated=false", "--format", "{{.Automated}}", "alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
output := search.OutputToStringArray()
for i := 0; i < len(output); i++ {
Expect(output[i]).To(Equal(""))
@@ -201,7 +202,7 @@ registries = ['{{.Host}}:{{.Port}}']`
"-p", fmt.Sprintf("%s:5000", registryEndpoints[0].Port),
registry, "/entrypoint.sh", "/etc/docker/registry/config.yml"})
fakereg.WaitWithDefaultTimeout()
- Expect(fakereg.ExitCode()).To(Equal(0))
+ Expect(fakereg).Should(Exit(0))
if !WaitContainerReady(podmanTest, "registry", "listening on", 20, 1) {
Skip("Cannot start docker registry.")
@@ -213,7 +214,7 @@ registries = ['{{.Host}}:{{.Port}}']`
// if this test succeeded, there will be no output (there is no entry named fake/image:andtag in an empty registry)
// and the exit code will be 0
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(search.OutputToString()).Should(BeEmpty())
Expect(search.ErrorToString()).Should(BeEmpty())
})
@@ -228,7 +229,7 @@ registries = ['{{.Host}}:{{.Port}}']`
"-p", fmt.Sprintf("%s:5000", registryEndpoints[3].Port), registry,
"/entrypoint.sh", "/etc/docker/registry/config.yml"})
registry.WaitWithDefaultTimeout()
- Expect(registry.ExitCode()).To(Equal(0))
+ Expect(registry).Should(Exit(0))
if !WaitContainerReady(podmanTest, "registry3", "listening on", 20, 1) {
Skip("Cannot start docker registry.")
@@ -238,17 +239,17 @@ registries = ['{{.Host}}:{{.Port}}']`
image := fmt.Sprintf("%s/my-alpine", registryEndpoints[3].Address())
push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, image})
push.WaitWithDefaultTimeout()
- Expect(push.ExitCode()).To(Equal(0))
+ Expect(push).Should(Exit(0))
search := podmanTest.Podman([]string{"search", image, "--tls-verify=false"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(search.OutputToString()).ShouldNot(BeEmpty())
// podman search v2 registry with empty query
searchEmpty := podmanTest.Podman([]string{"search", fmt.Sprintf("%s/", registryEndpoints[3].Address()), "--tls-verify=false"})
searchEmpty.WaitWithDefaultTimeout()
- Expect(searchEmpty.ExitCode()).To(BeZero())
+ Expect(searchEmpty).Should(Exit(0))
Expect(len(searchEmpty.OutputToStringArray())).To(BeNumerically(">=", 1))
match, _ := search.GrepString("my-alpine")
Expect(match).Should(BeTrue())
@@ -264,7 +265,7 @@ registries = ['{{.Host}}:{{.Port}}']`
registry := podmanTest.Podman([]string{"run", "-d", "-p", fmt.Sprintf("%s:5000", registryEndpoints[4].Port),
"--name", "registry4", registry, "/entrypoint.sh", "/etc/docker/registry/config.yml"})
registry.WaitWithDefaultTimeout()
- Expect(registry.ExitCode()).To(Equal(0))
+ Expect(registry).Should(Exit(0))
if !WaitContainerReady(podmanTest, "registry4", "listening on", 20, 1) {
Skip("Cannot start docker registry.")
@@ -274,7 +275,7 @@ registries = ['{{.Host}}:{{.Port}}']`
image := fmt.Sprintf("%s/my-alpine", registryEndpoints[4].Address())
push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, image})
push.WaitWithDefaultTimeout()
- Expect(push.ExitCode()).To(Equal(0))
+ Expect(push).Should(Exit(0))
// registries.conf set up
var buffer bytes.Buffer
@@ -289,7 +290,7 @@ registries = ['{{.Host}}:{{.Port}}']`
search := podmanTest.Podman([]string{"search", image})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
match, _ := search.GrepString("my-alpine")
Expect(match).Should(BeTrue())
Expect(search.ErrorToString()).Should(BeEmpty())
@@ -307,7 +308,7 @@ registries = ['{{.Host}}:{{.Port}}']`
registry := podmanTest.Podman([]string{"run", "-d", "-p", fmt.Sprintf("%s:5000", registryEndpoints[5].Port),
"--name", "registry5", registry})
registry.WaitWithDefaultTimeout()
- Expect(registry.ExitCode()).To(Equal(0))
+ Expect(registry).Should(Exit(0))
if !WaitContainerReady(podmanTest, "registry5", "listening on", 20, 1) {
Skip("Cannot start docker registry.")
@@ -317,7 +318,7 @@ registries = ['{{.Host}}:{{.Port}}']`
image := fmt.Sprintf("%s/my-alpine", registryEndpoints[5].Address())
push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, image})
push.WaitWithDefaultTimeout()
- Expect(push.ExitCode()).To(Equal(0))
+ Expect(push).Should(Exit(0))
var buffer bytes.Buffer
registryFileTmpl.Execute(&buffer, registryEndpoints[5])
@@ -327,7 +328,7 @@ registries = ['{{.Host}}:{{.Port}}']`
search := podmanTest.Podman([]string{"search", image, "--tls-verify=true"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(125))
+ Expect(search).Should(Exit(125))
Expect(search.OutputToString()).Should(BeEmpty())
match, _ := search.ErrorGrepString("error")
Expect(match).Should(BeTrue())
@@ -345,7 +346,7 @@ registries = ['{{.Host}}:{{.Port}}']`
registry := podmanTest.Podman([]string{"run", "-d", "-p", fmt.Sprintf("%s:5000", registryEndpoints[6].Port),
"--name", "registry6", registry})
registry.WaitWithDefaultTimeout()
- Expect(registry.ExitCode()).To(Equal(0))
+ Expect(registry).Should(Exit(0))
if !WaitContainerReady(podmanTest, "registry6", "listening on", 20, 1) {
Skip("Cannot start docker registry.")
@@ -355,7 +356,7 @@ registries = ['{{.Host}}:{{.Port}}']`
image := fmt.Sprintf("%s/my-alpine", registryEndpoints[6].Address())
push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, image})
push.WaitWithDefaultTimeout()
- Expect(push.ExitCode()).To(Equal(0))
+ Expect(push).Should(Exit(0))
var buffer bytes.Buffer
registryFileBadTmpl.Execute(&buffer, registryEndpoints[6])
@@ -370,7 +371,7 @@ registries = ['{{.Host}}:{{.Port}}']`
search := podmanTest.Podman([]string{"search", image})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(125))
+ Expect(search).Should(Exit(125))
Expect(search.OutputToString()).Should(BeEmpty())
match, _ := search.ErrorGrepString("error")
Expect(match).Should(BeTrue())
@@ -391,7 +392,7 @@ registries = ['{{.Host}}:{{.Port}}']`
registryLocal := podmanTest.Podman([]string{"run", "-d", "--net=host", "-p", fmt.Sprintf("%s:5000", registryEndpoints[7].Port),
"--name", "registry7", registry})
registryLocal.WaitWithDefaultTimeout()
- Expect(registryLocal.ExitCode()).To(Equal(0))
+ Expect(registryLocal).Should(Exit(0))
if !WaitContainerReady(podmanTest, "registry7", "listening on", 20, 1) {
Skip("Cannot start docker registry.")
@@ -399,7 +400,7 @@ registries = ['{{.Host}}:{{.Port}}']`
registryLocal = podmanTest.Podman([]string{"run", "-d", "-p", "6000:5000", "--name", "registry8", registry})
registryLocal.WaitWithDefaultTimeout()
- Expect(registryLocal.ExitCode()).To(Equal(0))
+ Expect(registryLocal).Should(Exit(0))
if !WaitContainerReady(podmanTest, "registry8", "listening on", 20, 1) {
Skip("Cannot start docker registry.")
@@ -408,7 +409,7 @@ registries = ['{{.Host}}:{{.Port}}']`
podmanTest.RestoreArtifact(ALPINE)
push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, "localhost:6000/my-alpine"})
push.WaitWithDefaultTimeout()
- Expect(push.ExitCode()).To(Equal(0))
+ Expect(push).Should(Exit(0))
// registries.conf set up
var buffer bytes.Buffer
@@ -424,7 +425,7 @@ registries = ['{{.Host}}:{{.Port}}']`
search := podmanTest.Podman([]string{"search", "my-alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(125))
+ Expect(search).Should(Exit(125))
Expect(search.OutputToString()).Should(BeEmpty())
match, _ := search.ErrorGrepString("error")
Expect(match).Should(BeTrue())
@@ -437,35 +438,35 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search fail with nonexistent --authfile", func() {
search := podmanTest.Podman([]string{"search", "--authfile", "/tmp/nonexistent", ALPINE})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Not(Equal(0)))
+ Expect(search).To(ExitWithError())
})
It("podman search with wildcards", func() {
search := podmanTest.Podman([]string{"search", "--limit", "30", "registry.redhat.io/*"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray())).To(Equal(31))
search = podmanTest.Podman([]string{"search", "registry.redhat.io/*openshift*"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray()) > 1).To(BeTrue())
})
It("podman search repository tags", func() {
search := podmanTest.Podman([]string{"search", "--list-tags", "--limit", "30", "docker.io/library/alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray())).To(Equal(31))
search = podmanTest.Podman([]string{"search", "--list-tags", "docker.io/library/alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray()) > 2).To(BeTrue())
search = podmanTest.Podman([]string{"search", "--filter=is-official", "--list-tags", "docker.io/library/alpine"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Not(Equal(0)))
+ Expect(search).To(ExitWithError())
search = podmanTest.Podman([]string{"search", "--list-tags", "docker.io/library/"})
search.WaitWithDefaultTimeout()
@@ -475,7 +476,7 @@ registries = ['{{.Host}}:{{.Port}}']`
It("podman search with limit over 100", func() {
search := podmanTest.Podman([]string{"search", "--limit", "130", "registry.redhat.io/rhel"})
search.WaitWithDefaultTimeout()
- Expect(search.ExitCode()).To(Equal(0))
+ Expect(search).Should(Exit(0))
Expect(len(search.OutputToStringArray())).To(Equal(131))
})
})