mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-28 03:07:56 +00:00
test/e2e: remove LineInOutputContainsTag
A bool assert on the parsed repo/tag map says nothing about the actual images output when it fails. Match the line with a regex instead, the failure then prints every line and the pattern. This also removes tagOutputToMap which had no other user. Part of #18540. Signed-off-by: Tushar Verma <tusharmyself06@gmail.com>
This commit is contained in:
parent
88b173cbde
commit
9f691c8a65
5 changed files with 16 additions and 66 deletions
|
|
@ -5,6 +5,7 @@ package integration
|
|||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
|
@ -61,7 +62,7 @@ var _ = Describe("Podman checkpoint", func() {
|
|||
session = podmanTest.Podman([]string{"images"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(session.LineInOutputContainsTag("localhost/"+checkpointImage, "latest")).To(BeFalse())
|
||||
Expect(session.OutputToStringArray()).ToNot(ContainElement(MatchRegexp("^" + regexp.QuoteMeta("localhost/"+checkpointImage) + `\s+latest\s`)))
|
||||
|
||||
// Check if none of the checkpoint/restore specific information is displayed
|
||||
// for newly started containers.
|
||||
|
|
@ -94,7 +95,7 @@ var _ = Describe("Podman checkpoint", func() {
|
|||
session = podmanTest.Podman([]string{"images"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(session.LineInOutputContainsTag("localhost/"+checkpointImage, "latest")).To(BeTrue())
|
||||
Expect(session.OutputToStringArray()).To(ContainElement(MatchRegexp("^" + regexp.QuoteMeta("localhost/"+checkpointImage) + `\s+latest\s`)))
|
||||
|
||||
// Check if the checkpoint image contains annotations
|
||||
inspect = podmanTest.Podman([]string{"inspect", checkpointImage})
|
||||
|
|
@ -159,7 +160,7 @@ var _ = Describe("Podman checkpoint", func() {
|
|||
session = podmanTest.Podman([]string{"images"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(session.LineInOutputContainsTag("localhost/"+checkpointImage, "latest")).To(BeFalse())
|
||||
Expect(session.OutputToStringArray()).ToNot(ContainElement(MatchRegexp("^" + regexp.QuoteMeta("localhost/"+checkpointImage) + `\s+latest\s`)))
|
||||
|
||||
result := podmanTest.Podman([]string{"container", "checkpoint", "--create-image", checkpointImage, "--keep", containerID})
|
||||
result.WaitWithDefaultTimeout()
|
||||
|
|
@ -172,7 +173,7 @@ var _ = Describe("Podman checkpoint", func() {
|
|||
session = podmanTest.Podman([]string{"images"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(session.LineInOutputContainsTag("localhost/"+checkpointImage, "latest")).To(BeTrue())
|
||||
Expect(session.OutputToStringArray()).To(ContainElement(MatchRegexp("^" + regexp.QuoteMeta("localhost/"+checkpointImage) + `\s+latest\s`)))
|
||||
|
||||
// Remove existing container
|
||||
result = podmanTest.Podman([]string{"rm", "-t", "1", "-f", containerID})
|
||||
|
|
|
|||
|
|
@ -49,13 +49,14 @@ var _ = Describe("Podman images", func() {
|
|||
session = podmanTest.Podman([]string{"images"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(session.LineInOutputContainsTag("quay.io/libpod/alpine", "latest")).To(BeTrue())
|
||||
Expect(session.LineInOutputContainsTag("quay.io/libpod/busybox", "latest")).To(BeTrue())
|
||||
Expect(session.LineInOutputContainsTag("localhost/foo", "a")).To(BeTrue())
|
||||
Expect(session.LineInOutputContainsTag("localhost/foo", "b")).To(BeTrue())
|
||||
Expect(session.LineInOutputContainsTag("localhost/foo", "c")).To(BeTrue())
|
||||
Expect(session.LineInOutputContainsTag("localhost/bar", "a")).To(BeTrue())
|
||||
Expect(session.LineInOutputContainsTag("localhost/bar", "b")).To(BeTrue())
|
||||
images := session.OutputToStringArray()
|
||||
Expect(images).To(ContainElement(MatchRegexp(`^quay\.io/libpod/alpine\s+latest\s`)))
|
||||
Expect(images).To(ContainElement(MatchRegexp(`^quay\.io/libpod/busybox\s+latest\s`)))
|
||||
Expect(images).To(ContainElement(MatchRegexp(`^localhost/foo\s+a\s`)))
|
||||
Expect(images).To(ContainElement(MatchRegexp(`^localhost/foo\s+b\s`)))
|
||||
Expect(images).To(ContainElement(MatchRegexp(`^localhost/foo\s+c\s`)))
|
||||
Expect(images).To(ContainElement(MatchRegexp(`^localhost/bar\s+a\s`)))
|
||||
Expect(images).To(ContainElement(MatchRegexp(`^localhost/bar\s+b\s`)))
|
||||
session = podmanTest.Podman([]string{"images", "-qn"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
|
|
@ -660,7 +661,7 @@ var _ = Describe("Podman pull", func() {
|
|||
|
||||
session := decryptionTestHelper(imgPath)
|
||||
|
||||
Expect(session.LineInOutputContainsTag("localhost/name", "tag")).To(BeTrue())
|
||||
Expect(session.OutputToStringArray()).To(ContainElement(MatchRegexp(`^localhost/name\s+tag\s`)))
|
||||
})
|
||||
|
||||
It("From local registry", func() {
|
||||
|
|
@ -690,7 +691,7 @@ var _ = Describe("Podman pull", func() {
|
|||
|
||||
session = decryptionTestHelper(imgPath)
|
||||
|
||||
Expect(session.LineInOutputContainsTag(imgPath, "latest")).To(BeTrue())
|
||||
Expect(session.OutputToStringArray()).To(ContainElement(MatchRegexp("^" + regexp.QuoteMeta(imgPath) + `\s+latest\s`)))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -36,19 +36,6 @@ var _ = Describe("PodmanSession test", func() {
|
|||
Expect(session.ErrorToStringArray()).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("Test LineInOutputContainsTag", func() {
|
||||
session = StartFakeCmdSession([]string{"HEAD LINE", "docker.io/library/busybox latest e1ddd7948a1c 5 weeks ago 1.38MB"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.LineInOutputContainsTag("docker.io/library/busybox", "latest")).To(BeTrue())
|
||||
Expect(session.LineInOutputContainsTag("busybox", "latest")).To(Not(BeTrue()))
|
||||
})
|
||||
|
||||
It("Test LineInOutputContainsTag with empty output", func() {
|
||||
session = StartFakeCmdSession([]string{})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.LineInOutputContainsTag("docker.io/library/busybox", "latest")).To(Not(BeTrue()))
|
||||
})
|
||||
|
||||
It("Test IsJSONOutputValid", func() {
|
||||
session = StartFakeCmdSession([]string{`{"page":1,"fruits":["apple","peach","pear"]}`})
|
||||
session.WaitWithDefaultTimeout()
|
||||
|
|
|
|||
|
|
@ -279,14 +279,6 @@ func (s *PodmanSession) ErrorToStringArray() []string {
|
|||
return results
|
||||
}
|
||||
|
||||
// LineInOutputContainsTag returns true if a line in the
|
||||
// session's output contains the repo-tag pair as returned
|
||||
// by podman-images(1).
|
||||
func (s *PodmanSession) LineInOutputContainsTag(repo, tag string) bool {
|
||||
tagMap := tagOutputToMap(s.OutputToStringArray())
|
||||
return tagMap[repo][tag]
|
||||
}
|
||||
|
||||
// IsJSONOutputValid attempts to unmarshal the session buffer
|
||||
// and if successful, returns true, else false
|
||||
func (s *PodmanSession) IsJSONOutputValid() bool {
|
||||
|
|
@ -343,38 +335,6 @@ func StartSystemExec(command string, args []string) *PodmanSession {
|
|||
return &PodmanSession{session}
|
||||
}
|
||||
|
||||
// tagOutputToMap parses each string in imagesOutput and returns
|
||||
// a map whose key is a repo, and value is another map whose keys
|
||||
// are the tags found for that repo. Notice, the first array item will
|
||||
// be skipped as it's considered to be the header.
|
||||
func tagOutputToMap(imagesOutput []string) map[string]map[string]bool {
|
||||
m := make(map[string]map[string]bool)
|
||||
// imagesOutput[1:] panics (slice bounds out of range) when imagesOutput
|
||||
// is empty, since there is no header line to skip in that case.
|
||||
if len(imagesOutput) == 0 {
|
||||
return m
|
||||
}
|
||||
// iterate over output but skip the header
|
||||
for _, i := range imagesOutput[1:] {
|
||||
tmp := []string{}
|
||||
for x := range strings.SplitSeq(i, " ") {
|
||||
if x != "" {
|
||||
tmp = append(tmp, x)
|
||||
}
|
||||
}
|
||||
// podman-images(1) return a list like output
|
||||
// in the format of "Repository Tag [...]"
|
||||
if len(tmp) < 2 {
|
||||
continue
|
||||
}
|
||||
if m[tmp[0]] == nil {
|
||||
m[tmp[0]] = map[string]bool{}
|
||||
}
|
||||
m[tmp[0]][tmp[1]] = true
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// GetHostDistributionInfo returns a struct with its distribution Name and version
|
||||
func GetHostDistributionInfo() HostOS {
|
||||
f, err := os.Open(OSReleasePath)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue