(t *testing.T)
| 30 | } |
| 31 | |
| 32 | func TestImageRemove(t *testing.T) { |
| 33 | const expectedURL = "/images/image_id" |
| 34 | removeCases := []struct { |
| 35 | force bool |
| 36 | pruneChildren bool |
| 37 | platform *ocispec.Platform |
| 38 | expectedQueryParams map[string]string |
| 39 | }{ |
| 40 | { |
| 41 | force: false, |
| 42 | pruneChildren: false, |
| 43 | expectedQueryParams: map[string]string{ |
| 44 | "force": "", |
| 45 | "noprune": "1", |
| 46 | }, |
| 47 | }, |
| 48 | { |
| 49 | force: true, |
| 50 | pruneChildren: true, |
| 51 | expectedQueryParams: map[string]string{ |
| 52 | "force": "1", |
| 53 | "noprune": "", |
| 54 | }, |
| 55 | }, |
| 56 | { |
| 57 | platform: &ocispec.Platform{ |
| 58 | Architecture: "amd64", |
| 59 | OS: "linux", |
| 60 | }, |
| 61 | expectedQueryParams: map[string]string{ |
| 62 | "platforms": `{"architecture":"amd64","os":"linux"}`, |
| 63 | }, |
| 64 | }, |
| 65 | } |
| 66 | for _, removeCase := range removeCases { |
| 67 | client, err := New(WithMockClient(func(req *http.Request) (*http.Response, error) { |
| 68 | if err := assertRequest(req, http.MethodDelete, expectedURL); err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | query := req.URL.Query() |
| 72 | for key, expected := range removeCase.expectedQueryParams { |
| 73 | actual := query.Get(key) |
| 74 | if actual != expected { |
| 75 | return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) |
| 76 | } |
| 77 | } |
| 78 | return mockJSONResponse(http.StatusOK, nil, []image.DeleteResponse{ |
| 79 | {Untagged: "image_id1"}, |
| 80 | {Deleted: "image_id"}, |
| 81 | })(req) |
| 82 | })) |
| 83 | assert.NilError(t, err) |
| 84 | |
| 85 | opts := ImageRemoveOptions{ |
| 86 | Force: removeCase.force, |
| 87 | PruneChildren: removeCase.pruneChildren, |
| 88 | } |
| 89 | if removeCase.platform != nil { |
nothing calls this directly
no test coverage detected
searching dependent graphs…