(t *testing.T)
| 65 | } |
| 66 | |
| 67 | func TestParseEnvelopeItems_MultipleItems(t *testing.T) { |
| 68 | p1 := `{"event_id":"e1","level":"error"}` |
| 69 | p2 := `{"trace_id":"tt","level":"info","body":"log line"}` |
| 70 | |
| 71 | body := []byte("{\"event_id\":\"e1\"}\n" + |
| 72 | "{\"type\":\"event\",\"length\":" + strconv.Itoa(len(p1)) + "}\n" + |
| 73 | p1 + "\n" + |
| 74 | "{\"type\":\"log\",\"length\":" + strconv.Itoa(len(p2)) + "}\n" + |
| 75 | p2) |
| 76 | |
| 77 | _, items, err := parseEnvelopeItems(body) |
| 78 | if err != nil { |
| 79 | t.Fatal(err) |
| 80 | } |
| 81 | if len(items) != 2 { |
| 82 | t.Fatalf("items = %d, want 2", len(items)) |
| 83 | } |
| 84 | if items[0].Type != "event" { |
| 85 | t.Errorf("item[0].Type = %q", items[0].Type) |
| 86 | } |
| 87 | if items[1].Type != "log" { |
| 88 | t.Errorf("item[1].Type = %q", items[1].Type) |
| 89 | } |
| 90 | if string(items[0].Payload) != p1 { |
| 91 | t.Errorf("item[0].Payload = %q", items[0].Payload) |
| 92 | } |
| 93 | if string(items[1].Payload) != p2 { |
| 94 | t.Errorf("item[1].Payload = %q", items[1].Payload) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | func TestParseEnvelopeItems_BadItemHeaderIsSkipped(t *testing.T) { |
| 99 | // Item header is unparseable — the parser must move past the next newline |
nothing calls this directly
no test coverage detected