|
3 | 3 | from collections.abc import AsyncGenerator, Generator |
4 | 4 | from contextlib import suppress |
5 | 5 | from pathlib import Path |
6 | | -from typing import Optional |
| 6 | +from typing import Any, Optional |
7 | 7 |
|
8 | 8 | import pytest |
9 | 9 | import pytest_asyncio |
10 | | -from minio import Minio # type: ignore[import-untyped] |
11 | | -from pytest_databases.docker.minio import MinioService |
| 10 | +from pytest_databases.docker.rustfs import RustfsService |
12 | 11 | from sqlalchemy import Engine, String, event |
13 | 12 | from sqlalchemy.exc import InvalidRequestError |
14 | 13 | from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker |
@@ -59,6 +58,33 @@ def remove_listeners() -> None: |
59 | 58 | set_async_context(False) |
60 | 59 |
|
61 | 60 |
|
| 61 | +def rustfs_endpoint_url(rustfs_service: RustfsService) -> str: |
| 62 | + scheme = "https" if rustfs_service.secure else "http" |
| 63 | + return f"{scheme}://{rustfs_service.endpoint}" |
| 64 | + |
| 65 | + |
| 66 | +def rustfs_s3_filesystem(rustfs_service: RustfsService, **kwargs: Any) -> Any: |
| 67 | + s3fs = pytest.importorskip("s3fs") |
| 68 | + return s3fs.S3FileSystem( |
| 69 | + anon=False, |
| 70 | + key=rustfs_service.access_key, |
| 71 | + secret=rustfs_service.secret_key, |
| 72 | + endpoint_url=rustfs_endpoint_url(rustfs_service), |
| 73 | + client_kwargs={ |
| 74 | + "verify": rustfs_service.secure, |
| 75 | + "use_ssl": rustfs_service.secure, |
| 76 | + }, |
| 77 | + config_kwargs={"s3": {"addressing_style": "path"}}, |
| 78 | + **kwargs, |
| 79 | + ) |
| 80 | + |
| 81 | + |
| 82 | +def ensure_rustfs_bucket(rustfs_service: RustfsService, bucket_name: str) -> None: |
| 83 | + fs = rustfs_s3_filesystem(rustfs_service, asynchronous=False, loop=None) |
| 84 | + with suppress(FileExistsError): |
| 85 | + fs.mkdir(bucket_name) |
| 86 | + |
| 87 | + |
62 | 88 | # --- Fixtures --- |
63 | 89 | orm_registry = create_registry() |
64 | 90 |
|
@@ -229,37 +255,20 @@ async def async_session( |
229 | 255 | ) |
230 | 256 | async def test_fsspec_s3_basic_operations_async( |
231 | 257 | storage_registry: StorageRegistry, |
232 | | - minio_client: "Minio", |
233 | | - minio_service: "MinioService", |
234 | | - minio_default_bucket_name: str, |
| 258 | + rustfs_service: RustfsService, |
| 259 | + rustfs_default_bucket_name: str, |
235 | 260 | ) -> None: |
236 | 261 | """Test basic save, get_content, delete via backend and FileObject with prefix.""" |
237 | 262 | remove_listeners() |
238 | | - try: |
239 | | - import s3fs |
240 | | - except ImportError: |
241 | | - pytest.skip("s3fs not installed") |
242 | 263 |
|
243 | | - assert minio_client.bucket_exists(minio_default_bucket_name) |
244 | | - _ = minio_client |
245 | | - |
246 | | - # Create s3fs filesystem instance without bucket info |
247 | | - fs = s3fs.S3FileSystem( |
248 | | - anon=False, |
249 | | - key=minio_service.access_key, |
250 | | - secret=minio_service.secret_key, |
251 | | - endpoint_url=f"http://{minio_service.endpoint}", |
252 | | - client_kwargs={ |
253 | | - "verify": False, |
254 | | - "use_ssl": False, |
255 | | - }, |
256 | | - ) |
| 264 | + ensure_rustfs_bucket(rustfs_service, rustfs_default_bucket_name) |
| 265 | + fs = rustfs_s3_filesystem(rustfs_service) |
257 | 266 |
|
258 | 267 | # Initialize backend with prefix |
259 | 268 | backend = FSSpecBackend( |
260 | 269 | key="s3_test_store", |
261 | 270 | fs=fs, |
262 | | - prefix=minio_default_bucket_name, |
| 271 | + prefix=rustfs_default_bucket_name, |
263 | 272 | ) |
264 | 273 |
|
265 | 274 | test_content = b"Hello Storage!" |
@@ -311,39 +320,24 @@ async def test_fsspec_s3_basic_operations_async( |
311 | 320 | ) |
312 | 321 | def test_fsspec_s3_basic_operations_sync( |
313 | 322 | storage_registry: StorageRegistry, |
314 | | - minio_client: "Minio", |
315 | | - minio_service: "MinioService", |
316 | | - minio_default_bucket_name: str, |
| 323 | + rustfs_service: RustfsService, |
| 324 | + rustfs_default_bucket_name: str, |
317 | 325 | ) -> None: |
318 | 326 | """Test basic save, get_content, delete via backend and FileObject with prefix.""" |
319 | 327 | remove_listeners() |
320 | | - try: |
321 | | - import s3fs |
322 | | - except ImportError: |
323 | | - pytest.skip("s3fs not installed") |
324 | | - |
325 | | - assert minio_client.bucket_exists(minio_default_bucket_name) |
326 | | - _ = minio_client |
327 | 328 |
|
328 | | - # Create s3fs filesystem instance without bucket info |
329 | | - fs = s3fs.S3FileSystem( |
330 | | - anon=False, |
331 | | - key=minio_service.access_key, |
332 | | - secret=minio_service.secret_key, |
333 | | - endpoint_url=f"http://{minio_service.endpoint}", |
334 | | - client_kwargs={ |
335 | | - "verify": False, |
336 | | - "use_ssl": False, |
337 | | - }, |
| 329 | + fs = rustfs_s3_filesystem( |
| 330 | + rustfs_service, |
338 | 331 | asynchronous=False, |
339 | 332 | loop=None, |
340 | 333 | ) |
| 334 | + ensure_rustfs_bucket(rustfs_service, rustfs_default_bucket_name) |
341 | 335 |
|
342 | 336 | # Initialize backend with prefix |
343 | 337 | backend = FSSpecBackend( |
344 | 338 | key="s3_test_store", |
345 | 339 | fs=fs, |
346 | | - prefix=minio_default_bucket_name, |
| 340 | + prefix=rustfs_default_bucket_name, |
347 | 341 | ) |
348 | 342 |
|
349 | 343 | test_content = b"Hello Storage!" |
@@ -391,22 +385,21 @@ def test_fsspec_s3_basic_operations_sync( |
391 | 385 | @pytest.mark.xdist_group("file_object") |
392 | 386 | async def test_obstore_s3_basic_operations_async( |
393 | 387 | storage_registry: StorageRegistry, |
394 | | - minio_client: "Minio", |
395 | | - minio_service: "MinioService", |
396 | | - minio_default_bucket_name: str, |
| 388 | + rustfs_service: RustfsService, |
| 389 | + rustfs_default_bucket_name: str, |
397 | 390 | ) -> None: |
398 | 391 | """Test basic save, get_content, delete via backend and FileObject.""" |
399 | 392 | remove_listeners() |
400 | | - assert minio_client.bucket_exists(minio_default_bucket_name) |
401 | | - _ = minio_client |
| 393 | + endpoint_url = rustfs_endpoint_url(rustfs_service) |
| 394 | + ensure_rustfs_bucket(rustfs_service, rustfs_default_bucket_name) |
402 | 395 | backend = ObstoreBackend( |
403 | 396 | key="s3_test_store", |
404 | | - fs=f"s3://{minio_default_bucket_name}/", |
405 | | - aws_endpoint=f"http://{minio_service.endpoint}/", |
406 | | - aws_access_key_id=minio_service.access_key, |
407 | | - aws_secret_access_key=minio_service.secret_key, |
| 397 | + fs=f"s3://{rustfs_default_bucket_name}/", |
| 398 | + aws_endpoint=f"{endpoint_url}/", |
| 399 | + aws_access_key_id=rustfs_service.access_key, |
| 400 | + aws_secret_access_key=rustfs_service.secret_key, |
408 | 401 | aws_virtual_hosted_style_request=False, |
409 | | - client_options={"allow_http": True}, |
| 402 | + client_options={"allow_http": not rustfs_service.secure}, |
410 | 403 | ) |
411 | 404 |
|
412 | 405 | test_content = b"Hello Storage!" |
@@ -456,22 +449,21 @@ async def test_obstore_s3_basic_operations_async( |
456 | 449 | @pytest.mark.xdist_group("file_object") |
457 | 450 | def test_obstore_s3_basic_operations_sync( |
458 | 451 | storage_registry: StorageRegistry, |
459 | | - minio_client: "Minio", |
460 | | - minio_service: "MinioService", |
461 | | - minio_default_bucket_name: str, |
| 452 | + rustfs_service: RustfsService, |
| 453 | + rustfs_default_bucket_name: str, |
462 | 454 | ) -> None: |
463 | 455 | """Test basic save, get_content, delete via backend and FileObject.""" |
464 | 456 | remove_listeners() |
465 | | - assert minio_client.bucket_exists(minio_default_bucket_name) |
466 | | - _ = minio_client |
| 457 | + endpoint_url = rustfs_endpoint_url(rustfs_service) |
| 458 | + ensure_rustfs_bucket(rustfs_service, rustfs_default_bucket_name) |
467 | 459 | backend = ObstoreBackend( |
468 | 460 | key="s3_test_store", |
469 | | - fs=f"s3://{minio_default_bucket_name}/", |
470 | | - aws_endpoint=f"http://{minio_service.endpoint}/", |
471 | | - aws_access_key_id=minio_service.access_key, |
472 | | - aws_secret_access_key=minio_service.secret_key, |
| 461 | + fs=f"s3://{rustfs_default_bucket_name}/", |
| 462 | + aws_endpoint=f"{endpoint_url}/", |
| 463 | + aws_access_key_id=rustfs_service.access_key, |
| 464 | + aws_secret_access_key=rustfs_service.secret_key, |
473 | 465 | aws_virtual_hosted_style_request=False, |
474 | | - client_options={"allow_http": True}, |
| 466 | + client_options={"allow_http": not rustfs_service.secure}, |
475 | 467 | ) |
476 | 468 |
|
477 | 469 | test_content = b"Hello Storage!" |
|
0 commit comments