|
| 1 | +"""Tests for URL utility functions.""" |
| 2 | +import pytest |
| 3 | +from databricks.sql.common.url_utils import normalize_host_with_protocol |
| 4 | + |
| 5 | + |
| 6 | +class TestNormalizeHostWithProtocol: |
| 7 | + """Tests for normalize_host_with_protocol function.""" |
| 8 | + |
| 9 | + @pytest.mark.parametrize("input_host,expected_output", [ |
| 10 | + # Hostname without protocol - should add https:// |
| 11 | + ("myserver.com", "https://myserver.com"), |
| 12 | + ("workspace.databricks.com", "https://workspace.databricks.com"), |
| 13 | + |
| 14 | + # Hostname with https:// - should not duplicate |
| 15 | + ("https://myserver.com", "https://myserver.com"), |
| 16 | + ("https://workspace.databricks.com", "https://workspace.databricks.com"), |
| 17 | + |
| 18 | + # Hostname with http:// - should preserve |
| 19 | + ("http://localhost", "http://localhost"), |
| 20 | + ("http://myserver.com:8080", "http://myserver.com:8080"), |
| 21 | + |
| 22 | + # Hostname with port numbers |
| 23 | + ("myserver.com:443", "https://myserver.com:443"), |
| 24 | + ("https://myserver.com:443", "https://myserver.com:443"), |
| 25 | + ("http://localhost:8080", "http://localhost:8080"), |
| 26 | + |
| 27 | + # Trailing slash - should be removed |
| 28 | + ("myserver.com/", "https://myserver.com"), |
| 29 | + ("https://myserver.com/", "https://myserver.com"), |
| 30 | + ("http://localhost/", "http://localhost"), |
| 31 | + |
| 32 | + # Real Databricks patterns |
| 33 | + ("adb-123456.azuredatabricks.net", "https://adb-123456.azuredatabricks.net"), |
| 34 | + ("https://adb-123456.azuredatabricks.net", "https://adb-123456.azuredatabricks.net"), |
| 35 | + ("https://adb-123456.azuredatabricks.net/", "https://adb-123456.azuredatabricks.net"), |
| 36 | + ("workspace.databricks.com/", "https://workspace.databricks.com"), |
| 37 | + ]) |
| 38 | + def test_normalize_host_with_protocol(self, input_host, expected_output): |
| 39 | + """Test host normalization with various input formats.""" |
| 40 | + assert normalize_host_with_protocol(input_host) == expected_output |
| 41 | + |
0 commit comments