Skip to content

Commit 71504ee

Browse files
committed
Output headers for volume ls when empty
To have consistency with other podman commands like `ps` and `images`, `volume ls` should output its headers even when there are no volumes. Fixes: #25911 Signed-off-by: Brent Baude <[email protected]>
1 parent b849550 commit 71504ee

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

cmd/podman/volumes/list.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,8 @@ func list(cmd *cobra.Command, args []string) error {
8080
return err
8181
}
8282

83-
switch {
84-
case report.IsJSON(cliOpts.Format):
83+
if report.IsJSON(cliOpts.Format) {
8584
return outputJSON(responses)
86-
case len(responses) < 1:
87-
return nil
8885
}
8986
return outputTemplate(cmd, responses)
9087
}

test/e2e/prune_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ var _ = Describe("Podman prune", func() {
377377
session = podmanTest.Podman([]string{"volume", "ls"})
378378
session.WaitWithDefaultTimeout()
379379
Expect(session).Should(ExitCleanly())
380-
Expect(session.OutputToStringArray()).To(BeEmpty())
380+
Expect(session.OutputToStringArray()).To(HaveLen(1))
381381

382382
// One Pod should not be pruned as it was running
383383
Expect(podmanTest.NumberOfPods()).To(Equal(1))

test/e2e/system_reset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var _ = Describe("podman system reset", Serial, func() {
5555
session = podmanTest.Podman([]string{"volume", "ls"})
5656
session.WaitWithDefaultTimeout()
5757
Expect(session).Should(ExitCleanly())
58-
Expect(session.OutputToStringArray()).To(BeEmpty())
58+
Expect(session.OutputToStringArray()).To(HaveLen(1))
5959

6060
session = podmanTest.Podman([]string{"container", "ls", "-q"})
6161
session.WaitWithDefaultTimeout()

test/e2e/volume_ls_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ var _ = Describe("Podman volume ls", func() {
1717
})
1818

1919
It("podman ls volume", func() {
20+
// https://github.com/containers/podman/issues/25911
21+
// Output header for volume ls even when empty
22+
empty := podmanTest.PodmanExitCleanly("volume", "ls")
23+
Expect(empty.OutputToString()).To(ContainSubstring("DRIVER"))
24+
Expect(empty.OutputToString()).To(ContainSubstring("VOLUME NAME"))
25+
Expect(empty.ErrorToStringArray()).To(HaveLen(1))
26+
2027
session := podmanTest.Podman([]string{"volume", "create", "myvol"})
2128
session.WaitWithDefaultTimeout()
2229
Expect(session).Should(ExitCleanly())
@@ -94,7 +101,6 @@ var _ = Describe("Podman volume ls", func() {
94101
session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=foo"})
95102
session.WaitWithDefaultTimeout()
96103
Expect(session).Should(ExitCleanly())
97-
Expect(session.OutputToStringArray()).To(BeEmpty())
98104

99105
session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=bar"})
100106
session.WaitWithDefaultTimeout()
@@ -105,7 +111,6 @@ var _ = Describe("Podman volume ls", func() {
105111
session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=baz"})
106112
session.WaitWithDefaultTimeout()
107113
Expect(session).Should(ExitCleanly())
108-
Expect(session.OutputToStringArray()).To(BeEmpty())
109114
})
110115

111116
It("podman ls volume with --filter until flag", func() {
@@ -121,7 +126,6 @@ var _ = Describe("Podman volume ls", func() {
121126
session = podmanTest.Podman([]string{"volume", "ls", "--filter", "until=50000"})
122127
session.WaitWithDefaultTimeout()
123128
Expect(session).Should(ExitCleanly())
124-
Expect(session.OutputToStringArray()).To(BeEmpty())
125129
})
126130

127131
It("podman volume ls with --filter dangling", func() {
@@ -171,7 +175,6 @@ var _ = Describe("Podman volume ls", func() {
171175
session = podmanTest.Podman([]string{"volume", "ls", "--filter", "name=volumex"})
172176
session.WaitWithDefaultTimeout()
173177
Expect(session).Should(ExitCleanly())
174-
Expect(session.OutputToStringArray()).To(BeEmpty())
175178

176179
session = podmanTest.Podman([]string{"volume", "ls", "--filter", "name=volume1"})
177180
session.WaitWithDefaultTimeout()

test/e2e/volume_prune_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var _ = Describe("Podman volume prune", func() {
6868
session = podmanTest.Podman([]string{"volume", "ls"})
6969
session.WaitWithDefaultTimeout()
7070
Expect(session).Should(ExitCleanly())
71-
Expect(session.OutputToStringArray()).To(BeEmpty())
71+
Expect(session.OutputToStringArray()).To(HaveLen(1))
7272
})
7373

7474
It("podman prune volume --filter", func() {
@@ -163,7 +163,7 @@ var _ = Describe("Podman volume prune", func() {
163163
session = podmanTest.Podman([]string{"volume", "ls"})
164164
session.WaitWithDefaultTimeout()
165165
Expect(session).Should(ExitCleanly())
166-
Expect(session.OutputToStringArray()).To(BeEmpty())
166+
Expect(session.OutputToStringArray()).To(HaveLen(1))
167167
})
168168

169169
It("podman volume prune --filter since/after", func() {

test/e2e/volume_rm_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var _ = Describe("Podman volume rm", func() {
2828
session = podmanTest.Podman([]string{"volume", "ls"})
2929
session.WaitWithDefaultTimeout()
3030
Expect(session).Should(ExitCleanly())
31-
Expect(session.OutputToStringArray()).To(BeEmpty())
31+
Expect(session.OutputToStringArray()).To(HaveLen(1))
3232
})
3333

3434
It("podman volume rm with --force flag", func() {
@@ -48,7 +48,7 @@ var _ = Describe("Podman volume rm", func() {
4848
session = podmanTest.Podman([]string{"volume", "ls"})
4949
session.WaitWithDefaultTimeout()
5050
Expect(session).Should(ExitCleanly())
51-
Expect(session.OutputToStringArray()).To(BeEmpty())
51+
Expect(session.OutputToStringArray()).To(HaveLen(1))
5252
})
5353

5454
It("podman volume remove bogus", func() {
@@ -73,7 +73,7 @@ var _ = Describe("Podman volume rm", func() {
7373
session = podmanTest.Podman([]string{"volume", "ls"})
7474
session.WaitWithDefaultTimeout()
7575
Expect(session).Should(ExitCleanly())
76-
Expect(session.OutputToStringArray()).To(BeEmpty())
76+
Expect(session.OutputToStringArray()).To(HaveLen(1))
7777
})
7878

7979
It("podman volume rm by partial name", func() {
@@ -88,7 +88,7 @@ var _ = Describe("Podman volume rm", func() {
8888
session = podmanTest.Podman([]string{"volume", "ls"})
8989
session.WaitWithDefaultTimeout()
9090
Expect(session).Should(ExitCleanly())
91-
Expect(session.OutputToStringArray()).To(BeEmpty())
91+
Expect(session.OutputToStringArray()).To(HaveLen(1))
9292
})
9393

9494
It("podman volume rm by nonunique partial name", func() {

0 commit comments

Comments
 (0)