summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-10-14 19:34:03 +0200
committerGitHub <noreply@github.com>2019-10-14 19:34:03 +0200
commita9190dac36f3f220ddc65ad8295778d40566e61f (patch)
tree115f033086d8837a1801bc73dbe6310d23988348
parent3e45d0730b4a17a91912eb161de30cb88e76bb33 (diff)
parent71410ff0738f69793cd282b2e9c341d56198cd98 (diff)
downloadpodman-a9190dac36f3f220ddc65ad8295778d40566e61f.tar.gz
podman-a9190dac36f3f220ddc65ad8295778d40566e61f.tar.bz2
podman-a9190dac36f3f220ddc65ad8295778d40566e61f.zip
Merge pull request #4245 from giuseppe/images-valid-json
images: empty list is valid json with --format=json
-rw-r--r--cmd/podman/images.go16
-rw-r--r--test/e2e/images_test.go7
2 files changed, 14 insertions, 9 deletions
diff --git a/cmd/podman/images.go b/cmd/podman/images.go
index fe7c89b5c..e363fa3bb 100644
--- a/cmd/podman/images.go
+++ b/cmd/podman/images.go
@@ -216,17 +216,18 @@ func (i imagesOptions) setOutputFormat() string {
}
// imagesToGeneric creates an empty array of interfaces for output
-func imagesToGeneric(templParams []imagesTemplateParams, JSONParams []imagesJSONParams) (genericParams []interface{}) {
+func imagesToGeneric(templParams []imagesTemplateParams, JSONParams []imagesJSONParams) []interface{} {
+ genericParams := []interface{}{}
if len(templParams) > 0 {
for _, v := range templParams {
genericParams = append(genericParams, interface{}(v))
}
- return
+ return genericParams
}
for _, v := range JSONParams {
genericParams = append(genericParams, interface{}(v))
}
- return
+ return genericParams
}
func sortImagesOutput(sortBy string, imagesOutput imagesSorted) imagesSorted {
@@ -309,7 +310,8 @@ func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerIma
}
// getImagesJSONOutput returns the images information in its raw form
-func getImagesJSONOutput(ctx context.Context, images []*adapter.ContainerImage) (imagesOutput []imagesJSONParams) {
+func getImagesJSONOutput(ctx context.Context, images []*adapter.ContainerImage) []imagesJSONParams {
+ imagesOutput := []imagesJSONParams{}
for _, img := range images {
size, err := img.Size(ctx)
if err != nil {
@@ -325,7 +327,7 @@ func getImagesJSONOutput(ctx context.Context, images []*adapter.ContainerImage)
}
imagesOutput = append(imagesOutput, params)
}
- return
+ return imagesOutput
}
// generateImagesOutput generates the images based on the format provided
@@ -336,10 +338,6 @@ func generateImagesOutput(ctx context.Context, images []*adapter.ContainerImage,
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:
diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go
index 8203e4273..e125c62b4 100644
--- a/test/e2e/images_test.go
+++ b/test/e2e/images_test.go
@@ -101,6 +101,13 @@ var _ = Describe("Podman images", func() {
Expect(session.LineInOuputStartsWith("docker.io/library/busybox")).To(BeTrue())
})
+ It("podman empty images list in JSON format", func() {
+ session := podmanTest.Podman([]string{"images", "--format=json", "not-existing-image"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.IsJSONOutputValid()).To(BeTrue())
+ })
+
It("podman images in JSON format", func() {
session := podmanTest.Podman([]string{"images", "--format=json"})
session.WaitWithDefaultTimeout()