MCPcopy
hub / github.com/moby/moby / TestImageInspectWithPlatform

Function TestImageInspectWithPlatform

client/image_inspect_test.go:61–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestImageInspectWithPlatform(t *testing.T) {
62 const expectedURL = "/images/image_id/json"
63 requestedPlatform := &ocispec.Platform{
64 OS: "linux",
65 Architecture: "arm64",
66 }
67
68 expectedPlatform, err := encodePlatform(requestedPlatform)
69 assert.NilError(t, err)
70
71 client, err := New(WithMockClient(func(req *http.Request) (*http.Response, error) {
72 if err := assertRequest(req, http.MethodGet, expectedURL); err != nil {
73 return nil, err
74 }
75
76 // Check if platform parameter is passed correctly
77 platform := req.URL.Query().Get("platform")
78 if platform != expectedPlatform {
79 return nil, fmt.Errorf("Expected platform '%s', got '%s'", expectedPlatform, platform)
80 }
81
82 return mockJSONResponse(http.StatusOK, nil, image.InspectResponse{
83 ID: "image_id",
84 Architecture: "arm64",
85 Os: "linux",
86 })(req)
87 }))
88 assert.NilError(t, err)
89
90 imageInspect, err := client.ImageInspect(t.Context(), "image_id", ImageInspectWithPlatform(requestedPlatform))
91 assert.NilError(t, err)
92 assert.Check(t, is.Equal(imageInspect.ID, "image_id"))
93 assert.Check(t, is.Equal(imageInspect.Architecture, "arm64"))
94 assert.Check(t, is.Equal(imageInspect.Os, "linux"))
95}

Callers

nothing calls this directly

Calls 12

encodePlatformFunction · 0.85
WithMockClientFunction · 0.85
assertRequestFunction · 0.85
mockJSONResponseFunction · 0.85
ImageInspectWithPlatformFunction · 0.85
ErrorfMethod · 0.80
CheckMethod · 0.80
EqualMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
ImageInspectMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…