Skip to content
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

RPM PoC: Integration tests #532

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
environment_variables: []
project_files: []
79 changes: 79 additions & 0 deletions tests/integration/test_data/rpm_multiple_archs/bom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"bomFormat": "CycloneDX",
"components": [
{
"name": "vim-common",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=x86_64&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/40/Everything/x86_64/os/Packages/v/vim-common-9.1.158-1.fc40.x86_64.rpm",
"type": "library",
"version": "9.1.158"
},
{
"name": "vim-data",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
},
{
"name": "cachi2:missing_hash:in_file",
"value": "rpms.lock.yaml"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=noarch&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/40/Everything/x86_64/os/Packages/v/vim-data-9.1.158-1.fc40.noarch.rpm",
"type": "library",
"version": "9.1.158"
},
{
"name": "vim-minimal",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=aarch64&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/40/Everything/aarch64/os/Packages/v/vim-minimal-9.1.158-1.fc40.aarch64.rpm",
"type": "library",
"version": "9.1.158"
},
{
"name": "vim-minimal",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=x86_64&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/40/Everything/x86_64/os/Packages/v/vim-minimal-9.1.158-1.fc40.x86_64.rpm",
"type": "library",
"version": "9.1.158"
},
{
"name": "vim",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=i686&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/40/Everything/source/tree/Packages/v/vim-9.1.158-1.fc40.src.rpm",
"type": "library",
"version": "9.1.158"
}
],
"metadata": {
"tools": [
{
"name": "cachi2",
"vendor": "red hat"
}
]
},
"specVersion": "1.4",
"version": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
environment_variables: []
project_files: []
67 changes: 67 additions & 0 deletions tests/integration/test_data/rpm_multiple_packages/bom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"bomFormat": "CycloneDX",
"components": [
{
"name": "glibc-common",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
},
{
"name": "cachi2:missing_hash:in_file",
"value": "another-project/rpms.lock.yaml"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=x86_64&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/40/Everything/x86_64/os/Packages/g/glibc-common-2.39-6.fc40.x86_64.rpm",
"type": "library",
"version": "2.39"
},
{
"name": "glibc-minimal-langpack",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=x86_64&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/g/glibc-minimal-langpack-2.38-7.fc39.x86_64.rpm",
"type": "library",
"version": "2.38"
},
{
"name": "glibc-minimal-langpack",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=x86_64&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/40/Everything/x86_64/os/Packages/g/glibc-minimal-langpack-2.39-6.fc40.x86_64.rpm",
"type": "library",
"version": "2.39"
},
{
"name": "gzip",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=x86_64&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/40/Everything/x86_64/os/Packages/g/gzip-1.13-1.fc40.x86_64.rpm",
"type": "library",
"version": "1.13"
}
],
"metadata": {
"tools": [
{
"name": "cachi2",
"vendor": "red hat"
}
]
},
"specVersion": "1.4",
"version": 1
}
10 changes: 10 additions & 0 deletions tests/integration/test_data/rpm_test_repo_file/cachi2.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[another-repoid]
baseurl=file:///tmp/rpm_test_repo_file-output/deps/rpm/x86_64/another-repoid
gpgcheck=1
[cachi2-aaa000]
baseurl=file:///tmp/rpm_test_repo_file-output/deps/rpm/x86_64/cachi2-aaa000
gpgcheck=1
name=Generated repository containing all packages unaffiliated with any official repository
[releases]
eskultety marked this conversation as resolved.
Show resolved Hide resolved
baseurl=file:///tmp/rpm_test_repo_file-output/deps/rpm/x86_64/releases
gpgcheck=1
102 changes: 102 additions & 0 deletions tests/integration/test_rpm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import re
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -50,6 +52,35 @@
),
id="rpm_unexpected_size",
),
pytest.param(
utils.TestParameters(
repo="https://github.com/cachito-testing/cachi2-rpm",
ref="12afdef45a07560303496217de0222c5f7a49cac",
packages=(
{"path": "this-project", "type": "rpm"},
{"path": "another-project", "type": "rpm"},
),
flags=["--dev-package-managers"],
check_output=True,
check_deps_checksums=False,
check_vendor_checksums=False,
expected_exit_code=0,
),
id="rpm_multiple_packages",
),
pytest.param(
utils.TestParameters(
repo="https://github.com/cachito-testing/cachi2-rpm",
ref="22cb12ee0ba4f98d8a751e552c3caee8de5b0237",
packages=({"path": ".", "type": "rpm"},),
flags=["--dev-package-managers"],
check_output=True,
check_deps_checksums=False,
check_vendor_checksums=False,
expected_exit_code=0,
),
id="rpm_multiple_archs",
),
],
)
def test_rpm_packages(
Expand All @@ -76,6 +107,77 @@ def test_rpm_packages(
)


@pytest.mark.parametrize(
"test_params",
[
pytest.param(
utils.TestParameters(
repo="https://github.com/cachito-testing/cachi2-rpm",
ref="ce7fed744fc8fc2fd5d8981027e519ecd50b8805",
packages=({"path": ".", "type": "rpm"},),
flags=["--dev-package-managers"],
check_output=False,
check_deps_checksums=False,
check_vendor_checksums=False,
expected_exit_code=0,
),
id="rpm_test_repo_file",
),
],
)
def test_repo_files(
test_params: utils.TestParameters,
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 = request.node.callspec.id
output_folder = tmp_path.joinpath(f"{test_case}-output")

source_folder = utils.clone_repository(
test_params.repo, test_params.ref, f"{test_case}-source", tmp_path
)

utils.fetch_deps_and_check_output(
tmp_path, test_case, test_params, source_folder, test_data_dir, cachi2_image
)

# call inject-files to create the .repo file
cmd = [
"inject-files",
output_folder,
"--for-output-dir",
Path("/tmp", 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}"

# load .repo file contents
def read_and_normalize_repofile(path: Path) -> str:
with open(path) as file:
# whenever an RPM lacks a repoid in the lockfile, Cachi2 will resort to a randomly
# generated internal repoid, which needs to be replaced by a constant string so it can
# be tested consistently.
return re.sub(r"cachi2-[a-f0-9]{6}", "cachi2-aaa000", file.read())

repo_file_content = read_and_normalize_repofile(
output_folder.joinpath("deps/rpm/x86_64/repos.d/cachi2.repo")
)

# update test data if needed
expected_repo_file_path = test_data_dir.joinpath(test_case, "cachi2.repo")

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)

# check if .repo file content matches the expected test data
assert repo_file_content == read_and_normalize_repofile(expected_repo_file_path)


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