diff --git a/tests/integration/test_bundler.py b/tests/integration/test_bundler.py index 416295b4d..9ecdb583f 100644 --- a/tests/integration/test_bundler.py +++ b/tests/integration/test_bundler.py @@ -13,8 +13,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, @@ -26,8 +25,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, @@ -39,8 +37,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 +53,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 ) @@ -76,8 +70,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, @@ -91,8 +84,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 +104,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 +116,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..cc1eb3d9b 100644 --- a/tests/integration/test_generic.py +++ b/tests/integration/test_generic.py @@ -11,8 +11,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 +27,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 +39,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 ) @@ -58,8 +49,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, @@ -72,8 +62,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 +81,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 +93,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..8f59d4576 100644 --- a/tests/integration/test_gomod.py +++ b/tests/integration/test_gomod.py @@ -16,8 +16,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, @@ -27,8 +26,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, @@ -40,8 +38,7 @@ # source repo, deps folder in output folder should be empty. 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, @@ -52,8 +49,7 @@ # Test case checks if request will fail when source provided wrong vendor. 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, @@ -70,8 +66,7 @@ # Test case checks if request will fail when source provided empty vendor. 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, @@ -88,8 +83,7 @@ # Test case checks if package can be replaced with local dependency 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, @@ -103,8 +97,7 @@ # a package and `foobar` as its dependency. 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, @@ -117,8 +110,7 @@ # See also https://github.com/cachito-testing/gomod-multiple-modules/tree/missing-checksums 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"}, @@ -133,8 +125,7 @@ # Test case checks if cachi2 can process go workspaces properly. 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 +139,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 +151,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 ) @@ -176,8 +164,7 @@ def test_gomod_packages( # app in built image 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, @@ -192,8 +179,7 @@ def test_gomod_packages( # app in built image. The retrodep module specifies minimum go version 1.21. 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, @@ -207,8 +193,7 @@ def test_gomod_packages( # repository for more details. 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"}, @@ -226,8 +211,7 @@ def test_gomod_packages( # update the go directive in go.mod, but go versions >= 1.21 will and dirty the repository 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, @@ -242,8 +226,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 +244,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 +256,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..0f7bc163d 100644 --- a/tests/integration/test_npm.py +++ b/tests/integration/test_npm.py @@ -14,8 +14,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, ), @@ -23,8 +22,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 +34,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 +46,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 ) @@ -61,8 +56,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, ), @@ -72,8 +66,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, ), @@ -83,8 +76,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, ), @@ -94,8 +86,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, ), @@ -105,7 +96,6 @@ def test_npm_packages( ), pytest.param( utils.TestParameters( - repo="https://github.com/cachito-testing/npm-dev-optional-peer-deps.git", ref="77018bf73295ef1248d24479da897d960576f933", packages=({"path": ".", "type": "npm"},), check_vendor_checksums=False, @@ -116,8 +106,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 +126,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 +138,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..3ad575208 100644 --- a/tests/integration/test_pip.py +++ b/tests/integration/test_pip.py @@ -15,8 +15,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, @@ -26,8 +25,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, @@ -38,8 +36,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, @@ -49,8 +46,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"}, { @@ -69,8 +65,7 @@ # Test case checks that an attempt to fetch a local file will result in failure. 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, @@ -86,8 +81,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"}, @@ -100,8 +94,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, @@ -111,8 +104,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, @@ -122,8 +114,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, @@ -135,8 +126,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 +144,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 +156,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 ) @@ -182,8 +169,7 @@ def test_pip_packages( # in built image pytest.param( utils.TestParameters( - repo="https://github.com/cachito-testing/pip-e2e-test.git", - ref="bae083d57dc265a899b59859b769e88eb8319404", + ref="pip/e2e", packages=( { "type": "pip", @@ -195,14 +181,13 @@ 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 +200,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 +212,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 +224,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..f8eb681a4 100644 --- a/tests/integration/test_rpm.py +++ b/tests/integration/test_rpm.py @@ -14,8 +14,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, @@ -27,8 +26,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, @@ -41,8 +39,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, @@ -55,8 +52,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"}, @@ -71,8 +67,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, @@ -84,8 +79,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": ".", @@ -114,8 +108,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 +127,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 +140,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")], @@ -166,8 +156,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,27 +172,24 @@ 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_dir = tmp_path.joinpath(utils.DEFAULT_OUTPUT_DIR) 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 cmd = [ "inject-files", - output_folder, + str(output_dir), "--for-output-dir", - Path("/tmp", f"{test_case}-output"), + f"/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}" @@ -217,7 +203,7 @@ def read_and_normalize_repofile(path: Path) -> str: return re.sub(r"cachi2-[a-f0-9]{6}", "cachi2-aaa000", file.read()) repo_file_content = read_and_normalize_repofile( - output_folder.joinpath("deps/rpm/x86_64/repos.d/cachi2.repo") + output_dir.joinpath("deps/rpm/x86_64/repos.d/cachi2.repo") ) # update test data if needed @@ -247,8 +233,7 @@ def read_and_normalize_repofile(path: Path) -> str: # RPMs were properly installed pytest.param( utils.TestParameters( - repo="https://github.com/cachito-testing/cachi2-rpm.git", - ref="e2e", + ref="rpm/e2e", packages=( { "type": "rpm", @@ -267,8 +252,7 @@ def read_and_normalize_repofile(path: Path) -> str: # if the RPMs (including modular packages) were properly installed. 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 +274,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 +286,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..7705792af 100644 --- a/tests/integration/test_yarn.py +++ b/tests/integration/test_yarn.py @@ -13,8 +13,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, @@ -26,8 +25,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, @@ -39,8 +37,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, @@ -50,8 +47,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, @@ -61,8 +57,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, @@ -74,8 +69,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, @@ -87,8 +81,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 +97,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 +109,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 ) @@ -129,8 +119,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, @@ -142,8 +131,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 +152,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..b0230354c 100644 --- a/tests/integration/test_yarn_classic.py +++ b/tests/integration/test_yarn_classic.py @@ -13,8 +13,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, @@ -27,8 +26,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, @@ -41,8 +39,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, @@ -55,8 +52,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, @@ -69,8 +65,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, @@ -83,8 +78,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 +95,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 +107,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 ) @@ -126,8 +117,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, @@ -139,8 +129,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 +150,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..56e26f263 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -60,10 +60,12 @@ "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: - repo: str ref: str packages: Tuple[Dict[str, Any], ...] check_output: bool = True @@ -94,12 +96,12 @@ def pull_image(self) -> None: def run_cmd_on_image( self, - cmd: List, - tmpdir: StrPath, + cmd: list[str], + 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 +120,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[str], + tmp_path: Path, mounts: Sequence[tuple[StrPath, StrPath]] = (), net: Optional[str] = "host", ) -> Tuple[str, int]: @@ -129,30 +131,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 +342,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 for temporary directory :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, + str(test_repo_dir), "--output", - output_folder, + str(output_dir), ] if test_params.flags: cmd += test_params.flags - cmd.append(json.dumps(test_params.packages).encode("utf-8")) + cmd.append(json.dumps(test_params.packages)) - (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 +395,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 +421,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 +435,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 +443,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 +456,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 for temporary directory + :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, + str(output_dir), "--output", - env_vars_file, + str(env_vars_file), "--for-output-dir", - Path("/tmp").joinpath(f"{test_case}-output"), + f"/tmp/{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, + str(output_dir), "--for-output-dir", - Path("/tmp").joinpath(f"{test_case}-output"), + f"/tmp/{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: