| 16 | ) |
| 17 | |
| 18 | func TestNewServer(t *testing.T) { |
| 19 | s := NewServer("1.1.1.1:::123456789") |
| 20 | if s != nil { |
| 21 | t.Fatalf("fatal error, server created with too many colons %v", s) |
| 22 | } |
| 23 | |
| 24 | s2 := NewServer("1.1.1.1:[]") |
| 25 | if s != nil { |
| 26 | t.Fatalf("%v", s2) |
| 27 | |
| 28 | } |
| 29 | |
| 30 | _, port, _ := net.SplitHostPort("") |
| 31 | if port != "" { |
| 32 | t.Fatalf("%v", port) |
| 33 | |
| 34 | } |
| 35 | |
| 36 | s = NewServer("http://127.0.0.1:8888") |
| 37 | hosts := s.Hosts() |
| 38 | if len(hosts) != 1 || hosts[0] != "http://127.0.0.1:8888" { |
| 39 | t.Fatalf("expected [http://127.0.0.1:8888], but have %v", hosts) |
| 40 | } |
| 41 | |
| 42 | s = NewServer("http://1.1.1.1:9999") |
| 43 | hosts = s.Hosts() |
| 44 | if len(hosts) != 1 || hosts[0] != "http://1.1.1.1:9999" { |
| 45 | t.Fatalf("expected [http://1.1.1.1:9999], but have %v", hosts) |
| 46 | } |
| 47 | |
| 48 | s = NewServer("https://1.1.1.1:8080") |
| 49 | hosts = s.Hosts() |
| 50 | if len(hosts) != 1 || hosts[0] != "https://1.1.1.1:8080" { |
| 51 | t.Fatalf("expected [https://1.1.1.1:8080], but have %v", hosts) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func TestInvalidPort(t *testing.T) { |
| 56 | s := NewServer("1.1.1.1:99999999999999999999999999999") |