diff --git a/tests/integration/test_cargo.py b/tests/integration/test_cargo.py new file mode 100644 index 000000000..fd88de1fa --- /dev/null +++ b/tests/integration/test_cargo.py @@ -0,0 +1,121 @@ +import logging +from pathlib import Path + +import pytest + +from . import utils + +log = logging.getLogger(__name__) + + +@pytest.mark.parametrize( + "test_params", + [ + pytest.param( + utils.TestParameters( + branch="cargo/just-a-crate-dependency", + packages=({"path": ".", "type": "cargo"},), + flags=["--dev-package-managers"], + check_output=False, + check_deps_checksums=False, + check_vendor_checksums=False, + expected_exit_code=0, + expected_output="", + ), + id="just_a_crate_dependency", + ), + pytest.param( + utils.TestParameters( + branch="cargo/just-a-git-dependency", + packages=({"path": ".", "type": "cargo"},), + flags=["--dev-package-managers"], + check_output=False, + check_deps_checksums=False, + check_vendor_checksums=False, + expected_exit_code=0, + expected_output="", + ), + id="just_a_git_dependency", + ), + pytest.param( + utils.TestParameters( + branch="cargo/mixed-git-crate-dependency", + packages=({"path": ".", "type": "cargo"},), + flags=["--dev-package-managers"], + check_output=False, + check_deps_checksums=False, + check_vendor_checksums=False, + expected_exit_code=0, + expected_output="", + ), + id="mixed_git_crate_dependency", + ), + ], +) +def test_cargo_packages( + test_params: utils.TestParameters, + cachi2_image: utils.ContainerImage, + tmp_path: Path, + test_repo_dir: Path, + test_data_dir: Path, + request: pytest.FixtureRequest, +) -> None: + """Integration tests for bundler package manager.""" + test_case = request.node.callspec.id + + utils.fetch_deps_and_check_output( + tmp_path, test_case, test_params, test_repo_dir, test_data_dir, cachi2_image + ) + + +@pytest.mark.parametrize( + "test_params,check_cmd,expected_cmd_output", + [ + pytest.param( + utils.TestParameters( + branch="cargo/mixed-git-crate-dependency", + packages=({"path": ".", "type": "cargo"},), + flags=["--dev-package-managers"], + check_output=True, + check_deps_checksums=False, + check_vendor_checksums=False, + expected_exit_code=0, + expected_output="", + ), + [], # No additional commands are run to verify the build + [], + id="cargo_mixed_dep", + ), + ], +) +def test_e2e_cargo( + test_params: utils.TestParameters, + check_cmd: list[str], + expected_cmd_output: str, + cachi2_image: utils.ContainerImage, + tmp_path: Path, + test_repo_dir: Path, + test_data_dir: Path, + request: pytest.FixtureRequest, +) -> None: + """ + End to end test for bundler. + + :param test_params: Test case arguments + :param tmp_path: Temp directory for pytest + """ + test_case = request.node.callspec.id + + utils.fetch_deps_and_check_output( + tmp_path, test_case, test_params, test_repo_dir, test_data_dir, cachi2_image + ) + + utils.build_image_and_check_cmd( + tmp_path, + test_repo_dir, + test_data_dir, + test_case, + check_cmd, + expected_cmd_output, + cachi2_image, + ) diff --git a/tests/integration/test_data/cargo_mixed_dep/.build-config.yaml b/tests/integration/test_data/cargo_mixed_dep/.build-config.yaml new file mode 100644 index 000000000..95e770fdf --- /dev/null +++ b/tests/integration/test_data/cargo_mixed_dep/.build-config.yaml @@ -0,0 +1,13 @@ +environment_variables: [] +project_files: +- abspath: ${test_case_tmp_path}/.cargo/config.toml + template: |- + [source.crates-io] + replace-with = "vendored-sources" + + [source."git+https://github.com/uuid-rs/uuid"] + git = "https://github.com/uuid-rs/uuid" + replace-with = "vendored-sources" + + [source.vendored-sources] + directory = "${output_dir}/deps/cargo" diff --git a/tests/integration/test_data/cargo_mixed_dep/bom.json b/tests/integration/test_data/cargo_mixed_dep/bom.json new file mode 100644 index 000000000..17232afaf --- /dev/null +++ b/tests/integration/test_data/cargo_mixed_dep/bom.json @@ -0,0 +1,39 @@ +{ + "bomFormat": "CycloneDX", + "components": [ + { + "name": "data-encoding", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:cargo/data-encoding@2.7.0", + "type": "library", + "version": "2.7.0" + }, + { + "name": "uuid", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:cargo/uuid@1.12.1", + "type": "library", + "version": "1.12.1" + } + ], + "metadata": { + "tools": [ + { + "name": "cachi2", + "vendor": "red hat" + } + ] + }, + "specVersion": "1.4", + "version": 1 +} diff --git a/tests/integration/test_data/cargo_mixed_dep/container/Containerfile b/tests/integration/test_data/cargo_mixed_dep/container/Containerfile new file mode 100644 index 000000000..85b5a3b06 --- /dev/null +++ b/tests/integration/test_data/cargo_mixed_dep/container/Containerfile @@ -0,0 +1,12 @@ +FROM docker.io/rust:1.67 + +# Test disabled network access +RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi + +# This should be a COPY, but the source code and Containerfile are in different directories +# RUN ls /tmp && echo "----" && cat /tmp/cachi2.env && cp -r /tmp/cachi2-output/deps/cargo /src + +WORKDIR /src +RUN . /tmp/cachi2.env && \ + sed -i 's/version = 4/version = 3/' Cargo.lock && \ + cargo build --offline