Skip to content

Commit

Permalink
Replace mocked find_image tests with real ones
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed Feb 28, 2025
1 parent 9753570 commit c04652e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- unit
- venv
- contentproviders
- registry
- norun
# Playwright test
- ui
include:
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions tests/norun/test_find.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 0 additions & 29 deletions tests/unit/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c04652e

Please sign in to comment.