| 216 | } |
| 217 | |
| 218 | func (w *WebhookReceiverResult) WaitForPayloads(t *testing.T, count int, timeout time.Duration) []ReceivedPayload { |
| 219 | t.Helper() |
| 220 | deadline := time.Now().Add(timeout) |
| 221 | for time.Now().Before(deadline) { |
| 222 | payloads := w.Payloads() |
| 223 | if len(payloads) >= count { |
| 224 | return payloads |
| 225 | } |
| 226 | time.Sleep(50 * time.Millisecond) |
| 227 | } |
| 228 | payloads := w.Payloads() |
| 229 | if len(payloads) < count { |
| 230 | t.Fatalf("expected %d webhook payloads, got %d after %v", count, len(payloads), timeout) |
| 231 | } |
| 232 | return payloads |
| 233 | } |
| 234 | |
| 235 | // SubscriberCaptured is one POST the SubscriberReceiver caught. The |
| 236 | // envelope is the parsed JSON body ({event, id, created_at, data}) |