producer_test.go 1.1 KB

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