|
9 | 9 | from types import SimpleNamespace |
10 | 10 | from unittest.mock import Mock |
11 | 11 |
|
| 12 | +import httpx |
| 13 | + |
12 | 14 | import pytest |
13 | 15 |
|
14 | 16 | from tests.sdk.conftest import ( |
@@ -373,13 +375,35 @@ def test_get_tunnel_url_constructs_url(self, mock_client: Mock) -> None: |
373 | 375 | tunnel=tunnel_view, |
374 | 376 | ) |
375 | 377 | mock_client.devboxes.retrieve.return_value = devbox_view_with_tunnel |
| 378 | + mock_client.base_url = httpx.URL("https://api.runloop.ai") |
376 | 379 |
|
377 | 380 | devbox = Devbox(mock_client, "dbx_123") |
378 | 381 | result = devbox.get_tunnel_url(8080) |
379 | 382 |
|
380 | 383 | assert result == "https://8080-abc123xyz.tunnel.runloop.ai" |
381 | 384 | mock_client.devboxes.retrieve.assert_called_once_with("dbx_123") |
382 | 385 |
|
| 386 | + def test_get_tunnel_url_derives_domain_from_base_url(self, mock_client: Mock) -> None: |
| 387 | + """Test get_tunnel_url derives tunnel domain from client base_url.""" |
| 388 | + tunnel_view = SimpleNamespace( |
| 389 | + tunnel_key="abc123xyz", |
| 390 | + auth_mode="open", |
| 391 | + create_time_ms=1234567890000, |
| 392 | + ) |
| 393 | + devbox_view_with_tunnel = SimpleNamespace( |
| 394 | + id="dbx_123", |
| 395 | + status="running", |
| 396 | + tunnel=tunnel_view, |
| 397 | + ) |
| 398 | + mock_client.devboxes.retrieve.return_value = devbox_view_with_tunnel |
| 399 | + devbox = Devbox(mock_client, "dbx_123") |
| 400 | + |
| 401 | + mock_client.base_url = httpx.URL("https://api.runloop.pro") |
| 402 | + assert devbox.get_tunnel_url(8080) == "https://8080-abc123xyz.tunnel.runloop.pro" |
| 403 | + |
| 404 | + mock_client.base_url = httpx.URL("http://127.0.0.1:8080") |
| 405 | + assert devbox.get_tunnel_url(8080) == "https://8080-abc123xyz.tunnel.127.0.0.1" |
| 406 | + |
383 | 407 | def test_get_tunnel_url_returns_none_when_no_tunnel(self, mock_client: Mock) -> None: |
384 | 408 | """Test get_tunnel_url returns None when no tunnel is enabled.""" |
385 | 409 | devbox_view_no_tunnel = SimpleNamespace( |
|
0 commit comments