Datasets:
File size: 6,698 Bytes
0e239c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | 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) {
|