MCPcopy
hub / github.com/grpc/grpc-go / handleStreamCloseBodyTest

Function handleStreamCloseBodyTest

internal/transport/handler_server_test.go:364–385  ·  view source on GitHub ↗
(t *testing.T, statusCode codes.Code, msg string)

Source from the content-addressed store, hash-verified

362}
363
364func handleStreamCloseBodyTest(t *testing.T, statusCode codes.Code, msg string) {
365 st := newHandleStreamTest(t, nil)
366
367 handleStream := func(s *ServerStream) {
368 s.WriteStatus(status.New(statusCode, msg))
369 }
370 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
371 defer cancel()
372 st.ht.HandleStreams(
373 ctx, func(s *ServerStream) { go handleStream(s) },
374 )
375 wantHeader := http.Header{
376 "Date": nil,
377 "Content-Type": {"application/grpc"},
378 "Trailer": {"Grpc-Status", "Grpc-Message", "Grpc-Status-Details-Bin"},
379 }
380 wantTrailer := http.Header{
381 "Grpc-Status": {fmt.Sprint(uint32(statusCode))},
382 "Grpc-Message": {encodeGrpcMessage(msg)},
383 }
384 checkHeaderAndTrailer(t, st.rw, wantHeader, wantTrailer)
385}
386
387func (s) TestHandlerTransport_HandleStreams_Timeout(t *testing.T) {
388 bodyr, bodyw := io.Pipe()

Calls 6

NewFunction · 0.92
newHandleStreamTestFunction · 0.85
encodeGrpcMessageFunction · 0.85
checkHeaderAndTrailerFunction · 0.85
WriteStatusMethod · 0.80
HandleStreamsMethod · 0.65

Tested by

no test coverage detected