Skip to content

Commit

Permalink
WIP: Add integration test to cover generated .repo files
Browse files Browse the repository at this point in the history
This test is different from the usual package managers tests, since it
uses a file that is RPM-specific and that also is a .toml file. This
means that the boilerplate needs to be customized for this specific
case.

For now, I wrote a very straightforward solution, but I am thinking if
there's a way to make it more generic and fit it into the utils module.

I also am checking if testing for the contents of repomd.xml is worth
the trouble, since it includes some timestamps that will need to be
worked around.

Signed-off-by: Bruno Pimentel <[email protected]>
  • Loading branch information
brunoapimentel committed May 2, 2024
1 parent 3d7b199 commit 9f24061
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/integration/test_data/test_repo_files/cachi2.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[releases]
baseurl=file:///tmp/test_repo_files-output/deps/rpm/x86_64/releases
gpgcheck=1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
65 changes: 64 additions & 1 deletion tests/integration/test_rpm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -54,7 +55,10 @@
utils.TestParameters(
repo="https://github.com/cachito-testing/cachi2-rpm",
ref="12afdef45a07560303496217de0222c5f7a49cac",
packages=[{"path": "this-project", "type": "rpm"}, {"path": "another-project", "type": "rpm"}],
packages=[
{"path": "this-project", "type": "rpm"},
{"path": "another-project", "type": "rpm"},
],
flags=["--dev-package-managers"],
check_output=True,
check_deps_checksums=False,
Expand Down Expand Up @@ -102,6 +106,65 @@ def test_rpm_packages(
)


def test_repo_files(
cachi2_image: utils.ContainerImage,
tmp_path: Path,
test_data_dir: Path,
request: pytest.FixtureRequest,
) -> None:
"""Test if the contents of the generated .repo file are correct."""
test_case = "test_repo_files"

source_folder = utils.clone_repository(
"https://github.com/cachito-testing/cachi2-rpm",
"3956e4d095920b3f06b861dbc778a520fdb89fd2",
f"{test_case}-source",
tmp_path,
)

output_folder = tmp_path.joinpath(f"{test_case}-output")

# prefetch dependencies
cmd = [
"fetch-deps",
"--source",
source_folder,
"--output",
output_folder,
"--dev-package-managers",
'{"type": "rpm"}',
]

(output, exit_code) = cachi2_image.run_cmd_on_image(cmd, tmp_path)
(f"Fetching deps ended with unexpected exitcode: {exit_code} != 0, " f"output-cmd: {output}")

Check notice

Code scanning / CodeQL

Statement has no effect Note test

This statement has no effect.

# inject files
cmd = [
"inject-files",
output_folder,
"--for-output-dir",
Path("/tmp").joinpath(f"{test_case}-output"),
]
(output, exit_code) = cachi2_image.run_cmd_on_image(cmd, tmp_path)
assert exit_code == 0, f"Injecting project files failed. output-cmd: {output}"

# check repofile contents
def read_file(path: Path) -> str:
with open(path) as file:
return file.read()

repo_file_content = read_file(output_folder.joinpath("deps/rpm/x86_64/repos.d/cachi2.repo"))
expected_repo_file_path = test_data_dir.joinpath(test_case, "cachi2.repo")

# update test data if needed
if os.getenv("CACHI2_GENERATE_TEST_DATA") == "true":
expected_repo_file_path.parent.mkdir(parents=True, exist_ok=True)
with open(expected_repo_file_path, "w") as file:
file.write(repo_file_content)

assert repo_file_content == read_file(expected_repo_file_path)


@pytest.mark.parametrize(
"test_params, check_cmd, expected_cmd_output",
[
Expand Down

0 comments on commit 9f24061

Please sign in to comment.