SubscriberReceiver returns a multi-path HTTP receiver wired for the new webhook-resource envelope. Routes work as plain paths under the receiver's base URL — e.g. receiver.Server.URL + "/sent" + ".../fail".
(t *testing.T)
| 308 | // new webhook-resource envelope. Routes work as plain paths under the |
| 309 | // receiver's base URL — e.g. receiver.Server.URL + "/sent" + ".../fail". |
| 310 | func SubscriberReceiver(t *testing.T) *SubscriberReceiverResult { |
| 311 | t.Helper() |
| 312 | result := &SubscriberReceiverResult{} |
| 313 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 314 | raw, err := io.ReadAll(r.Body) |
| 315 | if err != nil { |
| 316 | http.Error(w, "read err", 500) |
| 317 | return |
| 318 | } |
| 319 | var env map[string]any |
| 320 | _ = json.Unmarshal(raw, &env) // tolerate non-JSON for negative cases |
| 321 | |
| 322 | result.mu.Lock() |
| 323 | result.captured = append(result.captured, SubscriberCaptured{ |
| 324 | URL: r.URL.Path, |
| 325 | Envelope: env, |
| 326 | RawBody: raw, |
| 327 | Headers: r.Header.Clone(), |
| 328 | }) |
| 329 | status := 200 |
| 330 | if s, ok := result.statusByPath[r.URL.Path]; ok { |
| 331 | status = s |
| 332 | } |
| 333 | result.mu.Unlock() |
| 334 | w.WriteHeader(status) |
| 335 | })) |
| 336 | result.Server = server |
| 337 | t.Cleanup(server.Close) |
| 338 | return result |
| 339 | } |
| 340 | |
| 341 | func WebhookReceiver(t *testing.T) *WebhookReceiverResult { |
| 342 | t.Helper() |