Initial upload: snippet-manager with CI/CD workflow
Some checks failed
CI / test (push) Failing after 18s
CI / lint (push) Failing after 7s

This commit is contained in:
2026-03-22 11:22:39 +00:00
parent 190b274945
commit 9c53349b6a

45
tests/test_sync.py Normal file
View File

@@ -0,0 +1,45 @@
"""Tests for P2P sync functionality."""
import os
import tempfile
import pytest
from snip.db.database import Database
from snip.sync.protocol import SyncProtocol
@pytest.fixture
def db():
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
db_path = f.name
database = Database(db_path)
database.init_db()
yield database
os.unlink(db_path)
@pytest.fixture
def sync_protocol(db):
return SyncProtocol(db, port=18765)
def test_sync_protocol_init(sync_protocol):
"""Test sync protocol initialization."""
assert sync_protocol.port == 18765
assert sync_protocol.server is None
def test_start_stop_server(sync_protocol):
"""Test starting and stopping the sync server."""
sync_protocol.start_server()
assert sync_protocol.server is not None
sync_protocol.stop_server()
assert sync_protocol.server is None
def test_sync_with_peer_no_connection(sync_protocol, db):
"""Test sync with unreachable peer."""
synced = sync_protocol.sync_with_peer("127.0.0.1", 9999)
assert synced == 0