|
14 | 14 | """ |
15 | 15 |
|
16 | 16 | from unittest import TestCase |
17 | | -from unittest.mock import patch |
| 17 | +from unittest.mock import MagicMock, patch |
18 | 18 |
|
19 | 19 | from metadata.generated.schema.metadataIngestion.workflow import ( |
20 | 20 | OpenMetadataWorkflowConfig, |
@@ -135,3 +135,80 @@ def test_iceberg_relkind_mapping(self): |
135 | 135 | from metadata.ingestion.source.database.starrocks.metadata import RELKIND_MAP |
136 | 136 |
|
137 | 137 | assert RELKIND_MAP["ICEBERG"] == TableType.Iceberg |
| 138 | + |
| 139 | + |
| 140 | +class TestStarRocksGetTableDescription(TestCase): |
| 141 | + """Tests for get_table_description querying INFORMATION_SCHEMA directly (fixes #26692)""" |
| 142 | + |
| 143 | + @patch( |
| 144 | + "metadata.ingestion.source.database.common_db_source.CommonDbSourceService.test_connection" |
| 145 | + ) |
| 146 | + def setUp(self, test_connection): |
| 147 | + test_connection.return_value = False |
| 148 | + self.config = OpenMetadataWorkflowConfig.model_validate(mock_starrocks_config) |
| 149 | + self.source = StarRocksSource.create( |
| 150 | + mock_starrocks_config["source"], |
| 151 | + self.config.workflowConfig.openMetadataServerConfig, |
| 152 | + ) |
| 153 | + |
| 154 | + @patch( |
| 155 | + "metadata.ingestion.source.database.common_db_source.CommonDbSourceService.connection" |
| 156 | + ) |
| 157 | + def test_returns_table_comment(self, mock_connection): |
| 158 | + mock_result = MagicMock() |
| 159 | + mock_result.first.return_value = ("审计日志表",) |
| 160 | + mock_connection.execute.return_value = mock_result |
| 161 | + self.source.connection = mock_connection |
| 162 | + |
| 163 | + description = self.source.get_table_description( |
| 164 | + schema_name="test_db", |
| 165 | + table_name="audit_tbl", |
| 166 | + inspector=MagicMock(), |
| 167 | + ) |
| 168 | + assert description == "审计日志表" |
| 169 | + |
| 170 | + @patch( |
| 171 | + "metadata.ingestion.source.database.common_db_source.CommonDbSourceService.connection" |
| 172 | + ) |
| 173 | + def test_returns_none_for_empty_comment(self, mock_connection): |
| 174 | + mock_result = MagicMock() |
| 175 | + mock_result.first.return_value = ("",) |
| 176 | + mock_connection.execute.return_value = mock_result |
| 177 | + self.source.connection = mock_connection |
| 178 | + |
| 179 | + description = self.source.get_table_description( |
| 180 | + schema_name="test_db", |
| 181 | + table_name="no_comment_tbl", |
| 182 | + inspector=MagicMock(), |
| 183 | + ) |
| 184 | + assert description is None |
| 185 | + |
| 186 | + @patch( |
| 187 | + "metadata.ingestion.source.database.common_db_source.CommonDbSourceService.connection" |
| 188 | + ) |
| 189 | + def test_returns_none_when_no_row(self, mock_connection): |
| 190 | + mock_result = MagicMock() |
| 191 | + mock_result.first.return_value = None |
| 192 | + mock_connection.execute.return_value = mock_result |
| 193 | + self.source.connection = mock_connection |
| 194 | + |
| 195 | + description = self.source.get_table_description( |
| 196 | + schema_name="test_db", |
| 197 | + table_name="missing_tbl", |
| 198 | + inspector=MagicMock(), |
| 199 | + ) |
| 200 | + assert description is None |
| 201 | + |
| 202 | + @patch( |
| 203 | + "metadata.ingestion.source.database.common_db_source.CommonDbSourceService.connection" |
| 204 | + ) |
| 205 | + def test_returns_none_on_exception(self, mock_connection): |
| 206 | + mock_connection.execute.side_effect = Exception("connection error") |
| 207 | + self.source.connection = mock_connection |
| 208 | + |
| 209 | + description = self.source.get_table_description( |
| 210 | + schema_name="test_db", |
| 211 | + table_name="error_tbl", |
| 212 | + inspector=MagicMock(), |
| 213 | + ) |
| 214 | + assert description is None |
0 commit comments