-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces integration tests for cargo and an e2e test. Signed-off-by: Alexey Ovchinnikov <[email protected]>
- Loading branch information
1 parent
b34575a
commit 1063b9f
Showing
4 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
tests/integration/test_data/cargo_mixed_dep/.build-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"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": "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 | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/integration/test_data/cargo_mixed_dep/container/Containerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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 |