mirror of
https://github.com/containers/podman.git
synced 2025-07-15 03:02:52 +08:00
Print header for 'podman images' even with no images
Fixes #2877 Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
@ -318,13 +318,14 @@ func getImagesJSONOutput(ctx context.Context, images []*adapter.ContainerImage)
|
||||
|
||||
func generateImagesOutput(ctx context.Context, images []*adapter.ContainerImage, opts imagesOptions) error {
|
||||
templateMap := GenImageOutputMap()
|
||||
if len(images) == 0 {
|
||||
return nil
|
||||
}
|
||||
var out formats.Writer
|
||||
|
||||
switch opts.format {
|
||||
case formats.JSONString:
|
||||
// If 0 images are present, print nothing for JSON
|
||||
if len(images) == 0 {
|
||||
return nil
|
||||
}
|
||||
imagesOutput := getImagesJSONOutput(ctx, images)
|
||||
out = formats.JSONStructArray{Output: imagesToGeneric([]imagesTemplateParams{}, imagesOutput)}
|
||||
default:
|
||||
|
@ -43,6 +43,17 @@ var _ = Describe("Podman images", func() {
|
||||
Expect(session.LineInOuputStartsWith("docker.io/library/busybox")).To(BeTrue())
|
||||
})
|
||||
|
||||
It("podman images with no images prints header", func() {
|
||||
rmi := podmanTest.Podman([]string{"rmi", "-a"})
|
||||
rmi.WaitWithDefaultTimeout()
|
||||
Expect(rmi.ExitCode()).To(Equal(0))
|
||||
|
||||
session := podmanTest.Podman([]string{"images"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(1))
|
||||
})
|
||||
|
||||
It("podman image List", func() {
|
||||
session := podmanTest.Podman([]string{"image", "list"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
|
@ -82,7 +82,7 @@ var _ = Describe("Podman rm", func() {
|
||||
prune.WaitWithDefaultTimeout()
|
||||
Expect(prune.ExitCode()).To(Equal(0))
|
||||
|
||||
images := podmanTest.Podman([]string{"images", "-a"})
|
||||
images := podmanTest.Podman([]string{"images", "-aq"})
|
||||
images.WaitWithDefaultTimeout()
|
||||
// all images are unused, so they all should be deleted!
|
||||
Expect(len(images.OutputToStringArray())).To(Equal(0))
|
||||
@ -95,7 +95,7 @@ var _ = Describe("Podman rm", func() {
|
||||
prune.WaitWithDefaultTimeout()
|
||||
Expect(prune.ExitCode()).To(Equal(0))
|
||||
|
||||
images := podmanTest.Podman([]string{"images", "-a"})
|
||||
images := podmanTest.Podman([]string{"images", "-aq"})
|
||||
images.WaitWithDefaultTimeout()
|
||||
// all images are unused, so they all should be deleted!
|
||||
Expect(len(images.OutputToStringArray())).To(Equal(0))
|
||||
|
@ -270,7 +270,7 @@ RUN find $LOCAL
|
||||
fmt.Println(session.OutputToString())
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
images := podmanTest.Podman([]string{"images", "--all"})
|
||||
images := podmanTest.Podman([]string{"images", "-aq"})
|
||||
images.WaitWithDefaultTimeout()
|
||||
Expect(images.ExitCode()).To(Equal(0))
|
||||
Expect(len(images.OutputToStringArray())).To(Equal(0))
|
||||
|
Reference in New Issue
Block a user