Skip to content

Commit 797f1ea

Browse files
Merge pull request #9349 from baude/v3unixts
V3unixts [3.0 Backports]
2 parents 0010592 + f36d860 commit 797f1ea

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

cmd/podman/containers/ps.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,19 @@ func checkFlags(c *cobra.Command) error {
142142
}
143143

144144
func jsonOut(responses []entities.ListContainer) error {
145-
r := make([]entities.ListContainer, 0)
145+
type jsonFormat struct {
146+
entities.ListContainer
147+
Created int64
148+
}
149+
r := make([]jsonFormat, 0)
146150
for _, con := range responses {
147151
con.CreatedAt = units.HumanDuration(time.Since(con.Created)) + " ago"
148152
con.Status = psReporter{con}.Status()
149-
r = append(r, con)
153+
jf := jsonFormat{
154+
ListContainer: con,
155+
Created: con.Created.Unix(),
156+
}
157+
r = append(r, jf)
150158
}
151159
b, err := json.MarshalIndent(r, "", " ")
152160
if err != nil {

test/e2e/ps_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"regexp"
77
"sort"
8+
"strconv"
89
"strings"
910

1011
. "github.com/containers/podman/v2/test/utils"
@@ -210,6 +211,22 @@ var _ = Describe("Podman ps", func() {
210211
Expect(result.IsJSONOutputValid()).To(BeTrue())
211212
})
212213

214+
It("podman ps json format Created field is int64", func() {
215+
session := podmanTest.RunTopContainer("test1")
216+
session.WaitWithDefaultTimeout()
217+
Expect(session.ExitCode()).To(Equal(0))
218+
219+
result := podmanTest.Podman([]string{"ps", "--format", "json"})
220+
result.WaitWithDefaultTimeout()
221+
Expect(result.ExitCode()).To(Equal(0))
222+
223+
// Make sure Created field is an int64
224+
created, err := result.jq(".[0].Created")
225+
Expect(err).To(BeNil())
226+
_, err = strconv.ParseInt(created, 10, 64)
227+
Expect(err).To(BeNil())
228+
})
229+
213230
It("podman ps print a human-readable `Status` with json format", func() {
214231
_, ec, _ := podmanTest.RunLsContainer("test1")
215232
Expect(ec).To(Equal(0))

0 commit comments

Comments
 (0)