Skip to content

Commit

Permalink
bundler: Adding e2e tests
Browse files Browse the repository at this point in the history
This commit adds e2e to bundler. The tests verify that
gems pre-fetched with cachi2 could be built in isolation.

Signed-off-by: Alexey Ovchinnikov <[email protected]>
  • Loading branch information
a-ovchinnikov committed Oct 18, 2024
1 parent dbdac14 commit c6c1d49
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/integration/test_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,76 @@ def test_bundler_packages(
utils.fetch_deps_and_check_output(
tmp_path, test_case, test_params, source_folder, test_data_dir, cachi2_image
)


@pytest.mark.parametrize(
"test_params,check_cmd,expected_cmd_output",
[
pytest.param(
utils.TestParameters(
repo="https://github.com/cachito-testing/cachi2-bundler.git",
ref="well_formed_ruby_all_features",
packages=({"path": ".", "type": "bundler", "allow_binary": "true"},),
flags=["--dev-package-managers"],
check_output=False,
check_deps_checksums=False,
check_vendor_checksums=False,
expected_exit_code=0,
expected_output="",
),
[], # No additional commands are run to verify the build
[],
id="bundler_everything_present",
),
pytest.param(
utils.TestParameters(
repo="https://github.com/cachito-testing/cachi2-bundler.git",
ref="well_formed_ruby_without_gemspec",
packages=({"path": ".", "type": "bundler", "allow_binary": "true"},),
flags=["--dev-package-managers"],
check_output=False,
check_deps_checksums=False,
check_vendor_checksums=False,
expected_exit_code=0,
expected_output="",
),
[], # No additional commands are run to verify the build
[],
id="bundler_everything_present_except_gemspec",
),
],
)
def test_e2e_bundler(
test_params: utils.TestParameters,
check_cmd: list[str],
expected_cmd_output: str,
cachi2_image: utils.ContainerImage,
tmp_path: Path,
test_data_dir: Path,
request: pytest.FixtureRequest,
) -> None:
"""
End to end test for bundler.
:param test_params: Test case arguments
:param tmp_path: Temp directory for pytest
"""
test_case = request.node.callspec.id

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.build_image_and_check_cmd(
tmp_path,
output_folder,
test_data_dir,
test_case,
check_cmd,
expected_cmd_output,
cachi2_image,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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

0 comments on commit c6c1d49

Please sign in to comment.