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

Function testTap

test/end2end_test.go:2103–2157  ·  view source on GitHub ↗
(t *testing.T, e env)

Source from the content-addressed store, hash-verified

2101}
2102
2103func testTap(t *testing.T, e env) {
2104 te := newTest(t, e)
2105 te.userAgent = testAppUA
2106 ttap := &myTap{}
2107 te.tapHandle = ttap.handle
2108 te.startServer(&testServer{security: e.security})
2109 defer te.tearDown()
2110
2111 cc := te.clientConn()
2112 tc := testgrpc.NewTestServiceClient(cc)
2113 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
2114 defer cancel()
2115
2116 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != nil {
2117 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err)
2118 }
2119 if ttap.cnt.Load() != 1 {
2120 t.Fatalf("Get the count in ttap %d, want 1", ttap.cnt.Load())
2121 }
2122
2123 if _, err := tc.EmptyCall(metadata.AppendToOutgoingContext(ctx, "return-error", "false"), &testpb.Empty{}); err != nil {
2124 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err)
2125 }
2126 if ttap.cnt.Load() != 2 {
2127 t.Fatalf("Get the count in ttap %d, want 2", ttap.cnt.Load())
2128 }
2129
2130 if _, err := tc.EmptyCall(metadata.AppendToOutgoingContext(ctx, "return-error", "true"), &testpb.Empty{}); status.Code(err) != codes.Unknown {
2131 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %s", err, codes.Unknown)
2132 }
2133 if ttap.cnt.Load() != 3 {
2134 t.Fatalf("Get the count in ttap %d, want 3", ttap.cnt.Load())
2135 }
2136
2137 payload, err := newPayload(testpb.PayloadType_COMPRESSABLE, 31)
2138 if err != nil {
2139 t.Fatal(err)
2140 }
2141
2142 req := &testpb.SimpleRequest{
2143 ResponseType: testpb.PayloadType_COMPRESSABLE,
2144 ResponseSize: 45,
2145 Payload: payload,
2146 }
2147 if _, err := tc.UnaryCall(ctx, req); status.Code(err) != codes.PermissionDenied {
2148 t.Fatalf("TestService/UnaryCall(_, _) = _, %v, want _, %s", err, codes.PermissionDenied)
2149 }
2150 str, err := tc.FullDuplexCall(ctx)
2151 if err != nil {
2152 t.Fatalf("Unexpected error creating stream: %v", err)
2153 }
2154 if _, err := str.Recv(); status.Code(err) != codes.FailedPrecondition {
2155 t.Fatalf("FullDuplexCall Recv() = _, %v, want _, %s", err, codes.FailedPrecondition)
2156 }
2157}
2158
2159func (s) TestTapStatusDetails(t *testing.T) {
2160 tapHandler := func(context.Context, *tap.Info) (context.Context, error) {

Callers 1

TestTapMethod · 0.85

Calls 14

EmptyCallMethod · 0.95
UnaryCallMethod · 0.95
FullDuplexCallMethod · 0.95
AppendToOutgoingContextFunction · 0.92
newPayloadFunction · 0.85
CodeMethod · 0.80
newTestFunction · 0.70
FatalfMethod · 0.65
FatalMethod · 0.65
RecvMethod · 0.65
startServerMethod · 0.45
tearDownMethod · 0.45

Tested by

no test coverage detected