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))
| 67 | // it also mocks the "/_ping" endpoint and sets default headers as returned |
| 68 | // by the daemon. |
| 69 | func 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. |
| 98 | func applyDefaultHeaders(resp *http.Response) { |
no test coverage detected
searching dependent graphs…