|
15 | 15 | from borgstore.backends.rest import get_rest_backend |
16 | 16 | from borgstore.backends.posixfs import get_file_backend |
17 | 17 | from borgstore.backends.errors import ObjectNotFound, BackendAlreadyExists, QuotaExceeded |
18 | | -from borgstore.store import get_backend |
| 18 | +from borgstore.store import get_backend, Store |
19 | 19 |
|
20 | 20 |
|
21 | 21 | def start_server(backend_url, address, port, username=None, password=None, permissions=None, quota=None): |
@@ -652,3 +652,45 @@ def do_request(method, path, body=b""): |
652 | 652 | proc.wait(timeout=2) |
653 | 653 | except subprocess.TimeoutExpired: |
654 | 654 | proc.kill() |
| 655 | + |
| 656 | + |
| 657 | +def test_rest_url(tmp_path): |
| 658 | + repo_path = tmp_path / "repo" |
| 659 | + # Use rest: URL with stdio backend (empty host) |
| 660 | + url = f"rest:///{repo_path}" |
| 661 | + |
| 662 | + # Use levels=0 to avoid root nesting issues if they arise |
| 663 | + config = {"": {"levels": [0]}} |
| 664 | + store = Store(url, config=config) |
| 665 | + store.create() |
| 666 | + |
| 667 | + with store: |
| 668 | + item_name = "test-item" |
| 669 | + item_data = b"some data" |
| 670 | + store.store(item_name, item_data) |
| 671 | + |
| 672 | + # Test Store.info which calls Backend.info (HEAD) |
| 673 | + # This used to hang. |
| 674 | + info = store.info(item_name) |
| 675 | + assert info.exists |
| 676 | + assert info.size == len(item_data) |
| 677 | + assert info.atime > 0 |
| 678 | + |
| 679 | + # Test listing |
| 680 | + items = list(store.list("")) |
| 681 | + assert len(items) == 1 |
| 682 | + assert items[0].name == item_name |
| 683 | + assert items[0].atime > 0 |
| 684 | + |
| 685 | + # Test nonexistent item |
| 686 | + # This also used to hang if it returned a 404 with a body. |
| 687 | + info_none = store.info("nonexistent") |
| 688 | + assert not info_none.exists |
| 689 | + assert info_none.size == 0 |
| 690 | + |
| 691 | + # Test directory info (root) |
| 692 | + info_root = store.info("") |
| 693 | + assert info_root.exists |
| 694 | + assert info_root.directory |
| 695 | + |
| 696 | + store.destroy() |
0 commit comments