(t *testing.T)
| 62 | ) |
| 63 | |
| 64 | func TestNewRPCServer(t *testing.T) { |
| 65 | a := assertions.New(t) |
| 66 | ctx, cancel := context.WithCancel(test.Context()) |
| 67 | defer cancel() |
| 68 | |
| 69 | logHandler := memory.New() |
| 70 | logger := log.NewLogger(logHandler) |
| 71 | ctx = log.NewContext(ctx, logger) |
| 72 | |
| 73 | server := rpcserver.New(ctx, |
| 74 | rpcserver.WithContextFiller( |
| 75 | func(ctx context.Context) context.Context { |
| 76 | return context.WithValue(ctx, &mockKey{}, "foo") |
| 77 | }, |
| 78 | ), |
| 79 | rpcserver.WithUnaryInterceptors(UnaryServerInterceptor), |
| 80 | rpcserver.WithStreamInterceptors(StreamServerInterceptor), |
| 81 | ) |
| 82 | a.So(server, should.NotBeNil) |
| 83 | mock := &mockServer{} |
| 84 | ttnpb.RegisterAppAsServer(server.Server, mock) |
| 85 | |
| 86 | loopbackConn, err := rpcserver.StartLoopback(ctx, server.Server, rpcclient.DefaultDialOptions(ctx)...) |
| 87 | a.So(loopbackConn, should.NotBeNil) |
| 88 | a.So(err, should.BeNil) |
| 89 | |
| 90 | cli := ttnpb.NewAppAsClient(loopbackConn) |
| 91 | |
| 92 | t.Run("Unary", func(t *testing.T) { |
| 93 | a := assertions.New(t) |
| 94 | |
| 95 | _, err = cli.DownlinkQueuePush(ctx, downlinkQueueReq) |
| 96 | a.So(err, should.BeNil) |
| 97 | |
| 98 | a.So(mock.pushReq, should.NotBeNil) |
| 99 | a.So(mock.pushReq, should.Resemble, downlinkQueueReq) |
| 100 | |
| 101 | a.So(mock.pushCtx, should.NotBeNil) |
| 102 | a.So(mock.pushCtx.Value(&mockKey{}), should.Resemble, "foo") |
| 103 | a.So(grpc_ctxtags.Extract(mock.pushCtx).Values(), should.Resemble, map[string]any{ |
| 104 | "peer.address": "pipe", |
| 105 | "grpc.request.device_id": "foo", |
| 106 | "grpc.request.application_id": "bar", |
| 107 | }) |
| 108 | a.So(mock.pushCtx.Value(&mockKey2{}), should.Resemble, "bar") |
| 109 | |
| 110 | runtime.Gosched() |
| 111 | time.Sleep(test.Delay) |
| 112 | |
| 113 | a.So(logHandler.Entries, should.HaveLength, 1) |
| 114 | }) |
| 115 | |
| 116 | t.Run("Stream", func(t *testing.T) { |
| 117 | a := assertions.New(t) |
| 118 | |
| 119 | sub, err := cli.Subscribe(ctx, &ttnpb.ApplicationIdentifiers{ |
| 120 | ApplicationId: "bar", |
| 121 | }) |
nothing calls this directly
no test coverage detected