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

Function TestGRPC

pkg/component/component_test.go:182–237  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

180}
181
182func TestGRPC(t *testing.T) {
183 a := assertions.New(t)
184
185 baseConfig := component.Config{
186 ServiceBase: config.ServiceBase{GRPC: config.GRPC{}},
187 }
188
189 // gRPC without TLS
190 {
191 grpcPort := 9199
192 config := baseConfig
193 config.ServiceBase.GRPC.Listen = fmt.Sprintf("0.0.0.0:%d", grpcPort)
194
195 c, err := component.New(test.GetLogger(t), &config)
196 a.So(err, should.BeNil)
197
198 err = c.Start()
199 a.So(err, should.BeNil)
200
201 client, err := grpc.Dial(fmt.Sprintf("localhost:%d", grpcPort),
202 grpc.WithInsecure(),
203 grpc.WithTimeout(time.Second*3),
204 grpc.WithBlock())
205 a.So(err, should.BeNil)
206 client.Close()
207
208 c.Close()
209 }
210
211 // gRPC with TLS
212 {
213 grpcPort := 9197
214
215 config := baseConfig
216 config.ServiceBase.GRPC.ListenTLS = fmt.Sprintf("0.0.0.0:%d", grpcPort)
217 config.TLS.ServerAuth.Certificate = "testdata/servercert.pem"
218 config.TLS.ServerAuth.Key = "testdata/serverkey.pem"
219
220 c, err := component.New(test.GetLogger(t), &config)
221 a.So(err, should.BeNil)
222
223 err = c.Start()
224 a.So(err, should.BeNil)
225
226 tlsCredentials, err := credentials.NewClientTLSFromFile(config.TLS.ServerAuth.Certificate, "")
227 a.So(err, should.BeNil)
228
229 client, err := grpc.Dial(fmt.Sprintf("localhost:%d", grpcPort),
230 grpc.WithTimeout(time.Second*3),
231 grpc.WithTransportCredentials(tlsCredentials))
232 a.So(err, should.BeNil)
233 client.Close()
234
235 c.Close()
236 }
237}
238
239func TestContext(t *testing.T) {

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
GetLoggerFunction · 0.92
NewMethod · 0.65
CloseMethod · 0.65
StartMethod · 0.45

Tested by

no test coverage detected