mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-04 12:41:42 +00:00
Format times in inspect command with a template as RFC3339Nano
In 1.6.2 we were decoding inspect API response into interface{}.
time.Time fields were JSON encoded as RFC3339Nano in the response
and when decoded into interface{} they were just strings so the inspect
template treated them as just strings.
From 1.7 we are decoding into types.ContainerJSON and when the template
gets executed it now gets a time.Time and it's formatted as
2015-07-22 05:02:38.091530369 +0000 UTC.
This patch brings back the old behavior by typing time.Time fields
as string so they gets formatted as they were encoded in JSON -- RCF3339Nano
Signed-off-by: Antonio Murdaca <runcom@linux.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/go-check/check"
|
||||
@@ -260,3 +261,28 @@ func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) {
|
||||
c.Fatalf("Expected rw to be false")
|
||||
}
|
||||
}
|
||||
|
||||
// #14947
|
||||
func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *check.C) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
id := strings.TrimSpace(out)
|
||||
startedAt, err := inspectField(id, "State.StartedAt")
|
||||
c.Assert(err, check.IsNil)
|
||||
finishedAt, err := inspectField(id, "State.FinishedAt")
|
||||
c.Assert(err, check.IsNil)
|
||||
created, err := inspectField(id, "Created")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
_, err = time.Parse(time.RFC3339Nano, startedAt)
|
||||
c.Assert(err, check.IsNil)
|
||||
_, err = time.Parse(time.RFC3339Nano, finishedAt)
|
||||
c.Assert(err, check.IsNil)
|
||||
_, err = time.Parse(time.RFC3339Nano, created)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
created, err = inspectField("busybox", "Created")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
_, err = time.Parse(time.RFC3339Nano, created)
|
||||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user