(t *testing.T)
| 32 | ) |
| 33 | |
| 34 | func TestFooBarExampleServer(t *testing.T) { |
| 35 | lis, err := net.Listen("tcp", "127.0.0.1:0") |
| 36 | if err != nil { |
| 37 | panic(err) |
| 38 | } |
| 39 | |
| 40 | server := grpc.NewServer() |
| 41 | rpctest.RegisterFooBarServer(server, &rpctest.FooBarExampleServer{}) |
| 42 | |
| 43 | go server.Serve(lis) |
| 44 | |
| 45 | cc, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure()) |
| 46 | if err != nil { |
| 47 | panic(err) |
| 48 | } |
| 49 | defer cc.Close() |
| 50 | |
| 51 | cli := rpctest.NewFooBarClient(cc) |
| 52 | |
| 53 | t.Run("Unary", func(t *testing.T) { |
| 54 | a := assertions.New(t) |
| 55 | |
| 56 | bar, err := cli.Unary(test.Context(), &rpctest.Foo{Message: "foo"}) |
| 57 | a.So(err, should.BeNil) |
| 58 | a.So(bar.Message, should.Equal, "foofoo") |
| 59 | }) |
| 60 | |
| 61 | t.Run("ClientStream", func(t *testing.T) { |
| 62 | a := assertions.New(t) |
| 63 | |
| 64 | { |
| 65 | stream, err := cli.ClientStream(test.Context()) |
| 66 | a.So(err, should.BeNil) |
| 67 | err = stream.Send(&rpctest.Foo{Message: "foo"}) |
| 68 | a.So(err, should.BeNil) |
| 69 | err = stream.Send(&rpctest.Foo{Message: "reset"}) |
| 70 | a.So(err, should.BeNil) |
| 71 | bar, err := stream.CloseAndRecv() |
| 72 | a.So(err, should.BeNil) |
| 73 | a.So(bar.Message, should.Equal, "Thanks for the 1 Foo") |
| 74 | } |
| 75 | |
| 76 | { |
| 77 | ctx, cancel := context.WithCancel(test.Context()) |
| 78 | stream, err := cli.ClientStream(ctx) |
| 79 | a.So(err, should.BeNil) |
| 80 | err = stream.Send(&rpctest.Foo{Message: "foo"}) |
| 81 | a.So(err, should.BeNil) |
| 82 | cancel() |
| 83 | err = stream.RecvMsg(&rpctest.Bar{}) |
| 84 | a.So(status.Code(err), should.Equal, codes.Canceled) |
| 85 | } |
| 86 | |
| 87 | { |
| 88 | stream, err := cli.ClientStream(test.Context()) |
| 89 | a.So(err, should.BeNil) |
| 90 | err = stream.Send(&rpctest.Foo{Message: "foo"}) |
| 91 | a.So(err, should.BeNil) |
nothing calls this directly
no test coverage detected