This file is for unit tests. Where relevant, prefer to add e2e tests in e2e/*.test.go instead
(t *testing.T)
| 24 | // This file is for unit tests. Where relevant, prefer to add e2e tests in e2e/*.test.go instead |
| 25 | |
| 26 | func TestClient_URLParsing(t *testing.T) { |
| 27 | t.Run("should parse port-only URL format", func(t *testing.T) { |
| 28 | client := NewClient(&ClientOptions{ |
| 29 | Connection: URIConnection{URL: "8080"}, |
| 30 | }) |
| 31 | if client.actualPort != 8080 { |
| 32 | t.Errorf("Expected port 8080, got %d", client.actualPort) |
| 33 | } |
| 34 | if client.actualHost != "localhost" { |
| 35 | t.Errorf("Expected host localhost, got %s", client.actualHost) |
| 36 | } |
| 37 | if !client.isExternalServer { |
| 38 | t.Error("Expected isExternalServer to be true") |
| 39 | } |
| 40 | }) |
| 41 | |
| 42 | t.Run("should parse host:port URL format", func(t *testing.T) { |
| 43 | client := NewClient(&ClientOptions{ |
| 44 | Connection: URIConnection{URL: "127.0.0.1:9000"}, |
| 45 | }) |
| 46 | if client.actualPort != 9000 || client.actualHost != "127.0.0.1" { |
| 47 | t.Errorf("Expected 127.0.0.1:9000, got %s:%d", client.actualHost, client.actualPort) |
| 48 | } |
| 49 | }) |
| 50 | |
| 51 | t.Run("should parse http://host:port URL format", func(t *testing.T) { |
| 52 | client := NewClient(&ClientOptions{ |
| 53 | Connection: URIConnection{URL: "http://localhost:7000"}, |
| 54 | }) |
| 55 | if client.actualPort != 7000 || client.actualHost != "localhost" { |
| 56 | t.Errorf("Expected localhost:7000, got %s:%d", client.actualHost, client.actualPort) |
| 57 | } |
| 58 | }) |
| 59 | |
| 60 | t.Run("should parse https://host:port URL format", func(t *testing.T) { |
| 61 | client := NewClient(&ClientOptions{ |
| 62 | Connection: URIConnection{URL: "https://example.com:443"}, |
| 63 | }) |
| 64 | if client.actualPort != 443 || client.actualHost != "example.com" { |
| 65 | t.Errorf("Expected example.com:443, got %s:%d", client.actualHost, client.actualPort) |
| 66 | } |
| 67 | }) |
| 68 | |
| 69 | t.Run("should panic for invalid URL format", func(t *testing.T) { |
| 70 | defer func() { |
| 71 | if r := recover(); r == nil { |
| 72 | t.Error("Expected panic for invalid URL format") |
| 73 | } |
| 74 | }() |
| 75 | NewClient(&ClientOptions{Connection: URIConnection{URL: "invalid-url"}}) |
| 76 | }) |
| 77 | |
| 78 | t.Run("should panic for invalid port - too high", func(t *testing.T) { |
| 79 | defer func() { |
| 80 | if r := recover(); r == nil { |
| 81 | t.Error("Expected panic") |
| 82 | } |
| 83 | }() |