...
1
18
19 package grpc_test
20
21 import (
22 "context"
23 "testing"
24 "time"
25
26 "google.golang.org/grpc/codes"
27 "google.golang.org/grpc/internal/grpctest"
28 "google.golang.org/grpc/internal/stubserver"
29 "google.golang.org/grpc/status"
30
31 testgrpc "google.golang.org/grpc/interop/grpc_testing"
32 )
33
34 const defaultTestTimeout = 10 * time.Second
35
36 type s struct {
37 grpctest.Tester
38 }
39
40 func Test(t *testing.T) {
41 grpctest.RunSubTests(t, s{})
42 }
43
44 func (s) TestStream_Header_TrailersOnly(t *testing.T) {
45 ss := stubserver.StubServer{
46 FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error {
47 return status.Errorf(codes.NotFound, "a test error")
48 },
49 }
50 if err := ss.Start(nil); err != nil {
51 t.Fatal("Error starting server:", err)
52 }
53 defer ss.Stop()
54
55 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
56 defer cancel()
57
58 s, err := ss.Client.FullDuplexCall(ctx)
59 if err != nil {
60 t.Fatal("Error staring call", err)
61 }
62 if md, err := s.Header(); md != nil || err != nil {
63 t.Fatalf("s.Header() = %v, %v; want nil, nil", md, err)
64 }
65 if _, err := s.Recv(); status.Code(err) != codes.NotFound {
66 t.Fatalf("s.Recv() = _, %v; want _, err.Code()=codes.NotFound", err)
67 }
68 }
69
View as plain text