MCPcopy
hub / github.com/moby/moby / makeTestRoundTripper

Function makeTestRoundTripper

client/client_mock_test.go:69–95  ·  view source on GitHub ↗

makeTestRoundTripper makes sure the response has a Body, using [http.NoBody] if none is present, and returns it as a testRoundTripper. If withDefaults is set, it also mocks the "/_ping" endpoint and sets default headers as returned by the daemon.

(f func(req *http.Request) (*http.Response, error))

Source from the content-addressed store, hash-verified

67// it also mocks the "/_ping" endpoint and sets default headers as returned
68// by the daemon.
69func makeTestRoundTripper(f func(req *http.Request) (*http.Response, error)) testRoundTripper {
70 return func(req *http.Request) (*http.Response, error) {
71 if req.URL.Path == "/_ping" {
72 return mockPingResponse(http.StatusOK, PingResult{
73 APIVersion: MaxAPIVersion,
74 OSType: runtime.GOOS,
75 Experimental: true,
76 BuilderVersion: build.BuilderBuildKit,
77 SwarmStatus: &SwarmStatus{
78 NodeState: swarm.LocalNodeStateActive,
79 ControlAvailable: true,
80 },
81 })(req)
82 }
83 resp, err := f(req)
84 if resp != nil {
85 if resp.Body == nil {
86 resp.Body = http.NoBody
87 }
88 if resp.Request == nil {
89 resp.Request = req
90 }
91 }
92 applyDefaultHeaders(resp)
93 return resp, err
94 }
95}
96
97// applyDefaultHeaders mocks the headers set by the daemon's VersionMiddleware.
98func applyDefaultHeaders(resp *http.Response) {

Callers 1

WithMockClientFunction · 0.85

Calls 2

mockPingResponseFunction · 0.85
applyDefaultHeadersFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…