Silin-Chen's picture
CrossSWE-Bench: current 171-instance release
0e239c6
Raw History Blame Contribute Delete
6.7 kB
diff --git a/client/image_load.go b/client/image_load.go
index c52fd3f452..fab3098460 100644
--- a/client/image_load.go
+++ b/client/image_load.go
@@ -47,36 +47,13 @@ func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...I
}
return ImageLoadResult{
body: resp.Body,
- JSON: resp.Header.Get("Content-Type") == "application/json",
}, nil
}
// ImageLoadResult returns information to the client about a load process.
-//
-// TODO(thaJeztah): remove this type, and just use an io.ReadCloser
-//
-// This type was added in https://github.com/moby/moby/pull/18878, related
-// to https://github.com/moby/moby/issues/19177;
-//
-// Make docker load to output json when the response content type is json
-// Swarm hijacks the response from docker load and returns JSON rather
-// than plain text like the Engine does. This makes the API library to return
-// information to figure that out.
-//
-// However the "load" endpoint unconditionally returns JSON;
-// https://github.com/moby/moby/blob/7b9d2ef6e5518a3d3f3cc418459f8df786cfbbd1/api/server/router/image/image_routes.go#L248-L255
-//
-// PR https://github.com/moby/moby/pull/21959 made the response-type depend
-// on whether "quiet" was set, but this logic got changed in a follow-up
-// https://github.com/moby/moby/pull/25557, which made the JSON response-type
-// unconditionally, but the output produced depend on whether"quiet" was set.
-//
-// We should deprecated the "quiet" option, as it's really a client
-// responsibility.
type ImageLoadResult struct {
// Body must be closed to avoid a resource leak
body io.ReadCloser
- JSON bool
}
func (r ImageLoadResult) Read(p []byte) (n int, err error) {
diff --git a/client/image_load_test.go b/client/image_load_test.go
index 708f47458e..d2a774fba4 100644
--- a/client/image_load_test.go
+++ b/client/image_load_test.go
@@ -3,6 +3,7 @@ package client
import (
"bytes"
"context"
+ "encoding/json"
"io"
"net/http"
"net/url"
@@ -27,52 +28,41 @@ func TestImageLoad(t *testing.T) {
expectedURL = "/images/load"
expectedContentType = "application/x-tar"
expectedInput = "inputBody"
- expectedOutput = "outputBody"
+ expectedOutput = `{"stream":"Loaded image: busybox:latest\n"}`
)
tests := []struct {
- doc string
- quiet bool
- platforms []ocispec.Platform
- responseContentType string
- expectedResponseJSON bool
- expectedQueryParams url.Values
+ doc string
+ quiet bool
+ platforms []ocispec.Platform
+ expectedQueryParams url.Values
}{
{
- doc: "plain-text",
- quiet: false,
- responseContentType: "text/plain",
- expectedResponseJSON: false,
+ doc: "no options",
expectedQueryParams: url.Values{
"quiet": {"0"},
},
},
{
- doc: "json quiet",
- quiet: true,
- responseContentType: "application/json",
- expectedResponseJSON: true,
+ doc: "quiet",
+ quiet: true,
expectedQueryParams: url.Values{
"quiet": {"1"},
},
},
{
- doc: "json with platform",
- platforms: []ocispec.Platform{{Architecture: "arm64", OS: "linux", Variant: "v8"}},
- responseContentType: "application/json",
- expectedResponseJSON: true,
+ doc: "with platform",
+ platforms: []ocispec.Platform{{Architecture: "arm64", OS: "linux", Variant: "v8"}},
expectedQueryParams: url.Values{
"platform": {`{"architecture":"arm64","os":"linux","variant":"v8"}`},
"quiet": {"0"},
},
},
{
- doc: "json with multiple platforms",
+ doc: "multiple platforms",
platforms: []ocispec.Platform{
{Architecture: "arm64", OS: "linux", Variant: "v8"},
{Architecture: "amd64", OS: "linux"},
},
- responseContentType: "application/json",
- expectedResponseJSON: true,
expectedQueryParams: url.Values{
"platform": {`{"architecture":"arm64","os":"linux","variant":"v8"}`, `{"architecture":"amd64","os":"linux"}`},
"quiet": {"0"},
@@ -86,8 +76,7 @@ func TestImageLoad(t *testing.T) {
assert.Check(t, is.Equal(req.Header.Get("Content-Type"), expectedContentType))
assert.Check(t, is.DeepEqual(req.URL.Query(), tc.expectedQueryParams))
- hdr := http.Header{"Content-Type": []string{tc.responseContentType}}
- return mockResponse(http.StatusOK, hdr, expectedOutput)(req)
+ return mockJSONResponse(http.StatusOK, nil, json.RawMessage(expectedOutput))(req)
}))
assert.NilError(t, err)
@@ -97,7 +86,6 @@ func TestImageLoad(t *testing.T) {
ImageLoadWithPlatforms(tc.platforms...),
)
assert.NilError(t, err)
- assert.Check(t, is.Equal(imageLoadResponse.JSON, tc.expectedResponseJSON))
body, err := io.ReadAll(imageLoadResponse)
assert.NilError(t, err)
diff --git a/vendor/github.com/moby/moby/client/image_load.go b/vendor/github.com/moby/moby/client/image_load.go
index c52fd3f452..fab3098460 100644
--- a/vendor/github.com/moby/moby/client/image_load.go
+++ b/vendor/github.com/moby/moby/client/image_load.go
@@ -47,36 +47,13 @@ func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...I
}
return ImageLoadResult{
body: resp.Body,
- JSON: resp.Header.Get("Content-Type") == "application/json",
}, nil
}
// ImageLoadResult returns information to the client about a load process.
-//
-// TODO(thaJeztah): remove this type, and just use an io.ReadCloser
-//
-// This type was added in https://github.com/moby/moby/pull/18878, related
-// to https://github.com/moby/moby/issues/19177;
-//
-// Make docker load to output json when the response content type is json
-// Swarm hijacks the response from docker load and returns JSON rather
-// than plain text like the Engine does. This makes the API library to return
-// information to figure that out.
-//
-// However the "load" endpoint unconditionally returns JSON;
-// https://github.com/moby/moby/blob/7b9d2ef6e5518a3d3f3cc418459f8df786cfbbd1/api/server/router/image/image_routes.go#L248-L255
-//
-// PR https://github.com/moby/moby/pull/21959 made the response-type depend
-// on whether "quiet" was set, but this logic got changed in a follow-up
-// https://github.com/moby/moby/pull/25557, which made the JSON response-type
-// unconditionally, but the output produced depend on whether"quiet" was set.
-//
-// We should deprecated the "quiet" option, as it's really a client
-// responsibility.
type ImageLoadResult struct {
// Body must be closed to avoid a resource leak
body io.ReadCloser
- JSON bool
}
func (r ImageLoadResult) Read(p []byte) (n int, err error) {