MCPcopy
hub / github.com/nats-io/nats.go / TestConnectedAddr

Function TestConnectedAddr

test/nats_test.go:556–576  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

554}
555
556func TestConnectedAddr(t *testing.T) {
557 s := RunServerOnPort(TEST_PORT)
558 defer s.Shutdown()
559
560 var nc *nats.Conn
561 if addr := nc.ConnectedAddr(); addr != "" {
562 t.Fatalf("Expected empty result for nil connection, got %q", addr)
563 }
564 nc, err := nats.Connect(fmt.Sprintf("localhost:%d", TEST_PORT))
565 if err != nil {
566 t.Fatalf("Error connecting: %v", err)
567 }
568 expected := s.Addr().String()
569 if addr := nc.ConnectedAddr(); addr != expected {
570 t.Fatalf("Expected address %q, got %q", expected, addr)
571 }
572 nc.Close()
573 if addr := nc.ConnectedAddr(); addr != "" {
574 t.Fatalf("Expected empty result for closed connection, got %q", addr)
575 }
576}
577
578func TestLocalAddr(t *testing.T) {
579 s := RunServerOnPort(TEST_PORT)

Callers

nothing calls this directly

Calls 6

ConnectedAddrMethod · 0.95
CloseMethod · 0.95
FatalfMethod · 0.80
ConnectMethod · 0.80
RunServerOnPortFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected