From c04652e706a6dfa96cf5308860c5dc99f91aa094 Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Fri, 28 Feb 2025 13:11:34 -0800 Subject: [PATCH] Replace mocked find_image tests with real ones --- .github/workflows/test.yml | 2 +- tests/{registry => norun}/Dockerfile | 0 tests/norun/test_find.py | 23 +++++++++++++++++ tests/{registry => norun}/test_registry.py | 2 +- tests/unit/test_app.py | 29 ---------------------- 5 files changed, 25 insertions(+), 31 deletions(-) rename tests/{registry => norun}/Dockerfile (100%) create mode 100644 tests/norun/test_find.py rename tests/{registry => norun}/test_registry.py (99%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07bfc368..7e89cab5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,7 +65,7 @@ jobs: - unit - venv - contentproviders - - registry + - norun # Playwright test - ui include: diff --git a/tests/registry/Dockerfile b/tests/norun/Dockerfile similarity index 100% rename from tests/registry/Dockerfile rename to tests/norun/Dockerfile diff --git a/tests/norun/test_find.py b/tests/norun/test_find.py new file mode 100644 index 00000000..24025b0f --- /dev/null +++ b/tests/norun/test_find.py @@ -0,0 +1,23 @@ +import secrets +from pathlib import Path + +from repo2docker.__main__ import make_r2d + +HERE = Path(__file__).parent + + +def test_find_image(): + image_name = f"{secrets.token_hex(8)}:latest" + r2d = make_r2d(["--image", image_name, "--no-run", str(HERE)]) + + r2d.start() + + assert r2d.find_image() + + +def test_dont_find_image(): + image_name = f"{secrets.token_hex(8)}:latest" + r2d = make_r2d(["--image", image_name, "--no-run", str(HERE)]) + + # Just don't actually start the build, so image won't be found + assert not r2d.find_image() \ No newline at end of file diff --git a/tests/registry/test_registry.py b/tests/norun/test_registry.py similarity index 99% rename from tests/registry/test_registry.py rename to tests/norun/test_registry.py index 72526af3..e65b2532 100644 --- a/tests/registry/test_registry.py +++ b/tests/norun/test_registry.py @@ -116,4 +116,4 @@ def test_registry(registry, dind): r2d.start() proc = subprocess.run(["docker", "manifest", "inspect", "--insecure", image_name]) - assert proc.returncode == 0 + assert proc.returncode == 0 \ No newline at end of file diff --git a/tests/unit/test_app.py b/tests/unit/test_app.py index 0ee4d0b3..02841ba4 100644 --- a/tests/unit/test_app.py +++ b/tests/unit/test_app.py @@ -10,35 +10,6 @@ from repo2docker.app import Repo2Docker from repo2docker.utils import chdir - -def test_find_image(): - images = [{"RepoTags": ["some-org/some-repo:latest"]}] - - with patch("repo2docker.docker.docker.APIClient") as FakeDockerClient: - instance = FakeDockerClient.return_value - instance.images.return_value = images - - r2d = Repo2Docker() - r2d.output_image_spec = "some-org/some-repo" - assert r2d.find_image() - - instance.images.assert_called_with() - - -def test_dont_find_image(): - images = [{"RepoTags": ["some-org/some-image-name:latest"]}] - - with patch("repo2docker.docker.docker.APIClient") as FakeDockerClient: - instance = FakeDockerClient.return_value - instance.images.return_value = images - - r2d = Repo2Docker() - r2d.output_image_spec = "some-org/some-other-image-name" - assert not r2d.find_image() - - instance.images.assert_called_with() - - def test_image_name_remains_unchanged(): # if we specify an image name, it should remain unmodified with TemporaryDirectory() as src: