46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
import tempfile
|
|
import unittest
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path, PurePosixPath
|
|
|
|
from archive_clients.config import RootMapping
|
|
from archive_clients.routes import discover_routes
|
|
from archive_control.v1 import route_pb2
|
|
|
|
|
|
class RouteDiscoveryTests(unittest.TestCase):
|
|
def test_pairwise_routes_are_discovered_and_unsafe_folders_ignored(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
roots = RootMapping(PurePosixPath("/sync"), Path(directory))
|
|
configuration = {"folders": [
|
|
{
|
|
"id": "route-b", "path": "/sync/routes/b",
|
|
"type": "sendreceive",
|
|
"devices": [{"deviceID": "LOCAL"}, {"deviceID": "PEER"}],
|
|
"label": "Archive Control route-b",
|
|
},
|
|
{
|
|
"id": "route-a", "path": "/sync/routes/a",
|
|
"type": "sendonly",
|
|
"devices": [{"deviceID": "LOCAL"}, {"deviceID": "PEER"}],
|
|
},
|
|
{
|
|
"id": "outside", "path": "/other/path",
|
|
"type": "sendreceive", "devices": [],
|
|
},
|
|
]}
|
|
routes = discover_routes(
|
|
configuration, "LOCAL", roots, True,
|
|
datetime(2026, 1, 2, tzinfo=timezone.utc),
|
|
)
|
|
self.assertEqual([route.route_id for route in routes], ["route-a", "route-b"])
|
|
self.assertEqual(routes[0].state, route_pb2.ROUTE_STATE_UNSUPPORTED)
|
|
self.assertEqual(routes[1].state, route_pb2.ROUTE_STATE_DISCOVERED)
|
|
self.assertEqual(list(routes[1].peer_syncthing_device_ids), ["PEER"])
|
|
self.assertEqual(routes[1].local_relative_path, "routes/b")
|
|
self.assertFalse(routes[1].archive_control_created)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|