MCPcopy
hub / github.com/connectrpc/connect-go / TestOnionOrderingEndToEnd

Function TestOnionOrderingEndToEnd

interceptor_ext_test.go:511–644  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

509}
510
511func TestOnionOrderingEndToEnd(t *testing.T) {
512 t.Parallel()
513 // Helper function: returns a function that asserts that there's some value
514 // set for header "expect", and adds a value for header "add".
515 newInspector := func(expect, add string) func(connect.Spec, http.Header) {
516 return func(spec connect.Spec, header http.Header) {
517 if expect != "" {
518 assert.NotZero(
519 t,
520 header.Get(expect),
521 assert.Sprintf(
522 "%s (IsClient %v): header %q missing: %v",
523 spec.Procedure,
524 spec.IsClient,
525 expect,
526 header,
527 ),
528 )
529 }
530 header.Set(add, "v")
531 }
532 }
533 // Helper function: asserts that there's a value present for header keys
534 // "one", "two", "three", and "four".
535 assertAllPresent := func(spec connect.Spec, header http.Header) {
536 for _, key := range []string{"one", "two", "three", "four"} {
537 assert.NotZero(
538 t,
539 header.Get(key),
540 assert.Sprintf(
541 "%s (IsClient %v): checking all headers, %q missing: %v",
542 spec.Procedure,
543 spec.IsClient,
544 key,
545 header,
546 ),
547 )
548 }
549 }
550
551 var clientCounter1, clientCounter2, clientCounter3, handlerCounter1, handlerCounter2, handlerCounter3 atomic.Int32
552
553 // The client and handler interceptor onions are the meat of the test. The
554 // order of interceptor execution must be the same for unary and streaming
555 // procedures.
556 //
557 // Requests should fall through the client onion from top to bottom, traverse
558 // the network, and then fall through the handler onion from top to bottom.
559 // Responses should climb up the handler onion, traverse the network, and
560 // then climb up the client onion.
561 //
562 // The request and response sides of this onion are numbered to make the
563 // intended order clear.
564 clientOnion := connect.WithInterceptors(
565 newHeaderInterceptor(
566 &clientCounter1,
567 // 1 (start). request: should see protocol-related headers
568 func(_ connect.Spec, h http.Header) {

Callers

nothing calls this directly

Calls 15

ClientMethod · 0.95
URLMethod · 0.95
PingMethod · 0.95
CountUpMethod · 0.95
NotZeroFunction · 0.92
SprintfFunction · 0.92
WithInterceptorsFunction · 0.92
NewPingServiceHandlerFunction · 0.92
NewServerFunction · 0.92
NewPingServiceClientFunction · 0.92
NewRequestFunction · 0.92
NilFunction · 0.92

Tested by

no test coverage detected