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

Function TestEnvelopeParser

modules/sentry/storage_test.go:420–455  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

418}
419
420func TestEnvelopeParser(t *testing.T) {
421 t.Run("multi-item envelope", func(t *testing.T) {
422 body := []byte(`{"event_id":"env-id","sent_at":"2023-01-01T00:00:00Z"}
423{"type":"event","length":0}
424{"event_id":"evt-1","message":"test"}
425{"type":"session","length":0}
426{"sid":"sess-1"}`)
427
428 header, items, err := parseEnvelopeItems(body)
429 if err != nil {
430 t.Fatal(err)
431 }
432 if header.EventID != "env-id" {
433 t.Errorf("header.EventID = %q, want 'env-id'", header.EventID)
434 }
435 if len(items) != 2 {
436 t.Fatalf("items count = %d, want 2", len(items))
437 }
438 if items[0].Type != "event" {
439 t.Errorf("items[0].Type = %q, want 'event'", items[0].Type)
440 }
441 if items[1].Type != "session" {
442 t.Errorf("items[1].Type = %q, want 'session'", items[1].Type)
443 }
444 })
445
446 t.Run("empty envelope", func(t *testing.T) {
447 _, items, err := parseEnvelopeItems([]byte{})
448 if err != nil {
449 t.Fatal(err)
450 }
451 if len(items) != 0 {
452 t.Errorf("expected no items, got %d", len(items))
453 }
454 })
455}
456
457func TestSessionItemDiscarded(t *testing.T) {
458 h := &handler{}

Callers

nothing calls this directly

Calls 2

parseEnvelopeItemsFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected