From f7d55d64e7040cdad149684234ea150b0a90cf0e Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 11 Oct 2019 16:48:09 +0200 Subject: container: initialize results list it solves: $ podman ps --format=json null Signed-off-by: Giuseppe Scrivano --- cmd/podman/shared/container.go | 6 ++---- test/e2e/ps_test.go | 7 +++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/podman/shared/container.go b/cmd/podman/shared/container.go index 022377b1f..15bbb46d2 100644 --- a/cmd/podman/shared/container.go +++ b/cmd/podman/shared/container.go @@ -449,10 +449,8 @@ func GetPsContainerOutput(r *libpod.Runtime, opts PsOptions, filters []string, m // PBatch performs batch operations on a container in parallel. It spawns the // number of workers relative to the number of parallel operations desired. func PBatch(containers []*libpod.Container, workers int, opts PsOptions) []PsContainerOutput { - var ( - wg sync.WaitGroup - psResults []PsContainerOutput - ) + var wg sync.WaitGroup + psResults := []PsContainerOutput{} // If the number of containers in question is less than the number of // proposed parallel operations, we shouldnt spawn so many workers. diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go index efcf44f76..34f0692b2 100644 --- a/test/e2e/ps_test.go +++ b/test/e2e/ps_test.go @@ -151,6 +151,13 @@ var _ = Describe("Podman ps", func() { Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0)) }) + It("podman ps with no containers is valid json format", func() { + result := podmanTest.Podman([]string{"ps", "--format", "json"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(result.IsJSONOutputValid()).To(BeTrue()) + }) + It("podman ps namespace flag with json format", func() { _, ec, _ := podmanTest.RunLsContainer("test1") Expect(ec).To(Equal(0)) -- cgit v1.2.3-54-g00ecf