| 143 | } |
| 144 | |
| 145 | func 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. |
| 176 | func StartBootstrapServer(t *testing.T) (*ServerContext, func()) { |