RustFS#

Integration with RustFS, a high-performance, S3-compatible object storage service written in Rust.

This integration provides a container-managed RustFS service for testing S3-compatible storage without requiring any additional Python dependencies in the core package.

Installation#

pip install pytest-databases

Install your own S3 client library (for example boto3 or minio) to interact with the service in your tests.

Docker Image#

Note

Current rustfs/rustfs:latest images refuse to start when the root credentials look like documented defaults (e.g. rustfsadmin / rustfsadmin). The shipped defaults use non-default-looking values so the fixture starts cleanly out of the box.

The fixture creates the default bucket with a signed S3 PUT request before yielding. Use RustfsService.endpoint_url as the S3 endpoint and RustfsService.ensure_bucket(name) to create more buckets.

Usage Example#

Using minio:

from minio import Minio
from pytest_databases.docker.rustfs import RustfsService

pytest_plugins = ["pytest_databases.docker.rustfs"]

def test_rustfs_with_minio(rustfs_service: RustfsService, rustfs_default_bucket_name: str) -> None:
    client = Minio(
        endpoint=rustfs_service.endpoint,
        access_key=rustfs_service.access_key,
        secret_key=rustfs_service.secret_key,
        secure=rustfs_service.secure,
    )
    assert client.bucket_exists(rustfs_default_bucket_name)

Using boto3:

import boto3
from pytest_databases.docker.rustfs import RustfsService

pytest_plugins = ["pytest_databases.docker.rustfs"]

def test_rustfs_with_boto3(rustfs_service: RustfsService, rustfs_default_bucket_name: str) -> None:
    s3 = boto3.client(
        "s3",
        endpoint_url=rustfs_service.endpoint_url,
        aws_access_key_id=rustfs_service.access_key,
        aws_secret_access_key=rustfs_service.secret_key,
        region_name="us-east-1",
    )

    response = s3.list_buckets()
    bucket_names = [b["Name"] for b in response["Buckets"]]
    assert rustfs_default_bucket_name in bucket_names

Available Fixtures#

  • rustfs_image: Container image for the RustFS server (default: rustfs/rustfs:latest).

  • rustfs_access_key: Access key for RustFS (default: pytest-databases-rustfs; override via RUSTFS_ACCESS_KEY).

  • rustfs_secret_key: Secret key for RustFS (default: pytest-databases-rustfs-secret; override via RUSTFS_SECRET_KEY).

  • rustfs_secure: Whether to use HTTPS for RustFS (default: False; override via RUSTFS_SECURE).

  • rustfs_default_bucket_name: Default bucket automatically provisioned on startup (default: pytest-databases, suffixed with the worker number under pytest-xdist; override via RUSTFS_DEFAULT_BUCKET_NAME).

  • rustfs_service: Provides a running RustfsService instance.

Service API#

RustFS S3-compatible object storage service fixtures.

class pytest_databases.docker.rustfs.RustfsService(container: docker.models.containers.Container, host: str, port: int, endpoint: str, access_key: str, secret_key: str, secure: bool)[source]#

Bases: ServiceContainer

Service container for RustFS object storage.

endpoint: str#
access_key: str#
secret_key: str#
secure: bool#
property endpoint_url: str#

S3 endpoint URL, https when secure is set.

ensure_bucket(bucket_name: str) → None[source]#

Create bucket_name unless it already exists.

Parameters:

bucket_name – Bucket to create.

__init__(container: docker.models.containers.Container, host: str, port: int, endpoint: str, access_key: str, secret_key: str, secure: bool) → None#
pytest_databases.docker.rustfs.provide_rustfs_service(docker_service: DockerService, *, access_key: str, secret_key: str, secure: bool, default_bucket_name: str, isolation_level: XdistIsolationLevel, image: str = 'rustfs/rustfs:latest') → Generator[RustfsService, None, None][source]#

Start a RustFS service container and create the default bucket with a SigV4-signed request.

Yields:

RustfsService – Started RustFS container service metadata.

pytest_databases.docker.rustfs.rustfs_access_key() → str[source]#

Default RustFS root access key.

pytest_databases.docker.rustfs.rustfs_default_bucket_name(xdist_rustfs_isolation_level: Literal['database', 'server']) → str[source]#

Default bucket name provisioned on startup, isolated per pytest-xdist worker.

pytest_databases.docker.rustfs.rustfs_image() → str[source]#

Default RustFS container image.

pytest_databases.docker.rustfs.rustfs_secret_key() → str[source]#

Default RustFS root secret key.

pytest_databases.docker.rustfs.rustfs_secure() → bool[source]#

Whether RustFS connections use HTTPS.

pytest_databases.docker.rustfs.rustfs_service(docker_service: DockerService, rustfs_access_key: str, rustfs_secret_key: str, rustfs_secure: bool, rustfs_default_bucket_name: str, xdist_rustfs_isolation_level: XdistIsolationLevel, rustfs_image: str) → Generator[RustfsService, None, None][source]#

Start a RustFS service container and provision the default bucket.

Yields:

RustfsService – Started RustFS container service metadata.

pytest_databases.docker.rustfs.xdist_rustfs_isolation_level() → Literal['database', 'server'][source]#

Default pytest-xdist isolation level for RustFS.