"""Tests for mgf-cloud's exception types (Pass 2)."""

from __future__ import annotations

from mgf.common.exceptions import AppError, ConfigError

from mgf.cloud import exceptions as exc
from mgf.cloud.exceptions import CredentialsError, ProviderNotFoundError


def test_credentials_error_carries_machine_readable_fields() -> None:
    err = CredentialsError("no creds", source="env", missing=("auth_url",))
    assert err.source == "env"
    assert err.missing == ("auth_url",)
    assert isinstance(err, ConfigError)
    assert isinstance(err, AppError)
    assert "no creds" in str(err)


def test_provider_not_found_lists_available() -> None:
    err = ProviderNotFoundError("bogus", ("fake", "infomaniak"))
    assert err.provider == "bogus"
    assert err.available == ("fake", "infomaniak")
    assert "bogus" in str(err)
    assert "fake" in str(err)
    assert isinstance(err, ConfigError)


def test_federation_exceptions_are_reexported() -> None:
    for name in (
        "ProviderError",
        "ResourceNotFoundError",
        "ResourceAlreadyExistsError",
        "OperationError",
        "ConfigError",
    ):
        assert hasattr(exc, name), name
