MCPcopy
hub / github.com/moby/moby / TestImageSave

Function TestImageSave

client/image_save_test.go:23–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21}
22
23func TestImageSave(t *testing.T) {
24 const (
25 expectedURL = "/images/get"
26 expectedOutput = "outputBody"
27 )
28 tests := []struct {
29 doc string
30 options []ImageSaveOption
31 expectedQueryParams url.Values
32 }{
33 {
34 doc: "no platform",
35 expectedQueryParams: url.Values{
36 "names": {"image_id1", "image_id2"},
37 },
38 },
39 {
40 doc: "platform",
41 options: []ImageSaveOption{
42 ImageSaveWithPlatforms(ocispec.Platform{Architecture: "arm64", OS: "linux", Variant: "v8"}),
43 },
44 expectedQueryParams: url.Values{
45 "names": {"image_id1", "image_id2"},
46 "platform": {`{"architecture":"arm64","os":"linux","variant":"v8"}`},
47 },
48 },
49 {
50 doc: "multiple platforms",
51 options: []ImageSaveOption{
52 ImageSaveWithPlatforms(
53 ocispec.Platform{Architecture: "arm64", OS: "linux", Variant: "v8"},
54 ocispec.Platform{Architecture: "amd64", OS: "linux"},
55 ),
56 },
57 expectedQueryParams: url.Values{
58 "names": {"image_id1", "image_id2"},
59 "platform": {`{"architecture":"arm64","os":"linux","variant":"v8"}`, `{"architecture":"amd64","os":"linux"}`},
60 },
61 },
62 }
63 for _, tc := range tests {
64 t.Run(tc.doc, func(t *testing.T) {
65 client, err := New(WithMockClient(func(req *http.Request) (*http.Response, error) {
66 assert.Check(t, assertRequest(req, http.MethodGet, expectedURL))
67 assert.Check(t, is.DeepEqual(req.URL.Query(), tc.expectedQueryParams))
68 return mockResponse(http.StatusOK, nil, expectedOutput)(req)
69 }))
70 assert.NilError(t, err)
71 resp, err := client.ImageSave(t.Context(), []string{"image_id1", "image_id2"}, tc.options...)
72 assert.NilError(t, err)
73 defer func() {
74 assert.NilError(t, resp.Close())
75 }()
76
77 body, err := io.ReadAll(resp)
78 assert.NilError(t, err)
79 assert.Check(t, is.Equal(string(body), expectedOutput))
80 })

Callers

nothing calls this directly

Calls 11

ImageSaveWithPlatformsFunction · 0.85
WithMockClientFunction · 0.85
assertRequestFunction · 0.85
mockResponseFunction · 0.85
CheckMethod · 0.80
EqualMethod · 0.80
NewFunction · 0.70
RunMethod · 0.65
ImageSaveMethod · 0.65
ContextMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…