Wrap response errors for container copy methods.

This allows IsErrNotFound and IsErrNotImplemented to work as intended.

Signed-off-by: Emil Davtyan <emil2k@gmail.com>
This commit is contained in:
Emil Davtyan
2018-01-11 13:15:46 +01:00
parent cc79c6c7da
commit 44369bdd65
2 changed files with 38 additions and 8 deletions

View File

@@ -25,6 +25,16 @@ func TestContainerStatPathError(t *testing.T) {
}
}
func TestContainerStatPathNotFoundError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusNotFound, "Not found")),
}
_, err := client.ContainerStatPath(context.Background(), "container_id", "path")
if !IsErrNotFound(err) {
t.Fatalf("expected a not found error, got %v", err)
}
}
func TestContainerStatPathNoHeaderError(t *testing.T) {
client := &Client{
client: newMockClient(func(req *http.Request) (*http.Response, error) {
@@ -95,6 +105,16 @@ func TestCopyToContainerError(t *testing.T) {
}
}
func TestCopyToContainerNotFoundError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusNotFound, "Not found")),
}
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
if !IsErrNotFound(err) {
t.Fatalf("expected a not found error, got %v", err)
}
}
func TestCopyToContainerNotStatusOKError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusNoContent, "No content")),
@@ -161,6 +181,16 @@ func TestCopyFromContainerError(t *testing.T) {
}
}
func TestCopyFromContainerNotFoundError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusNotFound, "Not found")),
}
_, _, err := client.CopyFromContainer(context.Background(), "container_id", "path/to/file")
if !IsErrNotFound(err) {
t.Fatalf("expected a not found error, got %v", err)
}
}
func TestCopyFromContainerNotStatusOKError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusNoContent, "No content")),