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

Function TestLocalAddr

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

Source from the content-addressed store, hash-verified

576}
577
578func TestLocalAddr(t *testing.T) {
579 s := RunServerOnPort(TEST_PORT)
580 defer s.Shutdown()
581
582 var nc *nats.Conn
583 if addr := nc.LocalAddr(); addr != "" {
584 t.Fatalf("Expected empty result for nil connection, got %q", addr)
585 }
586 nc, err := nats.Connect(fmt.Sprintf("localhost:%d", TEST_PORT))
587 if err != nil {
588 t.Fatalf("Error connecting: %v", err)
589 }
590 addr := nc.LocalAddr()
591 if addr == "" {
592 t.Fatalf("Expected non-empty local address")
593 }
594 // Verify it's a valid address format
595 host, port, err := net.SplitHostPort(addr)
596 if err != nil {
597 t.Fatalf("Expected valid host:port format, got %q: %v", addr, err)
598 }
599 if host == "" {
600 t.Fatalf("Expected non-empty host in address %q", addr)
601 }
602 if port == "" {
603 t.Fatalf("Expected non-empty port in address %q", addr)
604 }
605 nc.Close()
606 if addr := nc.LocalAddr(); addr != "" {
607 t.Fatalf("Expected empty result for closed connection, got %q", addr)
608 }
609}
610
611func TestSubscribeSyncRace(t *testing.T) {
612 s := RunServerOnPort(TEST_PORT)

Callers

nothing calls this directly

Calls 5

LocalAddrMethod · 0.95
CloseMethod · 0.95
FatalfMethod · 0.80
ConnectMethod · 0.80
RunServerOnPortFunction · 0.70

Tested by

no test coverage detected