aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2021-02-11 09:23:49 -0600
committerbaude <bbaude@redhat.com>2021-02-11 09:38:54 -0600
commit5f999b6bcda79538cb1033503acd4c25615bd43b (patch)
tree08a1d0014901c3233d5721c70de998d76538c03f
parentafe4ce6b1ce6a5ba21472f51defd243bdd7750b3 (diff)
downloadpodman-5f999b6bcda79538cb1033503acd4c25615bd43b.tar.gz
podman-5f999b6bcda79538cb1033503acd4c25615bd43b.tar.bz2
podman-5f999b6bcda79538cb1033503acd4c25615bd43b.zip
container ps json format miscue
when printing out json format, we mistakenly changed the Created field output to be a time.time in a different commit. This allows for override of the Created field to be a unix ts as type int64. Fixes: #9315 Signed-off-by: baude <bbaude@redhat.com>
-rw-r--r--cmd/podman/containers/ps.go12
-rw-r--r--test/e2e/ps_test.go17
2 files changed, 27 insertions, 2 deletions
diff --git a/cmd/podman/containers/ps.go b/cmd/podman/containers/ps.go
index 31f44d92f..c9dda4db6 100644
--- a/cmd/podman/containers/ps.go
+++ b/cmd/podman/containers/ps.go
@@ -142,11 +142,19 @@ func checkFlags(c *cobra.Command) error {
}
func jsonOut(responses []entities.ListContainer) error {
- r := make([]entities.ListContainer, 0)
+ type jsonFormat struct {
+ entities.ListContainer
+ Created int64
+ }
+ r := make([]jsonFormat, 0)
for _, con := range responses {
con.CreatedAt = units.HumanDuration(time.Since(con.Created)) + " ago"
con.Status = psReporter{con}.Status()
- r = append(r, con)
+ jf := jsonFormat{
+ ListContainer: con,
+ Created: con.Created.UnixNano(),
+ }
+ r = append(r, jf)
}
b, err := json.MarshalIndent(r, "", " ")
if err != nil {
diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go
index db3f7a36b..225bd538e 100644
--- a/test/e2e/ps_test.go
+++ b/test/e2e/ps_test.go
@@ -5,6 +5,7 @@ import (
"os"
"regexp"
"sort"
+ "strconv"
"strings"
. "github.com/containers/podman/v2/test/utils"
@@ -210,6 +211,22 @@ var _ = Describe("Podman ps", func() {
Expect(result.IsJSONOutputValid()).To(BeTrue())
})
+ It("podman ps json format Created field is int64", func() {
+ session := podmanTest.RunTopContainer("test1")
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ result := podmanTest.Podman([]string{"ps", "--format", "json"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+
+ // Make sure Created field is an int64
+ created, err := result.jq(".[0].Created")
+ Expect(err).To(BeNil())
+ _, err = strconv.ParseInt(created, 10, 64)
+ Expect(err).To(BeNil())
+ })
+
It("podman ps print a human-readable `Status` with json format", func() {
_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))