File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -142,11 +142,19 @@ func checkFlags(c *cobra.Command) error {
142
142
}
143
143
144
144
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 )
146
150
for _ , con := range responses {
147
151
con .CreatedAt = units .HumanDuration (time .Since (con .Created )) + " ago"
148
152
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 )
150
158
}
151
159
b , err := json .MarshalIndent (r , "" , " " )
152
160
if err != nil {
Original file line number Diff line number Diff line change 5
5
"os"
6
6
"regexp"
7
7
"sort"
8
+ "strconv"
8
9
"strings"
9
10
10
11
. "github.com/containers/podman/v2/test/utils"
@@ -210,6 +211,22 @@ var _ = Describe("Podman ps", func() {
210
211
Expect (result .IsJSONOutputValid ()).To (BeTrue ())
211
212
})
212
213
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
+
213
230
It ("podman ps print a human-readable `Status` with json format" , func () {
214
231
_ , ec , _ := podmanTest .RunLsContainer ("test1" )
215
232
Expect (ec ).To (Equal (0 ))
You can’t perform that action at this time.
0 commit comments