Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
opalmer committed Apr 22, 2017
1 parent b1215ee commit 5988bca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
4 changes: 1 addition & 3 deletions container_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ var (
// ErrContainerStillRunning is returned by Finished() if the container
// is still running.
ErrContainerStillRunning = errors.New("container still running")

since = time.Since
)

// ContainerInfo provides a wrapper around information
Expand Down Expand Up @@ -109,7 +107,7 @@ func (c *ContainerInfo) Elapsed() (time.Duration, error) {
finished, err := c.Finished()
if err != nil {
if err == ErrContainerStillRunning {
return since(started), nil
return time.Since(started), nil
}
return time.Second * 0, nil
}
Expand Down
17 changes: 5 additions & 12 deletions container_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *ContainerInfoTest) TestID(c *C) {
func (s *ContainerInfoTest) TestStarted(c *C) {
info := &ContainerInfo{
State: &types.ContainerState{
StartedAt: "0001-01-01T00:00:00Z",
StartedAt: timeNotSet,
},
}
_, err := info.Started()
Expand All @@ -71,19 +71,18 @@ func (s *ContainerInfoTest) TestStarted(c *C) {
now := time.Now()
info = &ContainerInfo{
State: &types.ContainerState{
Running: true,
StartedAt: now.Format(time.RFC3339Nano),
},
}
value, err := info.Started()
c.Assert(err, IsNil)
c.Assert(value, Equals, now)
c.Assert(value.UnixNano(), Equals, now.UnixNano())
}

func (s *ContainerInfoTest) TestFinished(c *C) {
info := &ContainerInfo{
State: &types.ContainerState{
FinishedAt: "0001-01-01T00:00:00Z",
FinishedAt: timeNotSet,
},
}
_, err := info.Finished()
Expand All @@ -97,7 +96,7 @@ func (s *ContainerInfoTest) TestFinished(c *C) {
}
value, err := info.Finished()
c.Assert(err, IsNil)
c.Assert(value, Equals, now)
c.Assert(value.UnixNano(), Equals, now.UnixNano())
}

func (s *ContainerInfoTest) TestElapsed(c *C) {
Expand All @@ -117,18 +116,12 @@ func (s *ContainerInfoTest) TestElapsed(c *C) {
FinishedAt: toValue(time.Date(2017, time.January, 1, 1, 0, 0, 0, time.UTC)),
},
}: time.Hour * 1,
//&ContainerInfo{
// State: &types.ContainerState{
// StartedAt: toValue(time.Date(2017, time.January, 1, 0, 0, 0, 0, time.UTC)),
// FinishedAt: timeNotSet,
// },
//}: time.Hour * 1,
}

for info, expected := range expectations {
value, err := info.Elapsed()
c.Assert(err, IsNil)
c.Assert(value, Equals, expected)
c.Assert(value.Nanoseconds(), Equals, expected.Nanoseconds())
}

}

0 comments on commit 5988bca

Please sign in to comment.