diff --git a/test/e2e/checkpoint_image_test.go b/test/e2e/checkpoint_image_test.go index da18922ea3..9fd23ad99d 100644 --- a/test/e2e/checkpoint_image_test.go +++ b/test/e2e/checkpoint_image_test.go @@ -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}) diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go index b432b29f1d..1be2052a10 100644 --- a/test/e2e/images_test.go +++ b/test/e2e/images_test.go @@ -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()) diff --git a/test/e2e/pull_test.go b/test/e2e/pull_test.go index b7d969e190..1586bbdc68 100644 --- a/test/e2e/pull_test.go +++ b/test/e2e/pull_test.go @@ -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`))) }) }) }) diff --git a/test/utils/podmansession_test.go b/test/utils/podmansession_test.go index 8d954268e6..f2c3eedf1b 100644 --- a/test/utils/podmansession_test.go +++ b/test/utils/podmansession_test.go @@ -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() diff --git a/test/utils/utils.go b/test/utils/utils.go index e12da74924..71d07af32b 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -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)