MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / doBootstrapRequest

Function doBootstrapRequest

rest/utilities_testing_bootstrap.go:145–173  ·  view source on GitHub ↗
(t *testing.T, sc *ServerContext, method, path, body string, headers map[string]string, server serverType)

Source from the content-addressed store, hash-verified

143}
144
145func doBootstrapRequest(t *testing.T, sc *ServerContext, method, path, body string, headers map[string]string, server serverType) boostrapResponse {
146 host := "http://" + mustGetServerAddr(t, sc, server)
147 url := host + path
148
149 buf := bytes.NewBufferString(body)
150 req, err := http.NewRequest(method, url, buf)
151 require.NoError(t, err)
152
153 for headerName, headerVal := range headers {
154 req.Header.Set(headerName, headerVal)
155 }
156
157 resp, err := http.DefaultClient.Do(req)
158 require.NoError(t, err)
159
160 defer func() {
161 assert.NoError(t, resp.Body.Close())
162 }()
163
164 rBody, err := io.ReadAll(resp.Body)
165 require.NoError(t, err)
166
167 return boostrapResponse{
168 t: t,
169 Body: string(rBody),
170 url: method + " " + url,
171 response: resp,
172 }
173}
174
175// StartBootstrapServer starts a server with a default bootstrap config, and returns a function to close the server. This differs from RestTester in that this is running a real server listening on random port. Prefer use of RestTester for more ergnomic APIs.
176func StartBootstrapServer(t *testing.T) (*ServerContext, func()) {

Callers 1

TestBootstrapPingAPIFunction · 0.85

Calls 3

mustGetServerAddrFunction · 0.85
CloseMethod · 0.65
SetMethod · 0.45

Tested by 1

TestBootstrapPingAPIFunction · 0.68