Skip to content

Commit

Permalink
Merge pull request containers#9349 from baude/v3unixts
Browse files Browse the repository at this point in the history
V3unixts [3.0 Backports]
  • Loading branch information
openshift-merge-robot authored Feb 13, 2021
2 parents 0010592 + f36d860 commit 797f1ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Unix(),
}
r = append(r, jf)
}
b, err := json.MarshalIndent(r, "", " ")
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"regexp"
"sort"
"strconv"
"strings"

. "github.com/containers/podman/v2/test/utils"
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 797f1ea

Please sign in to comment.