|
1 | | -from typing import Callable |
| 1 | +from typing import Callable, Union |
2 | 2 |
|
3 | 3 | from httpx import Request |
4 | 4 | from pytest import mark, raises |
5 | 5 | from pytest_httpx import HTTPXMock |
6 | 6 |
|
7 | 7 | from firebolt.model.V2.database import Database |
8 | 8 | from firebolt.model.V2.engine import Engine, EngineStatus |
| 9 | +from firebolt.model.V2.instance_type import InstanceType |
9 | 10 | from firebolt.service.manager import ResourceManager |
10 | 11 | from firebolt.utils.exception import EngineNotFoundError |
11 | 12 | from tests.unit.response import Response |
@@ -219,3 +220,59 @@ def test_engine_new_status( |
219 | 220 | engine = resource_manager.engines.get_by_name(mock_engine.name) |
220 | 221 |
|
221 | 222 | assert engine.current_status == expected_status |
| 223 | + |
| 224 | + |
| 225 | +@mark.parametrize( |
| 226 | + "spec_input, expected_spec, status_input, expected_status", |
| 227 | + [ |
| 228 | + # Test all valid InstanceType values |
| 229 | + ("S", InstanceType.S, "RUNNING", EngineStatus.RUNNING), |
| 230 | + ("M", InstanceType.M, "STOPPED", EngineStatus.STOPPED), |
| 231 | + ("L", InstanceType.L, "STARTING", EngineStatus.STARTING), |
| 232 | + ("XL", InstanceType.XL, "STOPPING", EngineStatus.STOPPING), |
| 233 | + # Test InstanceType enum values directly |
| 234 | + (InstanceType.S, InstanceType.S, "FAILED", EngineStatus.FAILED), |
| 235 | + (InstanceType.M, InstanceType.M, "REPAIRING", EngineStatus.REPAIRING), |
| 236 | + # Test unknown/invalid values that should default to UNKNOWN |
| 237 | + ("INVALID_TYPE", InstanceType.UNKNOWN, "INVALID_STATUS", EngineStatus.UNKNOWN), |
| 238 | + ("XXL", InstanceType.UNKNOWN, "WEIRD_STATE", EngineStatus.UNKNOWN), |
| 239 | + # Test empty strings that should default to UNKNOWN |
| 240 | + ("", InstanceType.UNKNOWN, "", EngineStatus.UNKNOWN), |
| 241 | + # Test all valid EngineStatus values with M instance type |
| 242 | + ("M", InstanceType.M, "STARTED", EngineStatus.STARTED), |
| 243 | + ("M", InstanceType.M, "DROPPING", EngineStatus.DROPPING), |
| 244 | + ("M", InstanceType.M, "DELETING", EngineStatus.DELETING), |
| 245 | + ("M", InstanceType.M, "RESIZING", EngineStatus.RESIZING), |
| 246 | + ("M", InstanceType.M, "DRAINING", EngineStatus.DRAINING), |
| 247 | + ], |
| 248 | +) |
| 249 | +def test_engine_instantiation_with_different_configurations( |
| 250 | + spec_input: Union[str, InstanceType], |
| 251 | + expected_spec: InstanceType, |
| 252 | + status_input: str, |
| 253 | + expected_status: EngineStatus, |
| 254 | +) -> None: |
| 255 | + """ |
| 256 | + Test that Engine model correctly handles different instance types and statuses, |
| 257 | + including unknown values and empty strings that should default to UNKNOWN. |
| 258 | + """ |
| 259 | + engine = Engine( |
| 260 | + name="test_engine", |
| 261 | + region="us-east-1", |
| 262 | + spec=spec_input, |
| 263 | + scale=2, |
| 264 | + current_status=status_input, |
| 265 | + version="1.0", |
| 266 | + endpoint="https://test.endpoint.com", |
| 267 | + warmup="", |
| 268 | + auto_stop=3600, |
| 269 | + type="general_purpose", |
| 270 | + _database_name="test_db", |
| 271 | + _service=None, |
| 272 | + ) |
| 273 | + |
| 274 | + assert engine.spec == expected_spec |
| 275 | + assert engine.current_status == expected_status |
| 276 | + assert engine.name == "test_engine" |
| 277 | + assert engine.region == "us-east-1" |
| 278 | + assert engine.scale == 2 |
0 commit comments