server_address_test.go 877 B

123456789101112131415161718192021222324252627282930313233343536
  1. package pb
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func TestServerAddresses_ToAddressMapOrSrv_shouldRemovePrefix(t *testing.T) {
  7. str := ServerAddresses("dnssrv+hello.srv.consul")
  8. d := str.ToServiceDiscovery()
  9. expected := ServerSrvAddress("hello.srv.consul")
  10. if *d.srvRecord != expected {
  11. t.Fatalf(`ServerAddresses("dnssrv+hello.srv.consul") = %s, expected %s`, *d.srvRecord, expected)
  12. }
  13. }
  14. func TestServerAddresses_ToAddressMapOrSrv_shouldHandleIPPortList(t *testing.T) {
  15. str := ServerAddresses("10.0.0.1:23,10.0.0.2:24")
  16. d := str.ToServiceDiscovery()
  17. if d.srvRecord != nil {
  18. t.Fatalf(`ServerAddresses("dnssrv+hello.srv.consul") = %s, expected nil`, *d.srvRecord)
  19. }
  20. expected := []ServerAddress{
  21. ServerAddress("10.0.0.1:23"),
  22. ServerAddress("10.0.0.2:24"),
  23. }
  24. if !reflect.DeepEqual(d.list, expected) {
  25. t.Fatalf(`Expected %q, got %q`, expected, d.list)
  26. }
  27. }