-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config file generation for RubyGems
SPMM-9901 Signed-off-by: Milan Tichavský <[email protected]>
- Loading branch information
1 parent
76f509d
commit 07f5cb1
Showing
4 changed files
with
191 additions
and
17 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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
import base64 | ||
from pathlib import Path | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from cachito.errors import CachitoError | ||
from cachito.workers.tasks import rubygems | ||
|
||
|
||
|
@@ -12,3 +18,55 @@ def test_cleanup_rubygems_request(mock_exec_script): | |
"username": "cachito-rubygems-42", | ||
} | ||
mock_exec_script.assert_called_once_with("rubygems_cleanup", expected_payload) | ||
|
||
|
||
class MockBundleDir(type(Path())): | ||
"""Mocked RequestBundleDir.""" | ||
|
||
def __new__(cls, *args, **kwargs): | ||
"""Make a new MockBundleDir.""" | ||
self = super().__new__(cls, *args, **kwargs) | ||
self.source_root_dir = self.joinpath("app") | ||
self.rubygems_deps_dir = self / "deps" / "rubygems" | ||
return self | ||
|
||
|
||
@pytest.mark.parametrize("exists", [True, False]) | ||
def test_get_config_file(tmp_path, exists): | ||
bundle_dir = MockBundleDir(tmp_path) | ||
|
||
pkg_and_deps_info = { | ||
"dependencies": [ | ||
{ | ||
"name": "rspec-core.3", | ||
"path": bundle_dir.rubygems_deps_dir / "rspec-core.3" / "some-path", | ||
"kind": "GIT", | ||
} | ||
], | ||
} | ||
rubygems_hosted_repo = "https://admin:[email protected]" | ||
package_root = bundle_dir.source_root_dir / "pkg1" | ||
|
||
if exists: | ||
config_file = package_root / Path(".bundle/config") | ||
config_file.parent.mkdir(parents=True) | ||
config_file.touch() | ||
msg = ( | ||
f"Cachito wants to create a config file at location {config_file}, " | ||
f"but it already exists." | ||
) | ||
with pytest.raises(CachitoError, match=msg): | ||
rubygems._get_config_file_for_given_package( | ||
pkg_and_deps_info["dependencies"], bundle_dir, package_root, rubygems_hosted_repo | ||
) | ||
else: | ||
dep = rubygems._get_config_file_for_given_package( | ||
pkg_and_deps_info["dependencies"], bundle_dir, package_root, rubygems_hosted_repo | ||
) | ||
|
||
assert dep["path"] == "app/pkg1/.bundle/config" | ||
assert dep["type"] == "base64" | ||
contents = base64.b64decode(dep["content"]).decode() | ||
assert f'BUNDLE_MIRROR__ALL: "{rubygems_hosted_repo}"' in contents | ||
git_dep = 'BUNDLE_LOCAL__RSPEC___CORE__3: "../../deps/rubygems/rspec-core.3/some-path/app"' | ||
assert git_dep in contents |