Skip to content
This repository has been archived by the owner on Nov 23, 2019. It is now read-only.

Commit

Permalink
Use time.Duration as type for timeouts
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Dal-Pra <[email protected]>
  • Loading branch information
pdalpra committed Jun 7, 2016
1 parent 2bb28fe commit da7b0e7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
7 changes: 4 additions & 3 deletions client/container_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package client

import (
"net/url"
"strconv"
"time"

timetypes "github.com/docker/engine-api/types/time"
"golang.org/x/net/context"
)

// ContainerRestart stops and starts a container again.
// It makes the daemon to wait for the container to be up again for
// a specific amount of time, given the timeout.
func (cli *Client) ContainerRestart(ctx context.Context, containerID string, timeout int) error {
func (cli *Client) ContainerRestart(ctx context.Context, containerID string, timeout time.Duration) error {
query := url.Values{}
query.Set("t", strconv.Itoa(timeout))
query.Set("t", timetypes.DurationToSecondsString(timeout))
resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil)
ensureReaderClosed(resp)
return err
Expand Down
5 changes: 3 additions & 2 deletions client/container_restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"strings"
"testing"
"time"

"golang.org/x/net/context"
)
Expand All @@ -15,7 +16,7 @@ func TestContainerRestartError(t *testing.T) {
client := &Client{
transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
}
err := client.ContainerRestart(context.Background(), "nothing", 0)
err := client.ContainerRestart(context.Background(), "nothing", 0*time.Second)
if err == nil || err.Error() != "Error response from daemon: Server error" {
t.Fatalf("expected a Server Error, got %v", err)
}
Expand All @@ -39,7 +40,7 @@ func TestContainerRestart(t *testing.T) {
}),
}

err := client.ContainerRestart(context.Background(), "container_id", 100)
err := client.ContainerRestart(context.Background(), "container_id", 100*time.Second)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 4 additions & 3 deletions client/container_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package client

import (
"net/url"
"strconv"
"time"

timetypes "github.com/docker/engine-api/types/time"
"golang.org/x/net/context"
)

// ContainerStop stops a container without terminating the process.
// The process is blocked until the container stops or the timeout expires.
func (cli *Client) ContainerStop(ctx context.Context, containerID string, timeout int) error {
func (cli *Client) ContainerStop(ctx context.Context, containerID string, timeout time.Duration) error {
query := url.Values{}
query.Set("t", strconv.Itoa(timeout))
query.Set("t", timetypes.DurationToSecondsString(timeout))
resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil)
ensureReaderClosed(resp)
return err
Expand Down
5 changes: 3 additions & 2 deletions client/container_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"strings"
"testing"
"time"

"golang.org/x/net/context"
)
Expand All @@ -15,7 +16,7 @@ func TestContainerStopError(t *testing.T) {
client := &Client{
transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
}
err := client.ContainerStop(context.Background(), "nothing", 0)
err := client.ContainerStop(context.Background(), "nothing", 0*time.Second)
if err == nil || err.Error() != "Error response from daemon: Server error" {
t.Fatalf("expected a Server Error, got %v", err)
}
Expand All @@ -39,7 +40,7 @@ func TestContainerStop(t *testing.T) {
}),
}

err := client.ContainerStop(context.Background(), "container_id", 100)
err := client.ContainerStop(context.Background(), "container_id", 100*time.Second)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"io"
"time"

"golang.org/x/net/context"

Expand Down Expand Up @@ -37,11 +38,11 @@ type APIClient interface {
ContainerRemove(ctx context.Context, container string, options types.ContainerRemoveOptions) error
ContainerRename(ctx context.Context, container, newContainerName string) error
ContainerResize(ctx context.Context, container string, options types.ResizeOptions) error
ContainerRestart(ctx context.Context, container string, timeout int) error
ContainerRestart(ctx context.Context, container string, timeout time.Duration) error
ContainerStatPath(ctx context.Context, container, path string) (types.ContainerPathStat, error)
ContainerStats(ctx context.Context, container string, stream bool) (io.ReadCloser, error)
ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error
ContainerStop(ctx context.Context, container string, timeout int) error
ContainerStop(ctx context.Context, container string, timeout time.Duration) error
ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error)
ContainerUnpause(ctx context.Context, container string) error
ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) error
Expand Down

0 comments on commit da7b0e7

Please sign in to comment.