|
| 1 | +import logging |
1 | 2 | import threading |
2 | 3 | from unittest.mock import MagicMock, patch |
3 | 4 |
|
|
6 | 7 | from feast.infra.utils.clickhouse.clickhouse_config import ClickhouseConfig |
7 | 8 | from feast.infra.utils.clickhouse.connection_utils import get_client, thread_local |
8 | 9 |
|
| 10 | +logger = logging.getLogger(__name__) |
| 11 | + |
9 | 12 |
|
10 | 13 | @pytest.fixture |
11 | 14 | def clickhouse_config(): |
@@ -76,3 +79,57 @@ def thread_2_work(): |
76 | 79 | assert client_1a is not client_2, ( |
77 | 80 | "Different threads should get different client instances (not cached)" |
78 | 81 | ) |
| 82 | + |
| 83 | + |
| 84 | +def test_clickhouse_config_parses_additional_client_args(): |
| 85 | + """ |
| 86 | + Test that ClickhouseConfig correctly parses additional_client_args from a dict, |
| 87 | + simulating how it would be parsed from YAML by Pydantic. |
| 88 | + """ |
| 89 | + # This simulates the dict that would come from yaml.safe_load() |
| 90 | + raw_config = { |
| 91 | + "host": "localhost", |
| 92 | + "port": 8123, |
| 93 | + "database": "default", |
| 94 | + "user": "default", |
| 95 | + "password": "password", |
| 96 | + "additional_client_args": { |
| 97 | + "send_receive_timeout": 60, |
| 98 | + "compress": True, |
| 99 | + "client_name": "feast_test", |
| 100 | + }, |
| 101 | + } |
| 102 | + |
| 103 | + # Pydantic should parse this dict into a ClickhouseConfig object |
| 104 | + config = ClickhouseConfig(**raw_config) |
| 105 | + |
| 106 | + # Verify all fields are correctly parsed |
| 107 | + assert config.host == "localhost" |
| 108 | + assert config.port == 8123 |
| 109 | + assert config.database == "default" |
| 110 | + assert config.user == "default" |
| 111 | + assert config.password == "password" |
| 112 | + |
| 113 | + # Verify additional_client_args is correctly parsed as a dict |
| 114 | + assert config.additional_client_args is not None |
| 115 | + assert isinstance(config.additional_client_args, dict) |
| 116 | + assert config.additional_client_args["send_receive_timeout"] == 60 |
| 117 | + assert config.additional_client_args["compress"] is True |
| 118 | + assert config.additional_client_args["client_name"] == "feast_test" |
| 119 | + |
| 120 | + |
| 121 | +def test_clickhouse_config_handles_none_additional_client_args(): |
| 122 | + """ |
| 123 | + Test that ClickhouseConfig correctly handles when additional_client_args is not provided. |
| 124 | + """ |
| 125 | + raw_config = { |
| 126 | + "host": "localhost", |
| 127 | + "port": 8123, |
| 128 | + "database": "default", |
| 129 | + "user": "default", |
| 130 | + "password": "password", |
| 131 | + } |
| 132 | + |
| 133 | + config = ClickhouseConfig(**raw_config) |
| 134 | + |
| 135 | + assert config.additional_client_args is None |
0 commit comments