(t *testing.T)
| 21 | } |
| 22 | |
| 23 | func 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 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…