httpRaw issues an HTTP request and returns the raw response without asserting on the status code, so tests can verify 4xx/5xx paths.
(t *testing.T, ctx context.Context, method, socketPath, path string, payload any)
| 259 | // httpRaw issues an HTTP request and returns the raw response without |
| 260 | // asserting on the status code, so tests can verify 4xx/5xx paths. |
| 261 | func httpRaw(t *testing.T, ctx context.Context, method, socketPath, path string, payload any) struct { |
| 262 | StatusCode int |
| 263 | body string |
| 264 | } { |
| 265 | t.Helper() |
| 266 | |
| 267 | var ( |
| 268 | body io.Reader |
| 269 | contentType string |
| 270 | ) |
| 271 | if payload != nil { |
| 272 | buf, err := json.Marshal(payload) |
| 273 | require.NoError(t, err) |
| 274 | body = bytes.NewReader(buf) |
| 275 | contentType = "application/json" |
| 276 | } else { |
| 277 | body = http.NoBody |
| 278 | } |
| 279 | |
| 280 | req, err := http.NewRequestWithContext(ctx, method, "http://_"+path, body) |
| 281 | require.NoError(t, err) |
| 282 | req.Header.Set("Content-Type", contentType) |
| 283 | |
| 284 | client := &http.Client{ |
| 285 | Transport: &http.Transport{ |
| 286 | DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { |
| 287 | var d net.Dialer |
| 288 | return d.DialContext(ctx, "unix", strings.TrimPrefix(socketPath, "unix://")) |
| 289 | }, |
| 290 | }, |
| 291 | } |
| 292 | resp, err := client.Do(req) |
| 293 | require.NoError(t, err) |
| 294 | defer resp.Body.Close() |
| 295 | |
| 296 | buf, err := io.ReadAll(resp.Body) |
| 297 | require.NoError(t, err) |
| 298 | return struct { |
| 299 | StatusCode int |
| 300 | body string |
| 301 | }{StatusCode: resp.StatusCode, body: string(buf)} |
| 302 | } |
| 303 | |
| 304 | func startServerWithStore(t *testing.T, ctx context.Context, agentsDir string, store session.Store) string { |
| 305 | t.Helper() |
no test coverage detected