From f281d5d0738905e607c15cbde8216736f2600d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=A0oltis?= Date: Mon, 20 Jan 2025 14:52:13 +0100 Subject: [PATCH] integration tests: Use single test repository MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modify each test module to use a branch (not a git commit) as a reference inside the new integration test repository that contains all integration (e2e) tests for cachi2. Update and improve a few functions inside utils.py Drop unnecessary lines from each Containerfile that were blindly duplicated along with the comments. Plus, they were tightly coupled with our code printing output of specific files inside of directories coming from pytest. closes containerbuildsystem#676 Signed-off-by: Michal Ĺ oltis --- tests/integration/test_bundler.py | 28 ++-- .../container/Containerfile | 16 +- .../container/Containerfile | 16 +- .../generic_e2e/container/Containerfile | 4 +- .../generic_maven_e2e/container/Containerfile | 2 +- .../container/Containerfile | 13 +- .../container/Containerfile | 16 +- .../container/Containerfile | 13 +- .../container/Containerfile | 13 +- .../container/Containerfile | 8 +- .../container/Containerfile | 19 +-- .../container/Containerfile | 19 +-- .../container/Containerfile | 19 +-- .../container/Containerfile | 20 +-- .../container/Containerfile | 17 +-- .../container/Containerfile | 17 +-- .../pip_e2e_test/container/Containerfile | 22 +-- .../container/Containerfile | 19 +-- .../test_data/rpm_test_repo_file/cachi2.repo | 6 +- .../container/Containerfile | 22 +-- .../container/Containerfile | 23 +-- .../yarn_e2e_test/container/Containerfile | 20 +-- .../container/Containerfile | 22 +-- tests/integration/test_generic.py | 29 ++-- tests/integration/test_gomod.py | 48 +++--- tests/integration/test_npm.py | 32 ++-- tests/integration/test_pip.py | 48 +++--- tests/integration/test_rpm.py | 49 +++--- tests/integration/test_yarn.py | 36 ++--- tests/integration/test_yarn_classic.py | 34 ++--- tests/integration/utils.py | 144 +++++++++++------- 31 files changed, 283 insertions(+), 511 deletions(-) diff --git a/tests/integration/test_bundler.py b/tests/integration/test_bundler.py index 416295b4d..5ae0301e3 100644 --- a/tests/integration/test_bundler.py +++ b/tests/integration/test_bundler.py @@ -14,7 +14,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-bundler.git", - ref="malformed_ruby_missing_gemfile", + ref="bundler/missing-gemfile", packages=({"path": ".", "type": "bundler"},), check_output=False, check_deps_checksums=False, @@ -27,7 +27,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-bundler.git", - ref="malformed_ruby_missing_gemfile_lock", + ref="bundler/missing-lockfile", packages=({"path": ".", "type": "bundler"},), check_output=False, check_deps_checksums=False, @@ -40,7 +40,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-bundler.git", - ref="malformed_ruby_missing_git_revision", + ref="bundler/missing-git-revision", packages=({"path": ".", "type": "bundler"},), check_output=False, check_deps_checksums=False, @@ -56,18 +56,15 @@ def test_bundler_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 - 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 + tmp_path, test_case, test_params, test_repo_dir, test_data_dir, cachi2_image ) @@ -77,7 +74,7 @@ def test_bundler_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-bundler.git", - ref="well_formed_ruby_all_features", + ref="bundler/e2e", packages=({"path": ".", "type": "bundler", "allow_binary": "true"},), check_output=True, check_deps_checksums=False, @@ -92,7 +89,7 @@ def test_bundler_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-bundler.git", - ref="well_formed_ruby_without_gemspec", + ref="bundler/e2e-missing-gemspec", packages=({"path": ".", "type": "bundler", "allow_binary": "true"},), check_output=True, check_deps_checksums=False, @@ -112,6 +109,7 @@ def test_e2e_bundler( expected_cmd_output: str, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -123,17 +121,13 @@ def test_e2e_bundler( """ 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.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, - output_folder, + test_repo_dir, test_data_dir, test_case, check_cmd, diff --git a/tests/integration/test_data/bundler_everything_present/container/Containerfile b/tests/integration/test_data/bundler_everything_present/container/Containerfile index d8b657fa9..40faa1076 100644 --- a/tests/integration/test_data/bundler_everything_present/container/Containerfile +++ b/tests/integration/test_data/bundler_everything_present/container/Containerfile @@ -1,19 +1,5 @@ FROM docker.io/ruby:3.3 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check bundler deps -RUN ls /tmp/bundler_everything_present-output/deps/bundler - -# Check content of source repository folder -RUN ls /tmp/bundler_everything_present-source/ - -# This should be a COPY, but the source code and Containerfile are in different directories -RUN cp -r /tmp/bundler_everything_present-source /src - WORKDIR /src + RUN . /tmp/cachi2.env && bundle install diff --git a/tests/integration/test_data/bundler_everything_present_except_gemspec/container/Containerfile b/tests/integration/test_data/bundler_everything_present_except_gemspec/container/Containerfile index bf95b6e68..40faa1076 100644 --- a/tests/integration/test_data/bundler_everything_present_except_gemspec/container/Containerfile +++ b/tests/integration/test_data/bundler_everything_present_except_gemspec/container/Containerfile @@ -1,19 +1,5 @@ FROM docker.io/ruby:3.3 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check bundler deps -RUN ls /tmp/bundler_everything_present_except_gemspec-output/deps/bundler - -# Check content of source repository folder -RUN ls /tmp/bundler_everything_present_except_gemspec-source/ - -# This should be a COPY, but the source code and Containerfile are in different directories -RUN cp -r /tmp/bundler_everything_present_except_gemspec-source /src - WORKDIR /src + RUN . /tmp/cachi2.env && bundle install diff --git a/tests/integration/test_data/generic_e2e/container/Containerfile b/tests/integration/test_data/generic_e2e/container/Containerfile index b0a96f8c6..315afb86c 100644 --- a/tests/integration/test_data/generic_e2e/container/Containerfile +++ b/tests/integration/test_data/generic_e2e/container/Containerfile @@ -1,5 +1,5 @@ FROM registry.fedoraproject.org/fedora:40 -RUN cp -r /tmp/generic_e2e-output/deps/generic/ /deps +RUN cp -r /tmp/cachi2-output/deps/generic/ /deps -CMD ["ls", "-al", "/deps"] \ No newline at end of file +CMD ["ls", "-al", "/deps"] diff --git a/tests/integration/test_data/generic_maven_e2e/container/Containerfile b/tests/integration/test_data/generic_maven_e2e/container/Containerfile index e047a371a..aa2b278c9 100644 --- a/tests/integration/test_data/generic_maven_e2e/container/Containerfile +++ b/tests/integration/test_data/generic_maven_e2e/container/Containerfile @@ -1,5 +1,5 @@ FROM docker.io/ibmjava:11-jdk -RUN cp -r /tmp/generic_maven_e2e-output/deps/generic/ /deps +RUN cp -r /tmp/cachi2-output/deps/generic/ /deps CMD ["java", "-cp", "/deps/ant.jar:/deps/ant-launcher.jar", "org.apache.tools.ant.Main", "-version"] diff --git a/tests/integration/test_data/gomod_1.18_e2e_test/container/Containerfile b/tests/integration/test_data/gomod_1.18_e2e_test/container/Containerfile index af79ba5f4..afc29f666 100644 --- a/tests/integration/test_data/gomod_1.18_e2e_test/container/Containerfile +++ b/tests/integration/test_data/gomod_1.18_e2e_test/container/Containerfile @@ -1,15 +1,6 @@ -FROM docker.io/golang:1.18.1 AS build +FROM docker.io/golang:1.18.1 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check content of source repository folder -RUN ls /tmp/gomod_1.18_e2e_test-source/ - -WORKDIR /tmp/gomod_1.18_e2e_test-source +WORKDIR /src RUN . /tmp/cachi2.env && go build -o /usr/bin/retrodep CMD retrodep --help diff --git a/tests/integration/test_data/gomod_1.20_e2e_dirty_go.mod/container/Containerfile b/tests/integration/test_data/gomod_1.20_e2e_dirty_go.mod/container/Containerfile index 2c90857cc..93599aac2 100644 --- a/tests/integration/test_data/gomod_1.20_e2e_dirty_go.mod/container/Containerfile +++ b/tests/integration/test_data/gomod_1.20_e2e_dirty_go.mod/container/Containerfile @@ -1,18 +1,6 @@ -FROM docker.io/golang:1.20.0 AS build +FROM docker.io/golang:1.20.0 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check content of source repository folder -RUN ls /tmp/gomod_1.20_e2e_dirty_go.mod-source/ - -WORKDIR /tmp/gomod_1.20_e2e_dirty_go.mod-source/twenty - -# Check that repository is clean (go.mod should not be updated) -RUN if [ -n "$(git status --porcelain)" ]; then echo "Repo is dirty. Check go.mod"; exit 1; fi +WORKDIR /src/twenty RUN . /tmp/cachi2.env && go build -o /usr/bin/twenty diff --git a/tests/integration/test_data/gomod_1.21_e2e_test/container/Containerfile b/tests/integration/test_data/gomod_1.21_e2e_test/container/Containerfile index f25d80f4b..1782af935 100644 --- a/tests/integration/test_data/gomod_1.21_e2e_test/container/Containerfile +++ b/tests/integration/test_data/gomod_1.21_e2e_test/container/Containerfile @@ -1,15 +1,6 @@ -FROM docker.io/golang:1.21.5 AS build +FROM docker.io/golang:1.21.5 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check content of source repository folder -RUN ls /tmp/gomod_1.21_e2e_test-source/ - -WORKDIR /tmp/gomod_1.21_e2e_test-source +WORKDIR /src RUN . /tmp/cachi2.env && go build -o /usr/bin/retrodep CMD retrodep --help diff --git a/tests/integration/test_data/gomod_1.22_e2e_workspace_vendoring/container/Containerfile b/tests/integration/test_data/gomod_1.22_e2e_workspace_vendoring/container/Containerfile index d993551d2..0a417b9ff 100644 --- a/tests/integration/test_data/gomod_1.22_e2e_workspace_vendoring/container/Containerfile +++ b/tests/integration/test_data/gomod_1.22_e2e_workspace_vendoring/container/Containerfile @@ -1,15 +1,6 @@ -FROM docker.io/golang:1.22.0 AS build +FROM docker.io/golang:1.22.0 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check content of source repository folder -RUN ls /tmp/gomod_1.22_e2e_workspace_vendoring-source - -WORKDIR /tmp/gomod_1.22_e2e_workspace_vendoring-source/hi/hiii +WORKDIR /src/hi/hiii RUN . /tmp/cachi2.env && go build -o /usr/bin/hiii CMD hiii diff --git a/tests/integration/test_data/gomod_e2e_multiple_modules/container/Containerfile b/tests/integration/test_data/gomod_e2e_multiple_modules/container/Containerfile index f115b1c7e..2362a661f 100644 --- a/tests/integration/test_data/gomod_e2e_multiple_modules/container/Containerfile +++ b/tests/integration/test_data/gomod_e2e_multiple_modules/container/Containerfile @@ -1,12 +1,6 @@ FROM docker.io/golang:1.18.1 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -WORKDIR /tmp/gomod_e2e_multiple_modules-source +WORKDIR /src RUN . /tmp/cachi2.env && \ cd spam-module && go build -o /usr/bin/spam-module && \ cd ../eggs-module && go build -o /usr/bin/eggs-module diff --git a/tests/integration/test_data/npm_lockfile3_aliased_deps/container/Containerfile b/tests/integration/test_data/npm_lockfile3_aliased_deps/container/Containerfile index 56f477c75..8516a392f 100644 --- a/tests/integration/test_data/npm_lockfile3_aliased_deps/container/Containerfile +++ b/tests/integration/test_data/npm_lockfile3_aliased_deps/container/Containerfile @@ -1,20 +1,5 @@ FROM docker.io/node:18 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi +WORKDIR /src -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check npm deps -RUN ls /tmp/npm_lockfile3_aliased_deps-output/deps/npm - -# Check content of source repository folder -RUN ls /tmp/npm_lockfile3_aliased_deps-source/ - -WORKDIR /tmp/npm_lockfile3_aliased_deps-source - -# Install packages and list them -RUN . /tmp/cachi2.env && \ - npm install && \ - npm ll --parseable > /opt/npm-ls-output.txt +RUN . /tmp/cachi2.env && npm install diff --git a/tests/integration/test_data/npm_lockfile3_dev_optional_peer_deps/container/Containerfile b/tests/integration/test_data/npm_lockfile3_dev_optional_peer_deps/container/Containerfile index a30a2a901..8516a392f 100644 --- a/tests/integration/test_data/npm_lockfile3_dev_optional_peer_deps/container/Containerfile +++ b/tests/integration/test_data/npm_lockfile3_dev_optional_peer_deps/container/Containerfile @@ -1,20 +1,5 @@ FROM docker.io/node:18 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi +WORKDIR /src -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check npm deps -RUN ls /tmp/npm_lockfile3_dev_optional_peer_deps-output/deps/npm - -# Check content of source repository folder -RUN ls /tmp/npm_lockfile3_dev_optional_peer_deps-source/ - -WORKDIR /tmp/npm_lockfile3_dev_optional_peer_deps-source - -# Install packages and list them -RUN . /tmp/cachi2.env && \ - npm install && \ - npm ls -a --parseable > /opt/npm-ls-output.txt +RUN . /tmp/cachi2.env && npm install diff --git a/tests/integration/test_data/npm_lockfile3_multiple_dep_versions/container/Containerfile b/tests/integration/test_data/npm_lockfile3_multiple_dep_versions/container/Containerfile index 8733c0fff..8516a392f 100644 --- a/tests/integration/test_data/npm_lockfile3_multiple_dep_versions/container/Containerfile +++ b/tests/integration/test_data/npm_lockfile3_multiple_dep_versions/container/Containerfile @@ -1,20 +1,5 @@ FROM docker.io/node:18 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi +WORKDIR /src -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check npm deps -RUN ls /tmp/npm_lockfile3_multiple_dep_versions-output/deps/npm - -# Check content of source repository folder -RUN ls /tmp/npm_lockfile3_multiple_dep_versions-source/ - -WORKDIR /tmp/npm_lockfile3_multiple_dep_versions-source - -# Install packages and list them -RUN . /tmp/cachi2.env && \ - npm install && \ - npm ll --parseable > /opt/npm-ls-output.txt +RUN . /tmp/cachi2.env && npm install diff --git a/tests/integration/test_data/npm_multiple_packages_lockfile3/container/Containerfile b/tests/integration/test_data/npm_multiple_packages_lockfile3/container/Containerfile index 0b44f91eb..8d61ae4a7 100644 --- a/tests/integration/test_data/npm_multiple_packages_lockfile3/container/Containerfile +++ b/tests/integration/test_data/npm_multiple_packages_lockfile3/container/Containerfile @@ -1,19 +1,7 @@ FROM docker.io/node:17 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi +WORKDIR /src/first_pkg +RUN . /tmp/cachi2.env && npm install && npm ls -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check npm deps -RUN ls /tmp/npm_multiple_packages_lockfile3-output/deps/npm - -# Check content of source repository folder -RUN ls /tmp/npm_multiple_packages_lockfile3-source/ - -WORKDIR /tmp/npm_multiple_packages_lockfile3-source - -# Install packages -RUN cd ./first_pkg && . /tmp/cachi2.env && npm i && npm ls -RUN cd ./second_pkg && . /tmp/cachi2.env && npm i && npm ls +WORKDIR /src/second_pkg +RUN . /tmp/cachi2.env && npm install && npm ls diff --git a/tests/integration/test_data/npm_smoketest_lockfile2/container/Containerfile b/tests/integration/test_data/npm_smoketest_lockfile2/container/Containerfile index e99eacc79..8f00b0f47 100644 --- a/tests/integration/test_data/npm_smoketest_lockfile2/container/Containerfile +++ b/tests/integration/test_data/npm_smoketest_lockfile2/container/Containerfile @@ -1,18 +1,5 @@ FROM docker.io/node:17 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi +WORKDIR /src -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check pip deps -RUN ls /tmp/npm_smoketest_lockfile2-output/deps/npm - -# Check content of source repository folder -RUN ls /tmp/npm_smoketest_lockfile2-source/ - -WORKDIR /tmp/npm_smoketest_lockfile2-source - -# Install packages -RUN . /tmp/cachi2.env && npm i && npm ls +RUN . /tmp/cachi2.env && npm install && npm ls diff --git a/tests/integration/test_data/npm_smoketest_lockfile3/container/Containerfile b/tests/integration/test_data/npm_smoketest_lockfile3/container/Containerfile index 885d8df8d..394f6edc4 100644 --- a/tests/integration/test_data/npm_smoketest_lockfile3/container/Containerfile +++ b/tests/integration/test_data/npm_smoketest_lockfile3/container/Containerfile @@ -1,18 +1,5 @@ FROM docker.io/node:18 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi +WORKDIR /src -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check pip deps -RUN ls /tmp/npm_smoketest_lockfile3-output/deps/npm - -# Check content of source repository folder -RUN ls /tmp/npm_smoketest_lockfile3-source/ - -WORKDIR /tmp/npm_smoketest_lockfile3-source - -# Install packages -RUN . /tmp/cachi2.env && npm i && npm ls +RUN . /tmp/cachi2.env && npm install && npm ls diff --git a/tests/integration/test_data/pip_e2e_test/container/Containerfile b/tests/integration/test_data/pip_e2e_test/container/Containerfile index 4c138cec1..486a5cb17 100644 --- a/tests/integration/test_data/pip_e2e_test/container/Containerfile +++ b/tests/integration/test_data/pip_e2e_test/container/Containerfile @@ -1,19 +1,9 @@ FROM docker.io/python:3.8 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check pip deps -RUN ls /tmp/pip_e2e_test-output/deps/pip - -# Check content of source repository folder -RUN ls /tmp/pip_e2e_test-source/ - -WORKDIR /tmp/pip_e2e_test-source - -# Install packages +WORKDIR /src RUN . /tmp/cachi2.env && python3 -m pip install -r requirements.txt -RUN cp /tmp/pip_e2e_test-source/src/test_package_cachi2/main.py /opt/test_package_cachi2 + +# during the build, the source code is only mounted, not copied +# some integration tests use CMD that requires the source code to be present +RUN cp -r /src /app +WORKDIR /app diff --git a/tests/integration/test_data/pip_e2e_test_wheels/container/Containerfile b/tests/integration/test_data/pip_e2e_test_wheels/container/Containerfile index ed48e847c..e281744c1 100644 --- a/tests/integration/test_data/pip_e2e_test_wheels/container/Containerfile +++ b/tests/integration/test_data/pip_e2e_test_wheels/container/Containerfile @@ -1,16 +1,9 @@ FROM docker.io/python:3.12 -# check network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# check source code -RUN cat /tmp/cachi2.env -RUN ls /tmp/pip_e2e_test_wheels-output/deps/pip -RUN ls /tmp/pip_e2e_test_wheels-source - -WORKDIR /tmp/pip_e2e_test_wheels-source - -# install packages -RUN . /tmp/cachi2.env && pip install -r requirements.txt -RUN cp /tmp/pip_e2e_test_wheels-source/package/main.py /opt/package +WORKDIR /src +RUN . /tmp/cachi2.env && python3 -m pip install -r requirements.txt +# during the build, the source code is only mounted, not copied +# some integration tests use CMD that requires the source code to be present +RUN cp -r /src /app +WORKDIR /app diff --git a/tests/integration/test_data/rpm_test_repo_file/cachi2.repo b/tests/integration/test_data/rpm_test_repo_file/cachi2.repo index f648ce94e..a35a590a9 100644 --- a/tests/integration/test_data/rpm_test_repo_file/cachi2.repo +++ b/tests/integration/test_data/rpm_test_repo_file/cachi2.repo @@ -1,13 +1,13 @@ [releases] -baseurl = file:///tmp/rpm_test_repo_file-output/deps/rpm/x86_64/releases +baseurl = file:///tmp/cachi2-output/deps/rpm/x86_64/releases gpgcheck = 1 [another-repoid] -baseurl = file:///tmp/rpm_test_repo_file-output/deps/rpm/x86_64/another-repoid +baseurl = file:///tmp/cachi2-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 +baseurl = file:///tmp/cachi2-output/deps/rpm/x86_64/cachi2-aaa000 name = Packages unaffiliated with an official repository gpgcheck = 1 diff --git a/tests/integration/test_data/yarn_classic_e2e_test/container/Containerfile b/tests/integration/test_data/yarn_classic_e2e_test/container/Containerfile index 302c7c5cf..723eec3b7 100644 --- a/tests/integration/test_data/yarn_classic_e2e_test/container/Containerfile +++ b/tests/integration/test_data/yarn_classic_e2e_test/container/Containerfile @@ -1,19 +1,9 @@ FROM docker.io/node:22.8.0 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check yarn deps -RUN ls /tmp/yarn_classic_e2e_test-output/deps/yarn-classic - -# Check content of source repository folder -RUN ls /tmp/yarn_classic_e2e_test-source/ - -# This should be a COPY, but the source code and Containerfile are in different directories -RUN cp -r /tmp/yarn_classic_e2e_test-source /src - WORKDIR /src -RUN . /tmp/cachi2.env && yarn install \ No newline at end of file +RUN . /tmp/cachi2.env && yarn install + +# during the build, the source code is only mounted, not copied +# some integration tests use CMD that requires the source code to be present +RUN cp -r /src /app +WORKDIR /app diff --git a/tests/integration/test_data/yarn_classic_e2e_test_multiple_packages/container/Containerfile b/tests/integration/test_data/yarn_classic_e2e_test_multiple_packages/container/Containerfile index c9b290131..b6a23e0d1 100644 --- a/tests/integration/test_data/yarn_classic_e2e_test_multiple_packages/container/Containerfile +++ b/tests/integration/test_data/yarn_classic_e2e_test_multiple_packages/container/Containerfile @@ -1,23 +1,12 @@ FROM docker.io/node:22.8.0 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check yarn deps -RUN ls /tmp/yarn_classic_e2e_test_multiple_packages-output/deps/yarn-classic - -# Check content of source repository folder -RUN ls /tmp/yarn_classic_e2e_test_multiple_packages-source - -WORKDIR /tmp/yarn_classic_e2e_test_multiple_packages-source/second-pkg +WORKDIR /src/first-pkg RUN . /tmp/cachi2.env && yarn install -WORKDIR /tmp/yarn_classic_e2e_test_multiple_packages-source/first-pkg +WORKDIR /src/second-pkg RUN . /tmp/cachi2.env && yarn install -# This should be a COPY, but the source code and Containerfile are in different directories -RUN cp -r /tmp/yarn_classic_e2e_test_multiple_packages-source/first-pkg /src -WORKDIR /src +# during the build, the source code is only mounted, not copied +# some integration tests use CMD that requires the source code to be present +RUN cp -r /src/first-pkg /app +WORKDIR /app diff --git a/tests/integration/test_data/yarn_e2e_test/container/Containerfile b/tests/integration/test_data/yarn_e2e_test/container/Containerfile index 10be458fd..3bec3599e 100644 --- a/tests/integration/test_data/yarn_e2e_test/container/Containerfile +++ b/tests/integration/test_data/yarn_e2e_test/container/Containerfile @@ -1,19 +1,9 @@ FROM docker.io/node:18.19.0 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check yarn deps -RUN ls /tmp/yarn_e2e_test-output/deps/yarn - -# Check content of source repository folder -RUN ls /tmp/yarn_e2e_test-source/ - -# This should be a COPY, but the source code and Containerfile are in different directories -RUN cp -r /tmp/yarn_e2e_test-source /src - WORKDIR /src RUN . /tmp/cachi2.env && yarn install --mode skip-build && yarn build + +# during the build, the source code is only mounted, not copied +# some integration tests use CMD that requires the source code to be present +RUN cp -r /src /app +WORKDIR /app diff --git a/tests/integration/test_data/yarn_e2e_test_multiple_packages/container/Containerfile b/tests/integration/test_data/yarn_e2e_test_multiple_packages/container/Containerfile index 1b5421ac2..cd9ff7e03 100644 --- a/tests/integration/test_data/yarn_e2e_test_multiple_packages/container/Containerfile +++ b/tests/integration/test_data/yarn_e2e_test_multiple_packages/container/Containerfile @@ -1,22 +1,12 @@ FROM docker.io/node:18.19.0 -# Test disabled network access -RUN if curl -IsS www.google.com; then echo "Has network access!"; exit 1; fi - -# Print cachi2 env vars file -RUN cat /tmp/cachi2.env - -# Check yarn deps -RUN ls /tmp/yarn_e2e_test_multiple_packages-output/deps/yarn/cache - -# Check content of source repository folder -RUN ls /tmp/yarn_e2e_test_multiple_packages-source - -WORKDIR /tmp/yarn_e2e_test_multiple_packages-source/second-pkg +WORKDIR /src/first-pkg RUN . /tmp/cachi2.env && yarn install -WORKDIR /tmp/yarn_e2e_test_multiple_packages-source/first-pkg +WORKDIR /src/second-pkg RUN . /tmp/cachi2.env && yarn install -RUN cp -r /tmp/yarn_e2e_test_multiple_packages-source/first-pkg /src -WORKDIR /src +# during the build, the source code is only mounted, not copied +# some integration tests use CMD that requires the source code to be present +RUN cp -r /src/first-pkg /app +WORKDIR /app diff --git a/tests/integration/test_generic.py b/tests/integration/test_generic.py index 00d4f9987..b8430b641 100644 --- a/tests/integration/test_generic.py +++ b/tests/integration/test_generic.py @@ -12,7 +12,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-generic", - ref="test-file-not-reachable", + ref="generic/file-not-reachable", packages=({"path": ".", "type": "generic"},), check_output=False, check_deps_checksums=False, @@ -28,6 +28,7 @@ def test_generic_fetcher( test_params: utils.TestParameters, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -39,17 +40,8 @@ def test_generic_fetcher( """ test_case = request.node.callspec.id - 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, + tmp_path, test_case, test_params, test_repo_dir, test_data_dir, cachi2_image ) @@ -59,7 +51,7 @@ def test_generic_fetcher( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-generic", - ref="test-e2e", + ref="generic/e2e", packages=({"path": ".", "type": "generic"},), check_output=True, check_deps_checksums=True, @@ -73,7 +65,7 @@ def test_generic_fetcher( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-generic", - ref="test-e2e-maven", + ref="generic/e2e-maven", packages=({"path": ".", "type": "generic"},), check_output=True, check_deps_checksums=True, @@ -92,6 +84,7 @@ def test_e2e_generic( expected_cmd_output: str, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -103,17 +96,13 @@ def test_e2e_generic( """ 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.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, - output_folder, + test_repo_dir, test_data_dir, test_case, check_cmd, diff --git a/tests/integration/test_gomod.py b/tests/integration/test_gomod.py index e731631bd..d869b8b4c 100644 --- a/tests/integration/test_gomod.py +++ b/tests/integration/test_gomod.py @@ -17,7 +17,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachito-gomod-with-deps.git", - ref="4c65d49cae6bfbada4d479b321d8c0109fa1aa97", + ref="gomod/with-deps", packages=({"path": ".", "type": "gomod"},), check_vendor_checksums=False, expected_exit_code=0, @@ -28,7 +28,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachito-gomod-without-deps.git", - ref="a888f7261b9a9683972fbd77da2d12fe86faef5e", + ref="gomod/without-deps", packages=({"path": ".", "type": "gomod"},), check_vendor_checksums=False, expected_exit_code=0, @@ -41,7 +41,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/gomod-vendor-check-pass.git", - ref="0543a5034b687df174c6b12b7b6b9c04770a856f", + ref="gomod/vendor-check-pass", packages=({"path": ".", "type": "gomod"},), flags=["--gomod-vendor-check"], expected_exit_code=0, @@ -53,7 +53,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/gomod-vendor-check-fail.git", - ref="8553df6498705b2b36614320ca0c65bc24a1d9e6", + ref="gomod/vendor-check-fail", packages=({"path": ".", "type": "gomod"},), flags=["--gomod-vendor-check"], check_output=False, @@ -71,7 +71,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/gomod-vendor-check-empty-vendor.git", - ref="9989e210ac2993196e22d0a23fe18ce460012058", + ref="gomod/vendor-check-empty", packages=({"path": ".", "type": "gomod"},), flags=["--gomod-vendor-check"], check_output=False, @@ -89,7 +89,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachito-gomod-local-deps.git", - ref="b2e465b91a6a272540c77d4dde1e317773ed700b", + ref="gomod/local-deps", packages=({"path": ".", "type": "gomod"},), check_vendor_checksums=False, expected_exit_code=0, @@ -104,7 +104,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/go-generate-imported.git", - ref="56659413f7db4f5feed9bbde4560cb55fbb85d67", + ref="gomod/generate-imported", packages=({"path": ".", "type": "gomod"},), check_vendor_checksums=False, expected_exit_code=0, @@ -118,7 +118,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/gomod-multiple-modules.git", - ref="5a8c00ce49210e4b42a02003ef9ed0d1574abdae", + ref="gomod/missing-checksums", packages=( {"path": ".", "type": "gomod"}, {"path": "spam-module", "type": "gomod"}, @@ -134,7 +134,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-gomod.git", - ref="449f904ecf268856ef335b2033cb64cc417b7c26", + ref="gomod/workspaces", packages=({"path": "./workspace_modules/hello", "type": "gomod"},), check_vendor_checksums=False, expected_exit_code=0, @@ -148,6 +148,7 @@ def test_gomod_packages( test_params: utils.TestParameters, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -159,12 +160,8 @@ def test_gomod_packages( """ test_case = request.node.callspec.id - 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 + utils.fetch_deps_and_check_output( + tmp_path, test_case, test_params, test_repo_dir, test_data_dir, cachi2_image ) @@ -177,7 +174,7 @@ def test_gomod_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/retrodep.git", - ref="c3496edd5d45523a1ed300de1575a212b86d00d3", + ref="gomod/e2e-1.18", packages=({"path": ".", "type": "gomod"},), check_vendor_checksums=False, expected_exit_code=0, @@ -193,7 +190,7 @@ def test_gomod_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/retrodep.git", - ref="d0c316edef82e527fed5713f9960cfe7f7c29945", + ref="gomod/e2e-1.21", packages=({"path": ".", "type": "gomod"},), check_vendor_checksums=False, expected_exit_code=0, @@ -208,7 +205,7 @@ def test_gomod_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/gomod-multiple-modules.git", - ref="d909c337ffc82c7b92a8efa1281a7b6e8152b4a7", + ref="gomod/e2e-multiple-modules", packages=( {"path": ".", "type": "gomod"}, {"path": "spam-module", "type": "gomod"}, @@ -227,7 +224,7 @@ def test_gomod_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-gomod", - ref="3353e452672851079f1926b6b2d7372447104b31", + ref="gomod/e2e-1.21-dirty", packages=({"path": "twenty", "type": "gomod"},), check_vendor_checksums=False, expected_exit_code=0, @@ -243,7 +240,7 @@ def test_gomod_packages( pytest.param( utils.TestParameters( repo="https://github.com/eskultety/cachito-testing-cachi2-gomod", - ref="5aabb6779a3263103d77f2829cdc8d083fe7e1c5", + ref="gomod/e2e-1.22-workspace-vendoring", packages=({"path": "hi/hiii", "type": "gomod"},), flags=["--gomod-vendor"], expected_exit_code=0, @@ -261,6 +258,7 @@ def test_e2e_gomod( expected_cmd_output: str, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -272,17 +270,13 @@ def test_e2e_gomod( """ 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.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, - output_folder, + test_repo_dir, test_data_dir, test_case, check_cmd, diff --git a/tests/integration/test_npm.py b/tests/integration/test_npm.py index a7c20dc94..caa464805 100644 --- a/tests/integration/test_npm.py +++ b/tests/integration/test_npm.py @@ -15,7 +15,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/npm-cachi2-bundled.git", - ref="de68ac6aa88a81272660b6d0f6d44ce157207799", + ref="npm/bundled-lockfile3", packages=({"path": ".", "type": "npm"},), check_vendor_checksums=False, ), @@ -24,7 +24,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/npm-cachi2-registry-yarnpkg.git", - ref="f830b62780e75357c38abb7e1102871b51bfbcfe", + ref="npm/yarn-registry-lockfile3", packages=({"path": ".", "type": "npm"},), check_vendor_checksums=False, ), @@ -36,6 +36,7 @@ def test_npm_packages( test_params: utils.TestParameters, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -47,12 +48,8 @@ def test_npm_packages( """ test_case = request.node.callspec.id - 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 + tmp_path, test_case, test_params, test_repo_dir, test_data_dir, cachi2_image ) @@ -62,7 +59,7 @@ def test_npm_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/npm-cachi2-smoketest.git", - ref="532dd79bde494e90fae261afbb7b464dae2d2e32", + ref="npm/smoketest-lockfile2", packages=({"path": ".", "type": "npm"},), check_vendor_checksums=False, ), @@ -73,7 +70,7 @@ def test_npm_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/npm-cachi2-smoketest.git", - ref="f1d31c2b051b218c84399b12461e0957d87bd0cd", + ref="npm/smoketest-lockfile3", packages=({"path": ".", "type": "npm"},), check_vendor_checksums=False, ), @@ -84,7 +81,7 @@ def test_npm_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachito-npm-with-multiple-dep-versions.git", - ref="97070a9eb06bad62eb581890731221660ade9ea3", + ref="npm/multiple-dep-versions", packages=({"path": ".", "type": "npm"},), check_vendor_checksums=False, ), @@ -95,7 +92,7 @@ def test_npm_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/npm-with-aliased-deps.git", - ref="48c5f156b43b8727b10bf464c00847b09e2f25f6", + ref="npm/aliased-deps", packages=({"path": ".", "type": "npm"},), check_vendor_checksums=False, ), @@ -117,7 +114,7 @@ def test_npm_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/npm-cachi2-multiple-packages.git", - ref="a721cb61d43d07b0d8276a5b8c4555b1ed75bd39", + ref="npm/multiple-packages", packages=( {"path": "first_pkg", "type": "npm"}, {"path": "second_pkg", "type": "npm"}, @@ -137,6 +134,7 @@ def test_e2e_npm( expected_cmd_output: str, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -148,17 +146,13 @@ def test_e2e_npm( """ 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.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, - output_folder, + test_repo_dir, test_data_dir, test_case, check_cmd, diff --git a/tests/integration/test_pip.py b/tests/integration/test_pip.py index f4a2e9d92..5a9b3c744 100644 --- a/tests/integration/test_pip.py +++ b/tests/integration/test_pip.py @@ -16,7 +16,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachito-pip-without-deps.git", - ref="3fe2fc3cb8ffa36317cacbd9d356e35e17af2824", + ref="pip/without-deps", packages=({"path": ".", "type": "pip"},), check_vendor_checksums=False, expected_exit_code=0, @@ -27,7 +27,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachito-pip-with-deps.git", - ref="56efa5f7eb4ff1b7ea1409dbad76f5bb378291e6", + ref="pip/mixed-hashes", packages=({"path": ".", "type": "pip"},), check_vendor_checksums=False, expected_exit_code=0, @@ -39,7 +39,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachito-pip-with-deps.git", - ref="bbe76b351bf06fcfbaede8f9e2050976d9fd6f3b", + ref="pip/full-hashes", packages=({"path": ".", "type": "pip"},), check_vendor_checksums=False, expected_exit_code=0, @@ -50,7 +50,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachito-pip-multiple.git", - ref="d8a0c2789446f4119604a0cc5e7eb97f30652f9f", + ref="pip/multiple-packages", packages=( {"path": "first_pkg", "type": "pip"}, { @@ -70,7 +70,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachito-pip-local-path.git", - ref="d66f7e029a15e8dc96ced65865344e6088c3fdd5", + ref="pip/local-path", packages=({"path": ".", "type": "pip"},), check_output=False, check_deps_checksums=False, @@ -87,7 +87,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-pip-extra.git", - ref="ece153b4e3eb1f64b3cd8e73b0de7fa8991c3afc", + ref="pip/no-metadata", packages=( {"path": ".", "type": "pip"}, {"path": "subpath1/subpath2", "type": "pip"}, @@ -101,7 +101,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-pip-extra.git", - ref="5f4d168cd573712e56914c326d5f7eff488d7f32", + ref="pip/yanked", packages=({"path": ".", "type": "pip"},), check_vendor_checksums=False, expected_exit_code=0, @@ -112,7 +112,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-pip-wheels.git", - ref="3697d63affaec82985f1d9b4035d5305e58c91d6", + ref="pip/no-wheels", packages=({"path": ".", "type": "pip", "allow_binary": "true"},), check_vendor_checksums=False, expected_exit_code=0, @@ -123,7 +123,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-pip-wheels.git", - ref="eee59273542ee7d412fb359d471386b645cf166e", + ref="pip/no-sdists", packages=({"path": ".", "type": "pip", "allow_binary": "false"},), check_output=False, check_deps_checksums=False, @@ -136,7 +136,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-pip-custom-index.git", - ref="55376bc13904c2f450aac6ee89969d539c8d9f05", + ref="pip/custom-index", packages=({"path": ".", "type": "pip", "allow_binary": True},), check_vendor_checksums=False, expected_exit_code=0, @@ -154,6 +154,7 @@ def test_pip_packages( test_params: utils.TestParameters, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -165,12 +166,8 @@ def test_pip_packages( """ test_case = request.node.callspec.id - 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 + utils.fetch_deps_and_check_output( + tmp_path, test_case, test_params, test_repo_dir, test_data_dir, cachi2_image ) @@ -183,7 +180,7 @@ def test_pip_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/pip-e2e-test.git", - ref="bae083d57dc265a899b59859b769e88eb8319404", + ref="pip/e2e", packages=( { "type": "pip", @@ -195,14 +192,14 @@ def test_pip_packages( expected_exit_code=0, expected_output="All dependencies fetched successfully", ), - ["python3", "/opt/test_package_cachi2"], + ["python3", "/app/src/test_package_cachi2/main.py"], ["registry.fedoraproject.org/fedora-minimal:37"], id="pip_e2e_test", ), pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-pip-wheels", - ref="eee59273542ee7d412fb359d471386b645cf166e", + ref="pip/e2e-wheels", packages=( { "type": "pip", @@ -215,7 +212,7 @@ def test_pip_packages( expected_exit_code=0, expected_output="All dependencies fetched successfully", ), - ["python3", "/opt/package"], + ["python3", "/app/package/main.py"], ["Hello, world!"], id="pip_e2e_test_wheels", ), @@ -227,6 +224,7 @@ def test_e2e_pip( expected_cmd_output: str, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -238,17 +236,13 @@ def test_e2e_pip( """ 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.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, - output_folder, + test_repo_dir, test_data_dir, test_case, check_cmd, diff --git a/tests/integration/test_rpm.py b/tests/integration/test_rpm.py index 2eee48b3a..bc823b0a6 100644 --- a/tests/integration/test_rpm.py +++ b/tests/integration/test_rpm.py @@ -15,7 +15,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-rpm", - ref="missing-checksum", + ref="rpm/missing-checksum", packages=({"path": ".", "type": "rpm"},), flags=["--dev-package-managers"], check_output=True, @@ -28,7 +28,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-rpm", - ref="unmatched-checksum", + ref="rpm/unmatched-checksum", packages=({"path": ".", "type": "rpm"},), flags=["--dev-package-managers"], check_output=False, @@ -42,7 +42,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-rpm", - ref="unexpected-size", + ref="rpm/unexpected-size", packages=({"path": ".", "type": "rpm"},), flags=["--dev-package-managers"], check_output=False, @@ -56,7 +56,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-rpm", - ref="multiple-packages", + ref="rpm/multiple-packages", packages=( {"path": "this-project", "type": "rpm"}, {"path": "another-project", "type": "rpm"}, @@ -72,7 +72,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-rpm", - ref="multiple-archs", + ref="rpm/multiple-archs", packages=({"path": ".", "type": "rpm"},), flags=["--dev-package-managers"], check_output=True, @@ -85,7 +85,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-rpm", - ref="dnf_tls_client_auth", + ref="rpm/dnf-tls-client-auth", packages=( { "path": ".", @@ -115,7 +115,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-rpm", - ref="multiple-packages", + ref="rpm/multiple-packages", packages=( {"path": "this-project", "type": "rpm", "include_summary_in_sbom": "true"}, {"path": "another-project", "type": "rpm"}, @@ -134,6 +134,7 @@ def test_rpm_packages( test_params: utils.TestParameters, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, top_level_test_dir: Path, request: pytest.FixtureRequest, @@ -146,15 +147,11 @@ def test_rpm_packages( """ test_case = request.node.callspec.id - 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_repo_dir, test_data_dir, cachi2_image, mounts=[(top_level_test_dir / "dnfserver/certificates", "/certificates")], @@ -167,7 +164,7 @@ def test_rpm_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-rpm", - ref="test-repo-file", + ref="rpm/repo-file", packages=({"path": ".", "type": "rpm"},), flags=["--dev-package-managers"], check_output=False, @@ -183,19 +180,16 @@ def test_repo_files( test_params: utils.TestParameters, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: 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 - ) + output_folder = tmp_path.joinpath("cachi2-output") utils.fetch_deps_and_check_output( - tmp_path, test_case, test_params, source_folder, test_data_dir, cachi2_image + tmp_path, test_case, test_params, test_repo_dir, test_data_dir, cachi2_image ) # call inject-files to create the .repo file @@ -203,7 +197,7 @@ def test_repo_files( "inject-files", output_folder, "--for-output-dir", - Path("/tmp", f"{test_case}-output"), + Path("/tmp", utils.DEFAULT_OUTPUT_DIR), ] (output, exit_code) = cachi2_image.run_cmd_on_image(cmd, tmp_path) assert exit_code == 0, f"Injecting project files failed. output-cmd: {output}" @@ -248,7 +242,7 @@ def read_and_normalize_repofile(path: Path) -> str: pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-rpm.git", - ref="e2e", + ref="rpm/e2e", packages=( { "type": "rpm", @@ -268,7 +262,7 @@ def read_and_normalize_repofile(path: Path) -> str: pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-rpm.git", - ref="e2e-modularity", + ref="rpm/e2e-modularity", packages=( { "type": "rpm", @@ -290,6 +284,7 @@ def test_e2e_rpm( expected_cmd_output: str, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -301,17 +296,13 @@ def test_e2e_rpm( """ 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.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, - output_folder, + test_repo_dir, test_data_dir, test_case, check_cmd, diff --git a/tests/integration/test_yarn.py b/tests/integration/test_yarn.py index 32f380e13..b9fe8aae5 100644 --- a/tests/integration/test_yarn.py +++ b/tests/integration/test_yarn.py @@ -14,7 +14,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn-berry.git", - ref="08f09b9340c85fbb84c8fb46fc19a235056a178b", + ref="yarn/zero-installs", packages=({"path": ".", "type": "yarn"},), check_output=False, check_deps_checksums=False, @@ -27,7 +27,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn-berry.git", - ref="ea24d50fcc20f44f74fc0e7beb482c18349b1002", + ref="yarn/disallowed-protocols", packages=({"path": ".", "type": "yarn"},), check_output=False, check_vendor_checksums=False, @@ -40,7 +40,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn-berry.git", - ref="712e2e1baff80f8ad6e493babf08318b9051b3c7", + ref="yarn/corepack-install", packages=({"path": ".", "type": "yarn"},), check_vendor_checksums=False, expected_exit_code=0, @@ -51,7 +51,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn-berry.git", - ref="53a2bfe8d5ee7ed9c2f752fe75831a881d54895f", + ref="yarn/v4", packages=({"path": ".", "type": "yarn"},), check_vendor_checksums=False, expected_exit_code=0, @@ -62,7 +62,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn-berry.git", - ref="9d6a941220a1dfb14a6bdb6f3c52d7204a939688", + ref="yarn/immutable-installs", packages=({"path": ".", "type": "yarn"},), check_output=False, check_vendor_checksums=False, @@ -75,7 +75,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn-berry.git", - ref="c5268f91f0a0b68fa72d4f2c3a570d348d194241", + ref="yarn/incorrect-checksum", packages=({"path": ".", "type": "yarn"},), check_output=False, check_deps_checksums=False, @@ -88,7 +88,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn-berry.git", - ref="c1da60842aa94aaab8ed48122dc44522bd2a5ab1", + ref="yarn/missing-lockfile", packages=({"path": ".", "type": "yarn"},), check_output=False, check_deps_checksums=False, @@ -104,6 +104,7 @@ def test_yarn_packages( test_params: utils.TestParameters, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -115,12 +116,8 @@ def test_yarn_packages( """ test_case = request.node.callspec.id - 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 + tmp_path, test_case, test_params, test_repo_dir, test_data_dir, cachi2_image ) @@ -130,7 +127,7 @@ def test_yarn_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn-berry.git", - ref="70515793108df42547d3320c7ea4cd6b6e505c46", + ref="yarn/e2e", packages=({"path": ".", "type": "yarn"},), check_vendor_checksums=False, expected_exit_code=0, @@ -143,7 +140,7 @@ def test_yarn_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn-berry.git", - ref="b6f47bd07e669c8d2eced8015c4bfb06db499493", + ref="yarn/e2e-multiple-packages", packages=( {"path": "first-pkg", "type": "yarn"}, {"path": "second-pkg", "type": "yarn"}, @@ -164,23 +161,20 @@ def test_e2e_yarn( 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 yarn berry.""" 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.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, - output_folder, + test_repo_dir, test_data_dir, test_case, check_cmd, diff --git a/tests/integration/test_yarn_classic.py b/tests/integration/test_yarn_classic.py index 186f2a658..ebea602c6 100644 --- a/tests/integration/test_yarn_classic.py +++ b/tests/integration/test_yarn_classic.py @@ -14,7 +14,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn.git", - ref="corepack_packagemanager_ignored", + ref="yarn-classic/corepack-ignored", packages=({"path": ".", "type": "yarn"},), flags=["--dev-package-managers"], check_output=False, @@ -28,7 +28,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn.git", - ref="yarnpath_ignored", + ref="yarn-classic/yarn-path-ignored", packages=({"path": ".", "type": "yarn"},), flags=["--dev-package-managers"], check_output=False, @@ -42,7 +42,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn.git", - ref="invalid_checksum", + ref="yarn-classic/invalid-checksum", packages=({"path": ".", "type": "yarn"},), flags=["--dev-package-managers"], check_output=False, @@ -56,7 +56,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn.git", - ref="invalid_frozen_lockfile_add_dependency", + ref="yarn-classic/frozen-lockfile", packages=({"path": ".", "type": "yarn"},), flags=["--dev-package-managers"], check_output=False, @@ -70,7 +70,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn.git", - ref="lifecycle_scripts", + ref="yarn-classic/lifecycle-scripts", packages=({"path": ".", "type": "yarn"},), flags=["--dev-package-managers"], check_output=False, @@ -84,7 +84,7 @@ pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn.git", - ref="offline-mirror-collision", + ref="yarn-classic/offline-mirror-collision", packages=({"path": ".", "type": "yarn"},), flags=["--dev-package-managers"], check_output=False, @@ -101,6 +101,7 @@ def test_yarn_classic_packages( test_params: utils.TestParameters, cachi2_image: utils.ContainerImage, tmp_path: Path, + test_repo_dir: Path, test_data_dir: Path, request: pytest.FixtureRequest, ) -> None: @@ -112,12 +113,8 @@ def test_yarn_classic_packages( """ test_case = request.node.callspec.id - 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 + tmp_path, test_case, test_params, test_repo_dir, test_data_dir, cachi2_image ) @@ -127,7 +124,7 @@ def test_yarn_classic_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn.git", - ref="valid_yarn_all_dependency_types", + ref="yarn-classic/e2e", packages=({"path": ".", "type": "yarn"},), check_vendor_checksums=False, expected_exit_code=0, @@ -140,7 +137,7 @@ def test_yarn_classic_packages( pytest.param( utils.TestParameters( repo="https://github.com/cachito-testing/cachi2-yarn.git", - ref="valid_multiple_packages", + ref="yarn-classic/e2e-multiple-packages", packages=( {"path": "first-pkg", "type": "yarn"}, {"path": "second-pkg", "type": "yarn"}, @@ -161,23 +158,20 @@ def test_e2e_yarn_classic( 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 yarn classic.""" 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.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, - output_folder, + test_repo_dir, test_data_dir, test_case, check_cmd, diff --git a/tests/integration/utils.py b/tests/integration/utils.py index 60c77ba92..bb8c65f1a 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -60,6 +60,9 @@ "https://raw.githubusercontent.com/CycloneDX/specification/1.4/schema/bom-1.4.schema.json" ) +DEFAULT_OUTPUT_DIR = Path("cachi2-output") +DEFAULT_ENV_FILE = Path("cachi2.env") + @dataclass class TestParameters: @@ -94,12 +97,12 @@ def pull_image(self) -> None: def run_cmd_on_image( self, - cmd: List, - tmpdir: StrPath, + cmd: list[Any], + tmp_path: Path, mounts: Sequence[tuple[StrPath, StrPath]] = (), net: Optional[str] = None, ) -> Tuple[str, int]: - flags = ["-v", f"{tmpdir}:{tmpdir}:z"] + flags = ["-v", f"{tmp_path}:{tmp_path}:z"] for src, dest in mounts: flags.append("-v") flags.append(f"{src}:{dest}:z") @@ -118,8 +121,8 @@ def __exit__(self, exc_type: Any, exc_value: Any, exc_traceback: Any) -> None: class Cachi2Image(ContainerImage): def run_cmd_on_image( self, - cmd: List, - tmpdir: StrPath, + cmd: list[Any], + tmp_path: Path, mounts: Sequence[tuple[StrPath, StrPath]] = (), net: Optional[str] = "host", ) -> Tuple[str, int]: @@ -129,30 +132,42 @@ def run_cmd_on_image( netrc_path = Path(netrc_tmpdir, ".netrc") netrc_path.write_text(netrc_content) return super().run_cmd_on_image( - cmd, tmpdir, [*mounts, (netrc_path, "/root/.netrc")], net + cmd, tmp_path, [*mounts, (netrc_path, "/root/.netrc")], net ) - return super().run_cmd_on_image(cmd, tmpdir, mounts, net) + return super().run_cmd_on_image(cmd, tmp_path, mounts, net) def build_image(context_dir: Path, tag: str) -> ContainerImage: return _build_image(["podman", "build", str(context_dir)], tag=tag) -def build_image_for_test_case(tmp_path: Path, containerfile: str, test_case: str) -> ContainerImage: +def build_image_for_test_case( + source_dir: Path, + output_dir: Path, + containerfile_path: Path, + test_case: str, +) -> ContainerImage: + # mounts the source code of the test case + source_dir_mount_point = "/src" + # mounts the output of the fetch-deps command and cachi2.env + output_dir_mount_point = "/tmp" + cmd = [ "podman", "build", "-f", - containerfile, + str(containerfile_path), "-v", - f"{tmp_path}:/tmp:Z", + f"{source_dir}:{source_dir_mount_point}:Z", + "-v", + f"{output_dir}:{output_dir_mount_point}:Z", "--no-cache", "--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" + rpm_repos_path = f"{output_dir}/cachi2-output/deps/rpm/x86_64/repos.d" if Path(rpm_repos_path).exists(): cmd.extend( [ @@ -328,37 +343,50 @@ def fetch_deps_and_check_output( tmp_path: Path, test_case: str, test_params: TestParameters, - source_folder: Path, + test_repo_dir: Path, test_data_dir: Path, cachi2_image: ContainerImage, mounts: Sequence[tuple[StrPath, StrPath]] = (), -) -> Path: +) -> None: """ Fetch dependencies for source repo and check expected output. - :param tmp_path: Temp directory for pytest + :param tmp_path: pytest fixture :param test_case: Test case name retrieved from pytest id :param test_params: Test case arguments - :param source_folder: Folder path to source repository content + :param test_repo_dir: Path to source repository :param test_data_dir: Relative path to expected output test data :param cachi2_image: ContainerImage instance with Cachi2 image :param mounts: Additional volumes to be mounted to the image - :return: Path to output folder with fetched dependencies and output.json + :return: None """ - output_folder = tmp_path.joinpath(f"{test_case}-output") + repo = Repo(test_repo_dir) + repo.git.reset("--hard") + repo.git.clean("-fdx") + + node_modules = test_repo_dir.joinpath("node_modules") + shutil.rmtree(node_modules, ignore_errors=True) + + repo.git.checkout(test_params.ref) + + output_dir = tmp_path.joinpath(DEFAULT_OUTPUT_DIR) cmd = [ "fetch-deps", "--source", - source_folder, + test_repo_dir, "--output", - output_folder, + output_dir, ] if test_params.flags: cmd += test_params.flags cmd.append(json.dumps(test_params.packages).encode("utf-8")) - (output, exit_code) = cachi2_image.run_cmd_on_image(cmd, tmp_path, mounts) + (output, exit_code) = cachi2_image.run_cmd_on_image( + cmd, + tmp_path, + [*mounts, (test_repo_dir, test_repo_dir)], + ) assert exit_code == test_params.expected_exit_code, ( f"Fetching deps ended with unexpected exitcode: {exit_code} != " f"{test_params.expected_exit_code}, output-cmd: {output}" @@ -368,11 +396,11 @@ def fetch_deps_and_check_output( ), f"Expected msg {test_params.expected_output} was not found in cmd output: {output}" if test_params.check_output: - build_config = _load_json_or_yaml(output_folder.joinpath(".build-config.json")) - sbom = _load_json_or_yaml(output_folder.joinpath("bom.json")) + build_config = _load_json_or_yaml(output_dir.joinpath(".build-config.json")) + sbom = _load_json_or_yaml(output_dir.joinpath("bom.json")) if "project_files" in build_config: - _replace_tmp_path_with_placeholder(build_config["project_files"], tmp_path) + _replace_tmp_path_with_placeholder(build_config["project_files"], test_repo_dir) # store .build_config as yaml for more readable test data expected_build_config_path = test_data_dir.joinpath(test_case, ".build-config.yaml") @@ -394,10 +422,10 @@ def fetch_deps_and_check_output( deps_content_file = Path(test_data_dir, test_case, "fetch_deps_file_contents.yaml") if deps_content_file.exists(): - _validate_expected_dep_file_contents(deps_content_file, Path(output_folder)) + _validate_expected_dep_file_contents(deps_content_file, output_dir) if test_params.check_deps_checksums: - files_checksums = _calculate_files_checksums_in_dir(output_folder.joinpath("deps")) + files_checksums = _calculate_files_checksums_in_dir(output_dir.joinpath("deps")) expected_files_checksums_path = test_data_dir.joinpath( test_data_dir, test_case, "fetch_deps_sha256sums.json" ) @@ -408,7 +436,7 @@ def fetch_deps_and_check_output( assert files_checksums == expected_files_checksums if test_params.check_vendor_checksums: - files_checksums = _calculate_files_checksums_in_dir(source_folder.joinpath("vendor")) + files_checksums = _calculate_files_checksums_in_dir(test_repo_dir.joinpath("vendor")) expected_files_checksums_path = test_data_dir.joinpath(test_case, "vendor_sha256sums.json") update_test_data_if_needed(expected_files_checksums_path, files_checksums) expected_files_checksums = _load_json_or_yaml(expected_files_checksums_path) @@ -416,12 +444,10 @@ def fetch_deps_and_check_output( log.info("Compare checksums of files in source vendor folder") assert files_checksums == expected_files_checksums - return output_folder - def build_image_and_check_cmd( tmp_path: Path, - output_folder: Path, + test_repo_dir: Path, test_data_dir: Path, test_case: str, check_cmd: List, @@ -431,55 +457,71 @@ def build_image_and_check_cmd( """ Build image and check that Cachi2 provided sources properly. - :param tmp_path: Temp directory for pytest - :param output_folder: Path to output folder with fetched dependencies and output.json - :param test_case: Test case name retrieved from pytest id + :param tmp_path: pytest fixture + :param test_repo_dir: Path to source repository :param test_data_dir: Relative path to expected output test data + :param test_case: Test case name retrieved from pytest id :param check_cmd: Command to be run on image to check provided sources :param expected_cmd_output: Expected output of check_cmd :param cachi2_image: ContainerImage instance with Cachi2 image + :return: None """ - log.info("Create cachi2.env file") - env_vars_file = tmp_path.joinpath("cachi2.env") + output_dir = tmp_path.joinpath(DEFAULT_OUTPUT_DIR) + + log.info("Creating cachi2.env file") + env_vars_file = tmp_path.joinpath(DEFAULT_ENV_FILE) cmd = [ "generate-env", - output_folder, + output_dir, "--output", env_vars_file, "--for-output-dir", - Path("/tmp").joinpath(f"{test_case}-output"), + Path("/tmp").joinpath(DEFAULT_OUTPUT_DIR), ] (output, exit_code) = cachi2_image.run_cmd_on_image(cmd, tmp_path) assert exit_code == 0, f"Env var file creation failed. output-cmd: {output}" - log.info("Inject project files") + log.info("Injecting project files") cmd = [ "inject-files", - output_folder, + output_dir, "--for-output-dir", - Path("/tmp").joinpath(f"{test_case}-output"), + Path("/tmp").joinpath(DEFAULT_OUTPUT_DIR), ] - (output, exit_code) = cachi2_image.run_cmd_on_image(cmd, tmp_path) + (output, exit_code) = cachi2_image.run_cmd_on_image( + cmd, tmp_path, [(test_repo_dir, test_repo_dir)] + ) assert exit_code == 0, f"Injecting project files failed. output-cmd: {output}" log.info("Build container image with all prerequisites retrieved in previous steps") container_folder = test_data_dir.joinpath(test_case, "container") - with build_image_for_test_case( - tmp_path, str(container_folder.joinpath("Containerfile")), test_case - ) as test_image: - log.info(f"Run command {check_cmd} on built image {test_image.repository}") - (output, exit_code) = test_image.run_cmd_on_image(check_cmd, tmp_path) + test_image = build_image_for_test_case( + source_dir=test_repo_dir, + output_dir=tmp_path, + containerfile_path=container_folder.joinpath("Containerfile"), + test_case=test_case, + ) + + log.info(f"Run command {check_cmd} on built image {test_image.repository}") + (output, exit_code) = test_image.run_cmd_on_image(check_cmd, tmp_path) - assert exit_code == 0, f"{check_cmd} command failed, Output: {output}" - for expected_output in expected_cmd_output: - assert expected_output in output, f"{expected_output} is missing in {output}" + assert exit_code == 0, f"{check_cmd} command failed, Output: {output}" + for expected_output in expected_cmd_output: + assert expected_output in output, f"{expected_output} is missing in {output}" -def _replace_tmp_path_with_placeholder(project_files: list[dict[str, str]], tmp_path: Path) -> None: +def _replace_tmp_path_with_placeholder( + project_files: list[dict[str, str]], test_repo_dir: Path +) -> None: for item in project_files: - relative_path = item["abspath"].replace(str(tmp_path), "") - item["abspath"] = "${test_case_tmpdir}" + str(relative_path) + if "bundler" in item["abspath"]: + # special case for bundler, as it is not a real project file + item["abspath"] = "${test_case_tmp_path}/cachi2-output/bundler/config_override/config" + continue + + relative_path = Path(item["abspath"]).relative_to(test_repo_dir) + item["abspath"] = "${test_case_tmp_path}/" + str(relative_path) def _validate_expected_dep_file_contents(dep_contents_file: Path, output_dir: Path) -> None: