зеркало из https://github.com/docker/engine-api.git
Merge pull request #378 from allencloud/add-ContainerUpdateResponse-in-update-api
add ContainerUpdateResponse in update api
This commit is contained in:
Коммит
9140772fe5
|
@ -1,13 +1,23 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/docker/engine-api/types"
|
||||
"github.com/docker/engine-api/types/container"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// ContainerUpdate updates resources of a container
|
||||
func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) error {
|
||||
resp, err := cli.post(ctx, "/containers/"+containerID+"/update", nil, updateConfig, nil)
|
||||
ensureReaderClosed(resp)
|
||||
return err
|
||||
func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) (types.ContainerUpdateResponse, error) {
|
||||
var response types.ContainerUpdateResponse
|
||||
serverResp, err := cli.post(ctx, "/containers/"+containerID+"/update", nil, updateConfig, nil)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
|
||||
err = json.NewDecoder(serverResp.body).Decode(&response)
|
||||
|
||||
ensureReaderClosed(serverResp)
|
||||
return response, err
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@ package client
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/engine-api/types"
|
||||
"github.com/docker/engine-api/types/container"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
@ -16,7 +18,7 @@ func TestContainerUpdateError(t *testing.T) {
|
|||
client := &Client{
|
||||
transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
err := client.ContainerUpdate(context.Background(), "nothing", container.UpdateConfig{})
|
||||
_, err := client.ContainerUpdate(context.Background(), "nothing", container.UpdateConfig{})
|
||||
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
||||
t.Fatalf("expected a Server Error, got %v", err)
|
||||
}
|
||||
|
@ -24,19 +26,26 @@ func TestContainerUpdateError(t *testing.T) {
|
|||
|
||||
func TestContainerUpdate(t *testing.T) {
|
||||
expectedURL := "/containers/container_id/update"
|
||||
|
||||
client := &Client{
|
||||
transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
||||
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
||||
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
||||
}
|
||||
|
||||
b, err := json.Marshal(types.ContainerUpdateResponse{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),
|
||||
Body: ioutil.NopCloser(bytes.NewReader(b)),
|
||||
}, nil
|
||||
}),
|
||||
}
|
||||
|
||||
err := client.ContainerUpdate(context.Background(), "container_id", container.UpdateConfig{
|
||||
_, err := client.ContainerUpdate(context.Background(), "container_id", container.UpdateConfig{
|
||||
Resources: container.Resources{
|
||||
CPUPeriod: 1,
|
||||
},
|
||||
|
|
|
@ -56,7 +56,7 @@ type ContainerAPIClient interface {
|
|||
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
|
||||
ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (types.ContainerUpdateResponse, error)
|
||||
ContainerWait(ctx context.Context, container string) (int, error)
|
||||
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
|
||||
CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
|
||||
|
|
Загрузка…
Ссылка в новой задаче