MCPcopy Create free account
hub / github.com/buggregator/server / TestHandler_SDKv2_PlainJSON

Function TestHandler_SDKv2_PlainJSON

modules/sentry/handler_test.go:483–518  ·  view source on GitHub ↗

TestHandler_SDKv2_PlainJSON tests Sentry PHP SDK v2. v2 always sends plain JSON to /api/{project}/store with ISO 8601 timestamp string.

(t *testing.T)

Source from the content-addressed store, hash-verified

481// TestHandler_SDKv2_PlainJSON tests Sentry PHP SDK v2.
482// v2 always sends plain JSON to /api/{project}/store with ISO 8601 timestamp string.
483func TestHandler_SDKv2_PlainJSON(t *testing.T) {
484 h := &handler{}
485
486 // Real payload structure from sentry/sentry 2.5.2.
487 // Note: timestamp is ISO 8601 string, not float.
488 payload := `{"event_id":"197468f20c2b4697a0ae0d236330b0b0","timestamp":"2026-03-31T12:44:44Z","level":"error","platform":"php","sdk":{"name":"sentry.php","version":"2.5.2"},"server_name":"web-01","release":"1.0.0","environment":"production","message":"Something went wrong","contexts":{"os":{"name":"Linux","version":"6.17.0"},"runtime":{"name":"php","version":"8.5.3"}}}`
489
490 r := httptest.NewRequest("POST", "/api/1/store", strings.NewReader(payload))
491 r.Header.Set("X-Sentry-Auth", "Sentry sentry_version=7, sentry_client=sentry.php/2.5.2, sentry_key=test")
492
493 inc, err := h.Handle(r)
494 if err != nil {
495 t.Fatalf("Handle() error: %v", err)
496 }
497 if inc == nil {
498 t.Fatal("Handle() returned nil, want non-nil incoming event")
499 }
500 if inc.Type != "sentry" {
501 t.Errorf("Type = %q, want %q", inc.Type, "sentry")
502 }
503 if inc.UUID != "197468f20c2b4697a0ae0d236330b0b0" {
504 t.Errorf("UUID = %q, want %q", inc.UUID, "197468f20c2b4697a0ae0d236330b0b0")
505 }
506
507 var parsed map[string]any
508 if err := json.Unmarshal(inc.Payload, &parsed); err != nil {
509 t.Fatalf("failed to parse payload: %v", err)
510 }
511 if parsed["event_id"] != "197468f20c2b4697a0ae0d236330b0b0" {
512 t.Errorf("payload event_id = %v, want %q", parsed["event_id"], "197468f20c2b4697a0ae0d236330b0b0")
513 }
514 // v2 timestamp is ISO string — must be preserved.
515 if parsed["timestamp"] != "2026-03-31T12:44:44Z" {
516 t.Errorf("payload timestamp = %v, want %q", parsed["timestamp"], "2026-03-31T12:44:44Z")
517 }
518}
519
520// TestHandler_SDKv2_PlainJSON_WithDB tests that v2 events with ISO timestamps
521// are stored correctly in structured storage.

Callers

nothing calls this directly

Calls 1

HandleMethod · 0.95

Tested by

no test coverage detected