Skip to content

Commit 9048529

Browse files
committed
Added unit test for the 'push_images' function
1 parent 00dea15 commit 9048529

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

tests/cli/test_build_images.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from murfey.cli.build_images import build_image, run, tag_image
8+
from murfey.cli.build_images import build_image, push_images, run, tag_image
99

1010
images = [f"test_image_{n}" for n in range(3)]
1111

@@ -147,9 +147,50 @@ def test_tag_image(mock_subprocess, tag_params):
147147
)
148148

149149

150+
push_image_params_matrix: tuple[tuple[list[str], list[str], str, bool], ...] = (
151+
# Images | Tags | Source | Destination | User ID | Group ID | Group Name | Dry Run
152+
# Populated flags
153+
(
154+
images,
155+
["latest", "dev", "1.1.1"],
156+
"docker.io",
157+
False,
158+
),
159+
(
160+
images,
161+
["latest", "dev", "1.1.1"],
162+
"docker.io",
163+
True,
164+
),
165+
)
166+
167+
168+
@pytest.mark.parametrize("push_params", push_image_params_matrix)
169+
@patch("murfey.cli.build_images.run_subprocess")
170+
def test_push_images(
171+
mock_subprocess,
172+
push_params,
173+
):
174+
175+
# Unpack test parameters
176+
images, tags, dst, dry_run = push_params
177+
178+
# Construct all images to be pushed
179+
images_to_push = [f"{dst}/{image}:{tag}" for image in images for tag in tags]
180+
181+
# Mock the subprocess return value
182+
mock_subprocess.return_value = True
183+
184+
# Run the function
185+
result = push_images(
186+
images=images_to_push,
187+
dry_run=dry_run,
188+
)
189+
assert result
190+
191+
150192
@pytest.mark.parametrize("run_params", test_run_params_matrix)
151193
@patch("murfey.cli.build_images.Path.exists")
152-
@patch("murfey.cli.build_images.run_subprocess")
153194
@patch("murfey.cli.build_images.cleanup")
154195
@patch("murfey.cli.build_images.push_images")
155196
@patch("murfey.cli.build_images.tag_image")

0 commit comments

Comments
 (0)