MCPcopy Create free account
hub / github.com/facebook/time / TestReadResponse

Function TestReadResponse

sa53/protocol/protocol_test.go:122–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

120}
121
122func TestReadResponse(t *testing.T) {
123 tests := []struct {
124 name string
125 chunks [][]byte
126 want string
127 wantErr bool
128 }{
129 {
130 name: "single chunk",
131 chunks: [][]byte{[]byte("[=276428]\r\n")},
132 want: "[=276428]",
133 },
134 {
135 name: "split across reads",
136 chunks: [][]byte{[]byte("[=27"), []byte("6428]\r\n")},
137 want: "[=276428]",
138 },
139 {
140 name: "terminator split",
141 chunks: [][]byte{[]byte("[=42]\r"), []byte("\n")},
142 want: "[=42]",
143 },
144 {
145 name: "timeout before terminator",
146 chunks: [][]byte{[]byte("[=incomplete")},
147 wantErr: true,
148 },
149 {
150 name: "empty",
151 chunks: nil,
152 wantErr: true,
153 },
154 }
155 for _, tc := range tests {
156 t.Run(tc.name, func(t *testing.T) {
157 m := newTestMac(&fakePort{chunks: tc.chunks})
158 got, err := m.ReadResponse()
159 if tc.wantErr {
160 require.Error(t, err)
161 return
162 }
163 require.NoError(t, err)
164 require.Equal(t, tc.want, got)
165 })
166 }
167}
168
169func TestGetSendsExpectedCommand(t *testing.T) {
170 fp := &fakePort{chunks: [][]byte{[]byte("[=276428]\r\n")}}

Callers

nothing calls this directly

Calls 4

newTestMacFunction · 0.85
ReadResponseMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…