@@ -368,8 +368,10 @@ type test struct {
368
368
userAgent string
369
369
clientCompression bool
370
370
serverCompression bool
371
- unaryInt grpc.UnaryServerInterceptor
372
- streamInt grpc.StreamServerInterceptor
371
+ unaryClientInt grpc.UnaryClientInterceptor
372
+ streamClientInt grpc.StreamClientInterceptor
373
+ unaryServerInt grpc.UnaryServerInterceptor
374
+ streamServerInt grpc.StreamServerInterceptor
373
375
374
376
// srv and srvAddr are set once startServer is called.
375
377
srv * grpc.Server
@@ -423,11 +425,11 @@ func (te *test) startServer(ts testpb.TestServiceServer) {
423
425
grpc .RPCDecompressor (grpc .NewGZIPDecompressor ()),
424
426
)
425
427
}
426
- if te .unaryInt != nil {
427
- sopts = append (sopts , grpc .UnaryInterceptor (te .unaryInt ))
428
+ if te .unaryServerInt != nil {
429
+ sopts = append (sopts , grpc .UnaryInterceptor (te .unaryServerInt ))
428
430
}
429
- if te .streamInt != nil {
430
- sopts = append (sopts , grpc .StreamInterceptor (te .streamInt ))
431
+ if te .streamServerInt != nil {
432
+ sopts = append (sopts , grpc .StreamInterceptor (te .streamServerInt ))
431
433
}
432
434
la := "localhost:0"
433
435
switch te .e .network {
@@ -492,6 +494,12 @@ func (te *test) clientConn() *grpc.ClientConn {
492
494
grpc .WithDecompressor (grpc .NewGZIPDecompressor ()),
493
495
)
494
496
}
497
+ if te .unaryClientInt != nil {
498
+ opts = append (opts , grpc .WithUnaryInterceptor (te .unaryClientInt ))
499
+ }
500
+ if te .streamClientInt != nil {
501
+ opts = append (opts , grpc .WithStreamInterceptor (te .streamClientInt ))
502
+ }
495
503
switch te .e .security {
496
504
case "tls" :
497
505
creds , err := credentials .NewClientTLSFromFile (tlsDir + "ca.pem" , "x.test.youtube.com" )
@@ -2137,6 +2145,75 @@ func testCompressOK(t *testing.T, e env) {
2137
2145
}
2138
2146
}
2139
2147
2148
+ func TestUnaryClientInterceptor (t * testing.T ) {
2149
+ defer leakCheck (t )()
2150
+ for _ , e := range listTestEnv () {
2151
+ testUnaryClientInterceptor (t , e )
2152
+ }
2153
+ }
2154
+
2155
+ func failOkayRPC (ctx context.Context , method string , req , reply interface {}, cc * grpc.ClientConn , invoker grpc.UnaryInvoker , opts ... grpc.CallOption ) error {
2156
+ err := invoker (ctx , method , req , reply , cc , opts ... )
2157
+ if err == nil {
2158
+ return grpc .Errorf (codes .NotFound , "" )
2159
+ }
2160
+ return err
2161
+ }
2162
+
2163
+ func testUnaryClientInterceptor (t * testing.T , e env ) {
2164
+ te := newTest (t , e )
2165
+ te .userAgent = testAppUA
2166
+ te .unaryClientInt = failOkayRPC
2167
+ te .startServer (& testServer {security : e .security })
2168
+ defer te .tearDown ()
2169
+
2170
+ tc := testpb .NewTestServiceClient (te .clientConn ())
2171
+ if _ , err := tc .EmptyCall (context .Background (), & testpb.Empty {}); grpc .Code (err ) != codes .NotFound {
2172
+ t .Fatalf ("%v.EmptyCall(_, _) = _, %v, want _, error code %s" , tc , err , codes .NotFound )
2173
+ }
2174
+ }
2175
+
2176
+ func TestStreamClientInterceptor (t * testing.T ) {
2177
+ defer leakCheck (t )()
2178
+ for _ , e := range listTestEnv () {
2179
+ testStreamClientInterceptor (t , e )
2180
+ }
2181
+ }
2182
+
2183
+ func failOkayStream (ctx context.Context , desc * grpc.StreamDesc , cc * grpc.ClientConn , method string , streamer grpc.Streamer , opts ... grpc.CallOption ) (grpc.ClientStream , error ) {
2184
+ s , err := streamer (ctx , desc , cc , method , opts ... )
2185
+ if err == nil {
2186
+ return nil , grpc .Errorf (codes .NotFound , "" )
2187
+ }
2188
+ return s , nil
2189
+ }
2190
+
2191
+ func testStreamClientInterceptor (t * testing.T , e env ) {
2192
+ te := newTest (t , e )
2193
+ te .streamClientInt = failOkayStream
2194
+ te .startServer (& testServer {security : e .security })
2195
+ defer te .tearDown ()
2196
+
2197
+ tc := testpb .NewTestServiceClient (te .clientConn ())
2198
+ respParam := []* testpb.ResponseParameters {
2199
+ {
2200
+ Size : proto .Int32 (int32 (1 )),
2201
+ },
2202
+ }
2203
+ payload , err := newPayload (testpb .PayloadType_COMPRESSABLE , int32 (1 ))
2204
+ if err != nil {
2205
+ t .Fatal (err )
2206
+ }
2207
+ req := & testpb.StreamingOutputCallRequest {
2208
+ ResponseType : testpb .PayloadType_COMPRESSABLE .Enum (),
2209
+ ResponseParameters : respParam ,
2210
+ Payload : payload ,
2211
+ }
2212
+ if _ , err := tc .StreamingOutputCall (context .Background (), req ); grpc .Code (err ) != codes .NotFound {
2213
+ t .Fatalf ("%v.StreamingOutputCall(_) = _, %v, want _, error code %s" , tc , err , codes .NotFound )
2214
+ }
2215
+ }
2216
+
2140
2217
func TestUnaryServerInterceptor (t * testing.T ) {
2141
2218
defer leakCheck (t )()
2142
2219
for _ , e := range listTestEnv () {
@@ -2150,7 +2227,7 @@ func errInjector(ctx context.Context, req interface{}, info *grpc.UnaryServerInf
2150
2227
2151
2228
func testUnaryServerInterceptor (t * testing.T , e env ) {
2152
2229
te := newTest (t , e )
2153
- te .unaryInt = errInjector
2230
+ te .unaryServerInt = errInjector
2154
2231
te .startServer (& testServer {security : e .security })
2155
2232
defer te .tearDown ()
2156
2233
@@ -2181,7 +2258,7 @@ func fullDuplexOnly(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServ
2181
2258
2182
2259
func testStreamServerInterceptor (t * testing.T , e env ) {
2183
2260
te := newTest (t , e )
2184
- te .streamInt = fullDuplexOnly
2261
+ te .streamServerInt = fullDuplexOnly
2185
2262
te .startServer (& testServer {security : e .security })
2186
2263
defer te .tearDown ()
2187
2264
0 commit comments