From 48de0cd4b6b1cfdb9e9be0d20f975318cd745491 Mon Sep 17 00:00:00 2001 From: Atishyy27 <142108881+Atishyy27@users.noreply.github.com> Date: Sun, 16 Aug 2026 01:42:39 +0530 Subject: [PATCH] Fix ErrorToStringArray handling of empty stderr output strings.Split(output, "\n") on empty output returns [""], not []. so ErrorToStringArray() reported empty stderr as one line of empty output instead of no output, and any caller checking len() got a wrong count. volume_ls_test.go had to carry HaveLen(1) just to tolerate that on empty stderr, updated to BeEmpty() now that the length is actually correct. filter out empty lines when building the result. Signed-off-by: Atishyy27 <142108881+Atishyy27@users.noreply.github.com> --- test/e2e/volume_ls_test.go | 2 +- test/utils/podmansession_test.go | 8 +++++++- test/utils/utils.go | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/e2e/volume_ls_test.go b/test/e2e/volume_ls_test.go index bd574944458..8ff7f31a07c 100644 --- a/test/e2e/volume_ls_test.go +++ b/test/e2e/volume_ls_test.go @@ -21,7 +21,7 @@ var _ = Describe("Podman volume ls", func() { empty := podmanTest.PodmanExitCleanly("volume", "ls") Expect(empty.OutputToString()).To(ContainSubstring("DRIVER")) Expect(empty.OutputToString()).To(ContainSubstring("VOLUME NAME")) - Expect(empty.ErrorToStringArray()).To(HaveLen(1)) + Expect(empty.ErrorToStringArray()).To(BeEmpty()) session := podmanTest.Podman([]string{"volume", "create", "myvol"}) session.WaitWithDefaultTimeout() diff --git a/test/utils/podmansession_test.go b/test/utils/podmansession_test.go index 4c8c33dd79e..75df73237a8 100644 --- a/test/utils/podmansession_test.go +++ b/test/utils/podmansession_test.go @@ -27,7 +27,13 @@ var _ = Describe("PodmanSession test", func() { }) It("Test ErrorToStringArray", func() { - Expect(session.ErrorToStringArray()).To(Equal([]string{"PodmanSession", "test", "Podman Session", ""})) + Expect(session.ErrorToStringArray()).To(Equal([]string{"PodmanSession", "test", "Podman Session"})) + }) + + It("Test ErrorToStringArray with empty output", func() { + session = StartFakeCmdSession([]string{}) + session.WaitWithDefaultTimeout() + Expect(session.ErrorToStringArray()).To(BeEmpty()) }) It("Test GrepString", func() { diff --git a/test/utils/utils.go b/test/utils/utils.go index 9434efdbd35..905901031c1 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -269,8 +269,14 @@ func (s *PodmanSession) ErrorToString() string { // ErrorToStringArray returns the stderr output as a []string // where each array item is a line split by newline func (s *PodmanSession) ErrorToStringArray() []string { + var results []string output := string(s.Err.Contents()) - return strings.Split(output, "\n") + for line := range strings.SplitSeq(output, "\n") { + if line != "" { + results = append(results, line) + } + } + return results } // GrepString takes session output and behaves like grep. it returns a bool