MCPcopy Create free account
hub / github.com/coder/coder / sendRequest

Method sendRequest

enterprise/aibridgeproxyd/reload_test.go:201–219  ·  view source on GitHub ↗

sendRequest issues a single POST through the proxy. It returns rather than asserting so callers can branch on whether the host is currently routed (MITM'd to aibridged) or not (tunneled, dial of an unresolvable host fails).

(t *testing.T, targetURL string)

Source from the content-addressed store, hash-verified

199// routed (MITM'd to aibridged) or not (tunneled, dial of an unresolvable
200// host fails).
201func (h *reloadTestHarness) sendRequest(t *testing.T, targetURL string) requestResult {
202 t.Helper()
203
204 ctx, cancel := context.WithTimeout(t.Context(), testutil.WaitShort)
205 defer cancel()
206
207 req, err := http.NewRequestWithContext(ctx, http.MethodPost, targetURL, strings.NewReader(`{}`))
208 require.NoError(t, err)
209 req.Header.Set("Content-Type", "application/json")
210
211 resp, err := h.client.Do(req)
212 if err != nil {
213 return requestResult{err: err}
214 }
215 defer resp.Body.Close()
216 body, err := io.ReadAll(resp.Body)
217 require.NoError(t, err)
218 return requestResult{status: resp.StatusCode, body: string(body)}
219}
220
221// expectRoutedTo asserts the proxy MITM'd the request and forwarded it
222// to aibridged with the expected /api/v2/aibridge/<name>/<path>.

Callers 2

expectRoutedToMethod · 0.95
expectNotRoutedMethod · 0.95

Calls 6

HelperMethod · 0.65
ContextMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
ReadAllMethod · 0.45

Tested by

no test coverage detected