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

E2E test for RPM prefetching #519

Merged
merged 2 commits into from
Apr 15, 2024
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
2 changes: 2 additions & 0 deletions tests/integration/test_data/rpm_e2e_test/.build-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
environment_variables: []
project_files: []
171 changes: 171 additions & 0 deletions tests/integration/test_data/rpm_e2e_test/bom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"bomFormat": "CycloneDX",
"components": [
{
"name": "gpm-libs",
"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/gpm-libs-1.20.7-44.fc39.x86_64.rpm",
"type": "library",
"version": "1.20.7"
},
{
"name": "gpm",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=i686&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/source/tree/Packages/g/gpm-1.20.7-44.fc39.src.rpm",
"type": "library",
"version": "1.20.7"
},
{
"name": "libsodium",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=i686&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/source/tree/Packages/l/libsodium-1.0.18-14.fc39.src.rpm",
"type": "library",
"version": "1.0.18"
},
{
"name": "libsodium",
"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/l/libsodium-1.0.18-14.fc39.x86_64.rpm",
"type": "library",
"version": "1.0.18"
},
{
"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/39/Everything/x86_64/os/Packages/v/vim-common-9.0.1927-1.fc39.x86_64.rpm",
"type": "library",
"version": "9.0.1927"
},
{
"name": "vim-data",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=noarch&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/v/vim-data-9.0.1927-1.fc39.noarch.rpm",
"type": "library",
"version": "9.0.1927"
},
{
"name": "vim-enhanced",
"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/39/Everything/x86_64/os/Packages/v/vim-enhanced-9.0.1927-1.fc39.x86_64.rpm",
"type": "library",
"version": "9.0.1927"
},
{
"name": "vim-filesystem",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=noarch&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/v/vim-filesystem-9.0.1927-1.fc39.noarch.rpm",
"type": "library",
"version": "9.0.1927"
},
{
"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/39/Everything/x86_64/os/Packages/v/vim-minimal-9.0.1927-1.fc39.x86_64.rpm",
"type": "library",
"version": "9.0.1927"
},
{
"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/39/Everything/source/tree/Packages/v/vim-9.0.1927-1.fc39.src.rpm",
"type": "library",
"version": "9.0.1927"
},
{
"name": "which",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:rpm/fedora%20project/[email protected]?arch=i686&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/source/tree/Packages/w/which-2.21-40.fc39.src.rpm",
"type": "library",
"version": "2.21"
},
{
"name": "which",
"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/w/which-2.21-40.fc39.x86_64.rpm",
"type": "library",
"version": "2.21"
},
{
"name": "xxd",
"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/39/Everything/x86_64/os/Packages/x/xxd-9.0.1927-1.fc39.x86_64.rpm",
"type": "library",
"version": "9.0.1927"
}
],
"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,6 @@
FROM registry.fedoraproject.org/fedora:39

RUN dnf -y install \
vim

CMD ["vim", "--help"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"rpm/x86_64/releases/gpm-1.20.7-44.fc39.src.rpm": "sha256:2eb2412dde91b1130433c90ad53b889cb1e0fb0df324e015f29e76d7235ac438",
"rpm/x86_64/releases/gpm-libs-1.20.7-44.fc39.x86_64.rpm": "sha256:f5c8f20f0f9468da8cdf140d7df30ed117a43b73eee816888e2624b0fcd048ca",
"rpm/x86_64/releases/libsodium-1.0.18-14.fc39.src.rpm": "sha256:d20e5f6e358aa0c07260872ffb00d502f77778ae7496a836da0a65a6ce1cd709",
"rpm/x86_64/releases/libsodium-1.0.18-14.fc39.x86_64.rpm": "sha256:e38200a7b1012935dc83e8039c71c0fd2f84a4463ca086cb42f60f488cdad8e7",
"rpm/x86_64/releases/vim-9.0.1927-1.fc39.src.rpm": "sha256:dae76267f265093d0e1b178c05af197bc21b994a264c9c4e7701cce095b62f03",
"rpm/x86_64/releases/vim-common-9.0.1927-1.fc39.x86_64.rpm": "sha256:4cb8015a858439f519d5d2aa82fd853f3d1dd7f927a33d25d9598e54ee6201bc",
"rpm/x86_64/releases/vim-data-9.0.1927-1.fc39.noarch.rpm": "sha256:35d7b9542e46eca30d951960effe9a8e738543a839f0dbb3cf723da0958c355b",
"rpm/x86_64/releases/vim-enhanced-9.0.1927-1.fc39.x86_64.rpm": "sha256:615d46a08fbbd0eca6a6e8d2d23a6b5847db11c886e0dc979ffebab66236532d",
"rpm/x86_64/releases/vim-filesystem-9.0.1927-1.fc39.noarch.rpm": "sha256:f645ed8cda2fa07ba991320a684d9b71de75ff25220468b08fb36f6a5a231178",
"rpm/x86_64/releases/vim-minimal-9.0.1927-1.fc39.x86_64.rpm": "sha256:37a216f1af9f2eb961a9fa6674861146d11ca56fc9c576fa17a8cb7d806aa0af",
"rpm/x86_64/releases/which-2.21-40.fc39.src.rpm": "sha256:791428d30c136a2ff8e781b9c32cbd3d506699f1369ae2a589c02fceb72d4533",
"rpm/x86_64/releases/which-2.21-40.fc39.x86_64.rpm": "sha256:ec1d8a1c0d88883a03e96ba88a6278899bd559fb37833cb2383ffdd6a38c22ae",
"rpm/x86_64/releases/xxd-9.0.1927-1.fc39.x86_64.rpm": "sha256:e770b0a0e5e51225a76069d2210551a90f3140913f90f33759d002055179ecc7"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
67 changes: 67 additions & 0 deletions tests/integration/test_rpm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from pathlib import Path
from typing import List

import pytest

from . import utils


@pytest.mark.parametrize(
"test_params, check_cmd, expected_cmd_output",
[
# Test case that checks fetching RPM files, generating repos and repofiles, building an
# image that requires the RPM files to be installed and running the image to check if the
# RPMs were properly installed
pytest.param(
utils.TestParameters(
repo="https://github.com/cachito-testing/cachi2-rpm.git",
ref="eef99f074a9abd288b421697d7e00cec77590d0d",
packages=(
{
"type": "rpm",
},
),
flags=["--dev-package-managers"],
expected_exit_code=0,
expected_output="All dependencies fetched successfully",
),
["vim", "--version"],
["VIM - Vi IMproved 9.0"],
id="rpm_e2e_test",
),
],
)
def test_e2e_rpm(
test_params: utils.TestParameters,
check_cmd: List[str],
expected_cmd_output: str,
cachi2_image: utils.ContainerImage,
tmp_path: Path,
test_data_dir: Path,
request: pytest.FixtureRequest,
) -> None:
"""
End to end test for rpms.

:param test_params: Test case arguments
:param tmp_path: Temp directory for pytest
"""
test_case = request.node.callspec.id

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

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

utils.build_image_and_check_cmd(
tmp_path,
output_folder,
test_data_dir,
test_case,
check_cmd,
expected_cmd_output,
cachi2_image,
)
11 changes: 11 additions & 0 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ def build_image_for_test_case(tmp_path: Path, containerfile: str, test_case: str
"--network",
"none",
]

# this should be extended to support more archs when we have the means of testing it in our CI
rpm_repos_path = f"{tmp_path}/{test_case}-output/deps/rpm/x86_64/repos.d"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add a comment note here that we should extend this to more architectures in the future when we have means of testing it?
Up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Path(rpm_repos_path).exists():
cmd.extend(
[
"-v",
f"{rpm_repos_path}:/etc/yum.repos.d:Z",
]
)

return _build_image(cmd, tag=f"localhost/{test_case}")


Expand Down