mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-09-19 06:07:50 +00:00
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>
This commit is contained in:
parent
dbae2a4496
commit
ef171ba1b9
3 changed files with 15 additions and 3 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue