MCPcopy
hub / github.com/osrg/gobgp / TestGRPCAddPathUpdatesUUIDMap

Function TestGRPCAddPathUpdatesUUIDMap

pkg/server/grpc_server_test.go:465–537  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

463}
464
465func TestGRPCAddPathUpdatesUUIDMap(t *testing.T) {
466 assert := assert.New(t)
467
468 socketName, err := os.MkdirTemp("", "gobgp-grpc-test-*")
469 assert.NoError(err)
470 t.Cleanup(func() {
471 _ = os.RemoveAll(socketName)
472 })
473 socketAddr := "unix://" + socketName + "/gobgp.sock"
474
475 s := NewBgpServer(GrpcListenAddress(socketAddr))
476 go s.Serve()
477 defer s.Stop()
478
479 err = s.StartBgp(context.Background(), &api.StartBgpRequest{
480 Global: &api.Global{
481 Asn: 1,
482 RouterId: "1.1.1.1",
483 ListenPort: -1,
484 },
485 })
486 assert.NoError(err)
487 if err != nil {
488 return
489 }
490 if !assert.Eventually(func() bool {
491 _, statErr := os.Stat(socketName + "/gobgp.sock")
492 return statErr == nil
493 }, time.Second, 10*time.Millisecond) {
494 return
495 }
496
497 conn, err := grpc.NewClient(socketAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
498 assert.NoError(err)
499 if err != nil {
500 return
501 }
502 t.Cleanup(func() {
503 _ = conn.Close()
504 })
505 client := api.NewGoBgpServiceClient(conn)
506
507 prefix, err := bgp.NewIPAddrPrefix(netip.MustParsePrefix("10.0.0.0/24"))
508 assert.NoError(err)
509 nh, err := bgp.NewPathAttributeNextHop(netip.MustParseAddr("10.0.0.1"))
510 assert.NoError(err)
511 origin := bgp.NewPathAttributeOrigin(0)
512
513 path := &api.Path{
514 Family: &api.Family{
515 Afi: api.Family_AFI_IP,
516 Safi: api.Family_SAFI_UNICAST,
517 },
518 Nlri: nlri(prefix),
519 Pattrs: attrs([]bgp.PathAttributeInterface{origin, nh}),
520 }
521
522 resp, err := client.AddPath(context.Background(), &api.AddPathRequest{

Callers

nothing calls this directly

Calls 15

ServeMethod · 0.95
StopMethod · 0.95
StartBgpMethod · 0.95
AddPathMethod · 0.95
NewGoBgpServiceClientFunction · 0.92
NewIPAddrPrefixFunction · 0.92
NewPathAttributeNextHopFunction · 0.92
NewPathAttributeOriginFunction · 0.92
NewBgpServerFunction · 0.85
GrpcListenAddressFunction · 0.85
nlriFunction · 0.85
attrsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…