diff --git a/3.snapshot_comparator/tests/test_core.py b/3.snapshot_comparator/tests/test_core.py new file mode 100644 index 0000000..eea3880 --- /dev/null +++ b/3.snapshot_comparator/tests/test_core.py @@ -0,0 +1,55 @@ +import pytest +from snapshot_comparator import core + +@pytest.fixture +def sample_snapshots(): + snapshot1 = [ + {"artifact_key": "A", "status_before": "present", "status_after": "present"}, + {"artifact_key": "B", "status_before": "missing", "status_after": "missing"}, + {"artifact_key": "C", "status_before": "present", "status_after": "missing"}, + ] + snapshot2 = [ + {"artifact_key": "A", "status_before": "present", "status_after": "present"}, + {"artifact_key": "B", "status_before": "missing", "status_after": "present"}, + {"artifact_key": "D", "status_before": "missing", "status_after": "present"}, + ] + return snapshot1, snapshot2 + + +def test_compare_snapshots_basic_diff(sample_snapshots): + snapshot1, snapshot2 = sample_snapshots + result = core.compare_snapshots(snapshot1, snapshot2) + assert isinstance(result, dict) + # Artifact A should remain unchanged + assert 'A' not in result + # Artifact B changes from missing to present + assert 'B' in result + assert result['B']['before'] == 'missing' + assert result['B']['after'] == 'present' + # Artifact C missing in later snapshot + assert 'C' in result + assert result['C']['before'] == 'present' + assert result['C']['after'] == 'missing' + # Artifact D new in later snapshot + assert 'D' in result + assert result['D']['before'] == 'missing' + assert result['D']['after'] == 'present' + + +def test_compare_snapshots_empty_lists(): + result = core.compare_snapshots([], []) + assert result == {} + + +def test_compare_snapshots_identical_snapshots(): + snapshots = [ + {"artifact_key": "A", "status_before": "present", "status_after": "present"}, + {"artifact_key": "B", "status_before": "missing", "status_after": "missing"} + ] + result = core.compare_snapshots(snapshots, snapshots) + assert result == {} + + +def test_compare_snapshots_input_validation(): + with pytest.raises((TypeError, KeyError)): + core.compare_snapshots([{"artifact_key": "X"}], [123]) \ No newline at end of file