mirror of
https://github.com/containers/podman.git
synced 2025-09-27 08:43: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 {
|
func generateImagesOutput(ctx context.Context, images []*adapter.ContainerImage, opts imagesOptions) error {
|
||||||
templateMap := GenImageOutputMap()
|
templateMap := GenImageOutputMap()
|
||||||
if len(images) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
var out formats.Writer
|
var out formats.Writer
|
||||||
|
|
||||||
switch opts.format {
|
switch opts.format {
|
||||||
case formats.JSONString:
|
case formats.JSONString:
|
||||||
|
// If 0 images are present, print nothing for JSON
|
||||||
|
if len(images) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
imagesOutput := getImagesJSONOutput(ctx, images)
|
imagesOutput := getImagesJSONOutput(ctx, images)
|
||||||
out = formats.JSONStructArray{Output: imagesToGeneric([]imagesTemplateParams{}, imagesOutput)}
|
out = formats.JSONStructArray{Output: imagesToGeneric([]imagesTemplateParams{}, imagesOutput)}
|
||||||
default:
|
default:
|
||||||
|
@ -43,6 +43,17 @@ var _ = Describe("Podman images", func() {
|
|||||||
Expect(session.LineInOuputStartsWith("docker.io/library/busybox")).To(BeTrue())
|
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() {
|
It("podman image List", func() {
|
||||||
session := podmanTest.Podman([]string{"image", "list"})
|
session := podmanTest.Podman([]string{"image", "list"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
@ -82,7 +82,7 @@ var _ = Describe("Podman rm", func() {
|
|||||||
prune.WaitWithDefaultTimeout()
|
prune.WaitWithDefaultTimeout()
|
||||||
Expect(prune.ExitCode()).To(Equal(0))
|
Expect(prune.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
images := podmanTest.Podman([]string{"images", "-a"})
|
images := podmanTest.Podman([]string{"images", "-aq"})
|
||||||
images.WaitWithDefaultTimeout()
|
images.WaitWithDefaultTimeout()
|
||||||
// all images are unused, so they all should be deleted!
|
// all images are unused, so they all should be deleted!
|
||||||
Expect(len(images.OutputToStringArray())).To(Equal(0))
|
Expect(len(images.OutputToStringArray())).To(Equal(0))
|
||||||
@ -95,7 +95,7 @@ var _ = Describe("Podman rm", func() {
|
|||||||
prune.WaitWithDefaultTimeout()
|
prune.WaitWithDefaultTimeout()
|
||||||
Expect(prune.ExitCode()).To(Equal(0))
|
Expect(prune.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
images := podmanTest.Podman([]string{"images", "-a"})
|
images := podmanTest.Podman([]string{"images", "-aq"})
|
||||||
images.WaitWithDefaultTimeout()
|
images.WaitWithDefaultTimeout()
|
||||||
// all images are unused, so they all should be deleted!
|
// all images are unused, so they all should be deleted!
|
||||||
Expect(len(images.OutputToStringArray())).To(Equal(0))
|
Expect(len(images.OutputToStringArray())).To(Equal(0))
|
||||||
|
@ -270,7 +270,7 @@ RUN find $LOCAL
|
|||||||
fmt.Println(session.OutputToString())
|
fmt.Println(session.OutputToString())
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
images := podmanTest.Podman([]string{"images", "--all"})
|
images := podmanTest.Podman([]string{"images", "-aq"})
|
||||||
images.WaitWithDefaultTimeout()
|
images.WaitWithDefaultTimeout()
|
||||||
Expect(images.ExitCode()).To(Equal(0))
|
Expect(images.ExitCode()).To(Equal(0))
|
||||||
Expect(len(images.OutputToStringArray())).To(Equal(0))
|
Expect(len(images.OutputToStringArray())).To(Equal(0))
|
||||||
|
Reference in New Issue
Block a user