You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
3.7 KiB
132 lines
3.7 KiB
import pytest
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_list_backends_returns_default_local_backend(api_client) -> None:
|
|
response = await api_client.get("/api/backends")
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert len(payload["items"]) >= 1
|
|
assert payload["items"][0]["name"] == "local-default"
|
|
assert payload["items"][0]["type"] == "local"
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_create_local_backend(api_client, runtime_paths) -> None:
|
|
response = await api_client.post(
|
|
"/api/backends",
|
|
json={
|
|
"name": "archive-local",
|
|
"type": "local",
|
|
"stability_class": "stable",
|
|
"read_priority": 50,
|
|
"write_priority": 50,
|
|
"config": {
|
|
"base_path": runtime_paths["local_storage_dir"] + "/archive",
|
|
},
|
|
},
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()["backend"]
|
|
assert payload["name"] == "archive-local"
|
|
assert payload["type"] == "local"
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_create_s3_backend_metadata(api_client) -> None:
|
|
response = await api_client.post(
|
|
"/api/backends",
|
|
json={
|
|
"name": "s3-main",
|
|
"type": "s3",
|
|
"stability_class": "stable",
|
|
"read_priority": 80,
|
|
"write_priority": 80,
|
|
"config": {
|
|
"bucket": "iron-test",
|
|
"region": "us-east-1",
|
|
},
|
|
},
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()["backend"]
|
|
assert payload["name"] == "s3-main"
|
|
assert payload["type"] == "s3"
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_check_local_backend(api_client) -> None:
|
|
list_response = await api_client.get("/api/backends")
|
|
backend_id = list_response.json()["items"][0]["id"]
|
|
|
|
response = await api_client.post(f"/api/backends/{backend_id}/check")
|
|
|
|
assert response.status_code == 200
|
|
assert response.json()["status"] == "healthy"
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_check_s3_backend_returns_healthy(api_client, fake_s3) -> None:
|
|
create_response = await api_client.post(
|
|
"/api/backends",
|
|
json={
|
|
"name": "s3-main",
|
|
"type": "s3",
|
|
"stability_class": "stable",
|
|
"read_priority": 80,
|
|
"write_priority": 80,
|
|
"config": {
|
|
"bucket": "iron-test",
|
|
},
|
|
},
|
|
)
|
|
backend_id = create_response.json()["backend"]["id"]
|
|
|
|
response = await api_client.post(f"/api/backends/{backend_id}/check")
|
|
|
|
assert response.status_code == 200
|
|
assert response.json()["status"] == "healthy"
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_disable_backend(api_client) -> None:
|
|
create_response = await api_client.post(
|
|
"/api/backends",
|
|
json={
|
|
"name": "archive-local",
|
|
"type": "local",
|
|
"stability_class": "stable",
|
|
"read_priority": 50,
|
|
"write_priority": 50,
|
|
"config": {
|
|
"base_path": "/tmp/archive-local",
|
|
},
|
|
},
|
|
)
|
|
backend_id = create_response.json()["backend"]["id"]
|
|
|
|
response = await api_client.post(f"/api/backends/{backend_id}/disable")
|
|
|
|
assert response.status_code == 200
|
|
assert response.json()["backend"]["is_enabled"] is False
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_create_backend_rejects_invalid_config(api_client) -> None:
|
|
response = await api_client.post(
|
|
"/api/backends",
|
|
json={
|
|
"name": "bad-s3",
|
|
"type": "s3",
|
|
"stability_class": "stable",
|
|
"read_priority": 10,
|
|
"write_priority": 10,
|
|
"config": {},
|
|
},
|
|
)
|
|
|
|
assert response.status_code == 400
|
|
assert response.json()["error"]["code"] == "backend_config_invalid"
|
|
|