github.com/nsqio/nsq@v1.3.0/internal/clusterinfo/producer_test.go (about) 1 package clusterinfo 2 3 import "testing" 4 5 func TestHostNameAddresses(t *testing.T) { 6 p := &Producer{ 7 BroadcastAddress: "host.domain.com", 8 TCPPort: 4150, 9 HTTPPort: 4151, 10 } 11 12 if p.HTTPAddress() != "host.domain.com:4151" { 13 t.Errorf("Incorrect HTTPAddress: %s", p.HTTPAddress()) 14 } 15 if p.TCPAddress() != "host.domain.com:4150" { 16 t.Errorf("Incorrect TCPAddress: %s", p.TCPAddress()) 17 } 18 } 19 20 func TestIPv4Addresses(t *testing.T) { 21 p := &Producer{ 22 BroadcastAddress: "192.168.1.17", 23 TCPPort: 4150, 24 HTTPPort: 4151, 25 } 26 27 if p.HTTPAddress() != "192.168.1.17:4151" { 28 t.Errorf("Incorrect IPv4 HTTPAddress: %s", p.HTTPAddress()) 29 } 30 if p.TCPAddress() != "192.168.1.17:4150" { 31 t.Errorf("Incorrect IPv4 TCPAddress: %s", p.TCPAddress()) 32 } 33 } 34 35 func TestIPv6Addresses(t *testing.T) { 36 p := &Producer{ 37 BroadcastAddress: "fd4a:622f:d2f2::1", 38 TCPPort: 4150, 39 HTTPPort: 4151, 40 } 41 if p.HTTPAddress() != "[fd4a:622f:d2f2::1]:4151" { 42 t.Errorf("Incorrect IPv6 HTTPAddress: %s", p.HTTPAddress()) 43 } 44 if p.TCPAddress() != "[fd4a:622f:d2f2::1]:4150" { 45 t.Errorf("Incorrect IPv6 TCPAddress: %s", p.TCPAddress()) 46 } 47 }