mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-16 22:10:07 -06:00
test docker and docker_image directly
This commit is contained in:
27
tests/languages/docker_image_test.py
Normal file
27
tests/languages/docker_image_test.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pre_commit.languages import docker_image
|
||||
from testing.language_helpers import run_language
|
||||
from testing.util import xfailif_windows
|
||||
|
||||
|
||||
@xfailif_windows # pragma: win32 no cover
|
||||
def test_docker_image_hook_via_entrypoint(tmp_path):
|
||||
ret = run_language(
|
||||
tmp_path,
|
||||
docker_image,
|
||||
'--entrypoint echo ubuntu:22.04',
|
||||
args=('hello hello world',),
|
||||
)
|
||||
assert ret == (0, b'hello hello world\n')
|
||||
|
||||
|
||||
@xfailif_windows # pragma: win32 no cover
|
||||
def test_docker_image_hook_via_args(tmp_path):
|
||||
ret = run_language(
|
||||
tmp_path,
|
||||
docker_image,
|
||||
'ubuntu:22.04 echo',
|
||||
args=('hello hello world',),
|
||||
)
|
||||
assert ret == (0, b'hello hello world\n')
|
||||
@@ -11,6 +11,8 @@ import pytest
|
||||
|
||||
from pre_commit.languages import docker
|
||||
from pre_commit.util import CalledProcessError
|
||||
from testing.language_helpers import run_language
|
||||
from testing.util import xfailif_windows
|
||||
|
||||
DOCKER_CGROUP_EXAMPLE = b'''\
|
||||
12:hugetlb:/docker/c33988ec7651ebc867cb24755eaf637a6734088bc7eef59d5799293a9e5450f7
|
||||
@@ -181,3 +183,15 @@ def test_get_docker_path_in_docker_docker_in_docker(in_docker):
|
||||
err = CalledProcessError(1, (), b'', b'')
|
||||
with mock.patch.object(docker, 'cmd_output_b', side_effect=err):
|
||||
assert docker._get_docker_path('/project') == '/project'
|
||||
|
||||
|
||||
@xfailif_windows # pragma: win32 no cover
|
||||
def test_docker_hook(tmp_path):
|
||||
dockerfile = '''\
|
||||
FROM ubuntu:22.04
|
||||
CMD ["echo", "This is overwritten by the entry"']
|
||||
'''
|
||||
tmp_path.joinpath('Dockerfile').write_text(dockerfile)
|
||||
|
||||
ret = run_language(tmp_path, docker, 'echo hello hello world')
|
||||
assert ret == (0, b'hello hello world\n')
|
||||
|
||||
@@ -30,7 +30,6 @@ from testing.fixtures import make_repo
|
||||
from testing.fixtures import modify_manifest
|
||||
from testing.util import cwd
|
||||
from testing.util import get_resource_path
|
||||
from testing.util import skipif_cant_run_docker
|
||||
|
||||
|
||||
def _norm_out(b):
|
||||
@@ -163,45 +162,6 @@ def test_language_versioned_python_hook(tempdir_factory, store):
|
||||
)
|
||||
|
||||
|
||||
@skipif_cant_run_docker # pragma: win32 no cover
|
||||
def test_run_a_docker_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'docker_hooks_repo',
|
||||
'docker-hook',
|
||||
['Hello World from docker'], b'Hello World from docker\n',
|
||||
)
|
||||
|
||||
|
||||
@skipif_cant_run_docker # pragma: win32 no cover
|
||||
def test_run_a_docker_hook_with_entry_args(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'docker_hooks_repo',
|
||||
'docker-hook-arg',
|
||||
['Hello World from docker'], b'Hello World from docker',
|
||||
)
|
||||
|
||||
|
||||
@skipif_cant_run_docker # pragma: win32 no cover
|
||||
def test_run_a_failing_docker_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'docker_hooks_repo',
|
||||
'docker-hook-failing',
|
||||
['Hello World from docker'],
|
||||
mock.ANY, # an error message about `bork` not existing
|
||||
expected_return_code=127,
|
||||
)
|
||||
|
||||
|
||||
@skipif_cant_run_docker # pragma: win32 no cover
|
||||
@pytest.mark.parametrize('hook_id', ('echo-entrypoint', 'echo-cmd'))
|
||||
def test_run_a_docker_image_hook(tempdir_factory, store, hook_id):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'docker_image_hooks_repo',
|
||||
hook_id,
|
||||
['Hello World from docker'], b'Hello World from docker\n',
|
||||
)
|
||||
|
||||
|
||||
def test_system_hook_with_spaces(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'system_hook_with_spaces_repo',
|
||||
|
||||
Reference in New Issue
Block a user