-
Notifications
You must be signed in to change notification settings - Fork 113
[Test Improver] test: add unit tests for drift-detection helpers (0% -> ~100%) #727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danielmeppiel
wants to merge
3
commits into
main
Choose a base branch
from
test-assist/drift-detection-coverage-24486614511-e6485df22d208295
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+357
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,357 @@ | ||||||
| """Unit tests for apm_cli.drift -- pure drift-detection helpers. | ||||||
|
|
||||||
| These tests cover detect_ref_change, detect_orphans, detect_config_drift, | ||||||
| and build_download_ref. All four functions are stateless and side-effect-free | ||||||
| so no I/O or network access is required. | ||||||
| """ | ||||||
|
|
||||||
| from __future__ import annotations | ||||||
|
|
||||||
| import unittest | ||||||
| from dataclasses import dataclass, field | ||||||
| from typing import Dict, List, Optional | ||||||
| from unittest.mock import MagicMock | ||||||
|
|
||||||
| from apm_cli.drift import ( | ||||||
| build_download_ref, | ||||||
| detect_config_drift, | ||||||
| detect_orphans, | ||||||
| detect_ref_change, | ||||||
| ) | ||||||
| from apm_cli.models.dependency.reference import DependencyReference | ||||||
|
|
||||||
|
|
||||||
| # --------------------------------------------------------------------------- | ||||||
| # Helpers: minimal LockedDependency stub | ||||||
| # --------------------------------------------------------------------------- | ||||||
|
|
||||||
|
|
||||||
| @dataclass | ||||||
| class _LockedDep: | ||||||
| """Minimal stand-in for LockedDependency to keep tests self-contained.""" | ||||||
|
|
||||||
| repo_url: str = "owner/repo" | ||||||
| resolved_ref: Optional[str] = None | ||||||
| resolved_commit: Optional[str] = None | ||||||
| host: Optional[str] = None | ||||||
| registry_prefix: Optional[str] = None | ||||||
| virtual_path: Optional[str] = None | ||||||
| source: Optional[str] = None | ||||||
| local_path: Optional[str] = None | ||||||
| deployed_files: List[str] = field(default_factory=list) | ||||||
|
|
||||||
| def get_unique_key(self) -> str: | ||||||
| if self.source == "local" and self.local_path: | ||||||
| return self.local_path | ||||||
| if self.virtual_path: | ||||||
| return f"{self.repo_url}/{self.virtual_path}" | ||||||
| return self.repo_url | ||||||
|
|
||||||
|
|
||||||
| @dataclass | ||||||
| class _LockFile: | ||||||
| """Minimal stand-in for LockFile.""" | ||||||
|
|
||||||
| dependencies: Dict[str, _LockedDep] = field(default_factory=dict) | ||||||
|
|
||||||
| def get_dependency(self, key: str) -> Optional[_LockedDep]: | ||||||
| return self.dependencies.get(key) | ||||||
|
|
||||||
|
|
||||||
| def _dep(repo_url: str = "owner/repo", reference: Optional[str] = None) -> DependencyReference: | ||||||
| return DependencyReference(repo_url=repo_url, reference=reference) | ||||||
|
|
||||||
|
|
||||||
| # --------------------------------------------------------------------------- | ||||||
| # detect_ref_change | ||||||
| # --------------------------------------------------------------------------- | ||||||
|
|
||||||
|
|
||||||
| class TestDetectRefChange(unittest.TestCase): | ||||||
| """Tests for detect_ref_change().""" | ||||||
|
|
||||||
| # --- update_refs mode --- | ||||||
|
|
||||||
| def test_update_refs_always_false(self): | ||||||
| """update_refs=True means we intentionally ignore the lockfile.""" | ||||||
| locked = _LockedDep(resolved_ref="v1.0.0") | ||||||
| dep = _dep(reference="v2.0.0") | ||||||
| self.assertFalse(detect_ref_change(dep, locked, update_refs=True)) | ||||||
|
|
||||||
| def test_update_refs_false_no_lockfile(self): | ||||||
|
||||||
| def test_update_refs_false_no_lockfile(self): | |
| def test_update_refs_true_no_lockfile_returns_false(self): |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import: MagicMock is imported but never used in this test module. Please remove it to keep the test file clean and avoid potential lint failures.