Skip to content

Commit

Permalink
cargo: Adding integration tests
Browse files Browse the repository at this point in the history
This commit introduces integration tests for cargo
and an e2e test.

Signed-off-by: Alexey Ovchinnikov <[email protected]>
  • Loading branch information
a-ovchinnikov committed Feb 12, 2025
1 parent a8315df commit d0f903e
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 0 deletions.
116 changes: 116 additions & 0 deletions tests/integration/test_cargo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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 cargo."""
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,
)
13 changes: 13 additions & 0 deletions tests/integration/test_data/cargo_mixed_dep/.build-config.yaml
Original file line number Diff line number Diff line change
@@ -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"
51 changes: 51 additions & 0 deletions tests/integration/test_data/cargo_mixed_dep/bom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"bomFormat": "CycloneDX",
"components": [
{
"name": "data-encoding",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:cargo/[email protected]?source=registry%2Bhttps://github.com/rust-lang/crates.io-index",
"type": "library",
"version": "2.7.0"
},
{
"name": "integration-tests",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:cargo/[email protected]?vcs_url=git%2Bhttps://github.com/cachito-testing/integration-tests.git%4009c8cf923df4bb74ceac204e8d8be5732d90e740",
"type": "library",
"version": "0.1.0"
},
{
"name": "uuid",
"properties": [
{
"name": "cachi2:found_by",
"value": "cachi2"
}
],
"purl": "pkg:cargo/[email protected]?source=git%2Bhttps://github.com/uuid-rs/uuid%2370831d21b373a06149885e8aec18c9084ac918c3",
"type": "library",
"version": "1.12.1"
}
],
"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,7 @@
FROM docker.io/rust:1-alpine

# Test disabled network access
RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi

WORKDIR /src
RUN . /tmp/cachi2.env && cargo build --offline

0 comments on commit d0f903e

Please sign in to comment.