-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add label interpolation to repo baseurl
Fixes: #36
- Loading branch information
Showing
4 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,54 @@ | ||
from unittest.mock import patch | ||
|
||
from rpm_lockfile.content_origin import Repo | ||
from rpm_lockfile.content_origin.repos import RepoOrigin | ||
|
||
|
||
def test_collect_simple(tmpdir): | ||
baseurl = "https://example.com/repo" | ||
config = [{"repoid": "a", "baseurl": baseurl}] | ||
origin = RepoOrigin(tmpdir) | ||
repos = list(origin.collect(config)) | ||
|
||
assert repos == [Repo(repoid="a", baseurl=baseurl)] | ||
|
||
|
||
LABELS = { | ||
"vcs-ref": "abcdef", | ||
"architecture": "x86_64", | ||
} | ||
|
||
TEMPLATE_CONFIG = { | ||
"repoid": "a", "baseurl": "https://example.com/{architecture}/repo" | ||
} | ||
EXPANDED_REPO = Repo(repoid="a", baseurl="https://example.com/x86_64/repo") | ||
|
||
|
||
def test_collect_with_vars_from_image(tmpdir): | ||
origin = RepoOrigin(tmpdir) | ||
image = "registry.example.com/image:latest" | ||
|
||
with patch("rpm_lockfile.utils.get_labels") as mock_get_labels: | ||
mock_get_labels.return_value = LABELS | ||
repos = list(origin.collect([TEMPLATE_CONFIG | {"varsFromImage": image}])) | ||
|
||
assert repos == [EXPANDED_REPO] | ||
mock_get_labels.assert_called_once_with(image, None) | ||
|
||
|
||
def test_collect_with_vars_from_containerfile(tmpdir): | ||
origin = RepoOrigin(tmpdir) | ||
(tmpdir / "Containerfile").write_text( | ||
"FROM registry.example.com/image:latest\nRUN date\n", encoding="utf-8" | ||
) | ||
|
||
with patch("rpm_lockfile.utils.get_labels") as mock_get_labels: | ||
mock_get_labels.return_value = LABELS | ||
repos = list( | ||
origin.collect( | ||
[TEMPLATE_CONFIG | {"varsFromContainerfile": "Containerfile"}] | ||
) | ||
) | ||
|
||
assert repos == [EXPANDED_REPO] | ||
mock_get_labels.assert_called_once_with(None, tmpdir / "Containerfile") |