MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / TestScanEvents

Function TestScanEvents

mcp/event_test.go:17–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestScanEvents(t *testing.T) {
18 tests := []struct {
19 name string
20 input string
21 want []Event
22 wantErr string
23 }{
24 {
25 name: "simple event",
26 input: "event: message\nid: 1\ndata: hello\n\n",
27 want: []Event{
28 {Name: "message", ID: "1", Data: []byte("hello")},
29 },
30 },
31 {
32 name: "multiple data lines",
33 input: "data: line 1\ndata: line 2\n\n",
34 want: []Event{
35 {Data: []byte("line 1\nline 2")},
36 },
37 },
38 {
39 name: "multiple events",
40 input: "data: first\n\nevent: second\ndata: second\n\n",
41 want: []Event{
42 {Data: []byte("first")},
43 {Name: "second", Data: []byte("second")},
44 },
45 },
46 {
47 name: "no trailing newline",
48 input: "data: hello",
49 want: []Event{
50 {Data: []byte("hello")},
51 },
52 },
53 {
54 name: "malformed line",
55 input: "invalid line\n\n",
56 wantErr: "malformed line",
57 },
58 {
59 name: "message with 2 data lines and another event",
60 input: "event: message\ndata: hello\ndata: hello\ndata: hello\n\nevent:keepalive",
61 want: []Event{
62 {Name: "message", Data: []byte("hello\nhello\nhello")},
63 {Name: "keepalive"},
64 },
65 },
66 {
67 name: "event with multiple lines",
68 input: "event: message\ndata: hello\ndata: hello\ndata: hello\nid:1",
69 want: []Event{
70 {Name: "message", ID: "1", Data: []byte("hello\nhello\nhello")},
71 },
72 },
73 {
74 name: "multiple events, out of order keys",

Callers

nothing calls this directly

Calls 3

scanEventsFunction · 0.85
RunMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…