MCPcopy
hub / github.com/keploy/keploy / TestSimulateHTTP_SSEStreamMatchAndEarlyClose_316

Function TestSimulateHTTP_SSEStreamMatchAndEarlyClose_316

pkg/util_test.go:229–320  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

227}
228
229func TestSimulateHTTP_SSEStreamMatchAndEarlyClose_316(t *testing.T) {
230 ctx := context.Background()
231 logger := zap.NewNop()
232
233 serverClosed := make(chan struct{})
234 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
235 w.Header().Set("Content-Type", "text/event-stream; charset=utf-8")
236 flusher, ok := w.(http.Flusher)
237 require.True(t, ok, "server response writer must support flushing")
238
239 _, _ = w.Write([]byte("id:100\nevent:ticker\ndata:{\"value\":1}\n\n"))
240 flusher.Flush()
241 _, _ = w.Write([]byte("id:101\nevent:ticker\ndata:{\"value\":2}\n\n"))
242 flusher.Flush()
243 _, _ = w.Write([]byte("id:102\nevent:ticker\ndata:{\"value\":3}\n\n"))
244 flusher.Flush()
245
246 <-r.Context().Done()
247 close(serverClosed)
248 }))
249 defer server.Close()
250
251 expectedSSEBody := strings.Join([]string{
252 "id:100",
253 "event:ticker",
254 "data:{\"value\":1}",
255 "",
256 "id:101",
257 "event:ticker",
258 "data:{\"value\":2}",
259 "",
260 }, "\n")
261
262 tc := &models.TestCase{
263 Name: "sse-match-and-close",
264 HTTPReq: models.HTTPReq{
265 Method: "GET",
266 URL: server.URL,
267 Header: map[string]string{
268 "Accept": "text/event-stream",
269 },
270 },
271 HTTPResp: models.HTTPResp{
272 Header: map[string]string{
273 "Content-Type": "text/event-stream; charset=utf-8",
274 },
275 Body: expectedSSEBody,
276 StreamBody: []models.HTTPStreamChunk{
277 {
278 Data: []models.HTTPStreamDataField{
279 {Key: "id", Value: "100"},
280 {Key: "event", Value: "ticker"},
281 {Key: "data", Value: `{"value":1}`},
282 },
283 },
284 {
285 Data: []models.HTTPStreamDataField{
286 {Key: "id", Value: "101"},

Callers

nothing calls this directly

Calls 6

SimulateHTTPStreamingFunction · 0.85
CompareHTTPStreamFunction · 0.85
FlushMethod · 0.80
WriteMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected