MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestLoopbackConn

Function TestLoopbackConn

pkg/rpcserver/loopback_test.go:30–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestLoopbackConn(t *testing.T) {
31 a := assertions.New(t)
32 ctx, cancel := context.WithCancel(test.Context())
33 defer cancel()
34
35 server := grpc.NewServer()
36 a.So(server, should.NotBeNil)
37 rpctest.RegisterFooBarServer(server, &rpctest.FooBarExampleServer{})
38
39 stats := &statsHandler{}
40 loopbackConn, err := rpcserver.StartLoopback(ctx, server, grpc.WithStatsHandler(stats))
41 a.So(loopbackConn, should.NotBeNil)
42 a.So(err, should.BeNil)
43
44 cli := rpctest.NewFooBarClient(loopbackConn)
45
46 bar, err := cli.Unary(ctx, &rpctest.Foo{Message: "foo"})
47 a.So(err, should.BeNil)
48 a.So(bar.Message, should.Equal, "foofoo")
49
50 a.So(stats.rpcTag, should.NotBeNil)
51 a.So(stats.rpcTag.FullMethodName, should.Equal, "/rpctest.FooBar/Unary")
52 a.So(stats.rpcTag.FailFast, should.Equal, true)
53
54 a.So(stats.connTag, should.NotBeNil)
55 a.So(stats.connTag.RemoteAddr, should.Resemble, stats.connTag.LocalAddr)
56}
57
58type statsHandler struct {
59 rpcTag *stats.RPCTagInfo

Callers

nothing calls this directly

Calls 6

UnaryMethod · 0.95
ContextFunction · 0.92
RegisterFooBarServerFunction · 0.92
StartLoopbackFunction · 0.92
NewFooBarClientFunction · 0.92
NewMethod · 0.65

Tested by

no test coverage detected