MCPcopy
hub / github.com/moby/moby / TestImageRemove

Function TestImageRemove

client/image_remove_test.go:32–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func 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 {

Callers

nothing calls this directly

Calls 10

WithMockClientFunction · 0.85
assertRequestFunction · 0.85
mockJSONResponseFunction · 0.85
ErrorfMethod · 0.80
CheckMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
ImageRemoveMethod · 0.65
ContextMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…