Add remaining test files: test_merge, test_sync, test_validate
This commit is contained in:
81
confsync/tests/test_sync.py
Normal file
81
confsync/tests/test_sync.py
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
"""Tests for sync operations."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
class TestGitOperations:
|
||||||
|
"""Tests for Git operations."""
|
||||||
|
|
||||||
|
def test_git_manager_init(self):
|
||||||
|
"""Test GitManager initialization."""
|
||||||
|
from confsync.utils.git_utils import GitManager
|
||||||
|
|
||||||
|
git = GitManager()
|
||||||
|
assert git.repo_path is None
|
||||||
|
|
||||||
|
git = GitManager(repo_path="/test/repo")
|
||||||
|
assert git.repo_path == "/test/repo"
|
||||||
|
|
||||||
|
|
||||||
|
class TestSyncManager:
|
||||||
|
"""Tests for sync manager operations."""
|
||||||
|
|
||||||
|
def test_sync_operation_enum(self):
|
||||||
|
"""Test SyncOperation enum values."""
|
||||||
|
from confsync.models.config_models import SyncOperation
|
||||||
|
|
||||||
|
assert SyncOperation.PUSH.value == "push"
|
||||||
|
assert SyncOperation.PULL.value == "pull"
|
||||||
|
assert SyncOperation.SYNC.value == "sync"
|
||||||
|
assert SyncOperation.STATUS.value == "status"
|
||||||
|
|
||||||
|
|
||||||
|
class TestSyncWorkflows:
|
||||||
|
"""Tests for sync workflows."""
|
||||||
|
|
||||||
|
def test_create_encrypted_manifest(self):
|
||||||
|
"""Test creating encrypted manifest."""
|
||||||
|
from confsync.core.manifest import ManifestBuilder
|
||||||
|
from confsync.utils.encryption import EncryptionManager
|
||||||
|
from confsync.models.config_models import ConfigFile, ConfigCategory
|
||||||
|
|
||||||
|
builder = ManifestBuilder()
|
||||||
|
|
||||||
|
config = ConfigFile(
|
||||||
|
path="/test/.vimrc",
|
||||||
|
name=".vimrc",
|
||||||
|
category=ConfigCategory.EDITOR,
|
||||||
|
tool_name="vim",
|
||||||
|
content="set nocompatible",
|
||||||
|
)
|
||||||
|
|
||||||
|
builder.build_from_detected([config])
|
||||||
|
|
||||||
|
enc_manager = EncryptionManager(passphrase="test_key")
|
||||||
|
encrypted = enc_manager.encrypt_manifest("test manifest data")
|
||||||
|
|
||||||
|
assert isinstance(encrypted, str)
|
||||||
|
assert len(encrypted) > 0
|
||||||
|
|
||||||
|
|
||||||
|
class TestSyncIntegration:
|
||||||
|
"""Integration tests for sync operations."""
|
||||||
|
|
||||||
|
def test_sync_with_mocked_git(self):
|
||||||
|
"""Test sync with mocked Git operations."""
|
||||||
|
from confsync.models.config_models import SyncMetadata, SyncOperation
|
||||||
|
|
||||||
|
metadata = SyncMetadata(
|
||||||
|
operation=SyncOperation.PUSH,
|
||||||
|
source="/local/configs",
|
||||||
|
destination="https://github.com/user/configs.git",
|
||||||
|
committed_files=[".vimrc", ".bashrc"],
|
||||||
|
status="pending",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert metadata.operation == SyncOperation.PUSH
|
||||||
|
assert len(metadata.committed_files) == 2
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
pytest.main([__file__, "-v"])
|
||||||
Reference in New Issue
Block a user