|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
8 | | -from murfey.cli.build_images import run |
| 8 | +from murfey.cli.build_images import build_image, run |
9 | 9 |
|
10 | 10 | images = [f"test_image_{n}" for n in range(3)] |
11 | 11 |
|
|
19 | 19 | def_dry_run = False |
20 | 20 |
|
21 | 21 |
|
| 22 | +build_image_params_matrix: tuple[ |
| 23 | + tuple[list[str], list[str], str, str, int, int, str, bool], ... |
| 24 | +] = ( |
| 25 | + # Images | Tags | Source | Destination | User ID | Group ID | Group Name | Dry Run |
| 26 | + # Populated flags |
| 27 | + ( |
| 28 | + images, |
| 29 | + ["latest", "dev", "1.1.1"], |
| 30 | + "", |
| 31 | + "docker.io", |
| 32 | + 12345, |
| 33 | + 34567, |
| 34 | + "my-group", |
| 35 | + False, |
| 36 | + ), |
| 37 | + ( |
| 38 | + images, |
| 39 | + ["latest", "dev", "1.1.1"], |
| 40 | + "", |
| 41 | + "docker.io", |
| 42 | + 12345, |
| 43 | + 34567, |
| 44 | + "my-group", |
| 45 | + True, |
| 46 | + ), |
| 47 | +) |
| 48 | + |
| 49 | + |
| 50 | +@pytest.mark.parametrize("build_params", build_image_params_matrix) |
| 51 | +@patch("murfey.cli.build_images.Path.exists") |
| 52 | +@patch("murfey.cli.build_images.run_subprocess") |
| 53 | +def test_build_images(mock_subprocess, mock_exists, build_params): |
| 54 | + |
| 55 | + # Unpack build params |
| 56 | + images, tags, src, dst, uid, gid, gname, dry_run = build_params |
| 57 | + |
| 58 | + # Set the return values for 'Path().exists()' and 'run_subprocess' |
| 59 | + mock_exists.return_value = True |
| 60 | + mock_subprocess.return_value = 0 |
| 61 | + |
| 62 | + # Run the command |
| 63 | + built_image = build_image( |
| 64 | + image=images[0], |
| 65 | + tag=tags[0], |
| 66 | + source=src, |
| 67 | + destination=dst, |
| 68 | + user_id=uid, |
| 69 | + group_id=gid, |
| 70 | + group_name=gname, |
| 71 | + dry_run=dry_run, |
| 72 | + ) |
| 73 | + |
| 74 | + # Check that the image path generated is correct |
| 75 | + assert built_image == f"{dst}/{images[0]:{tags[0]}}" |
| 76 | + |
| 77 | + |
22 | 78 | test_run_params_matrix: tuple[ |
23 | 79 | tuple[list[str], list[str], str, str, str, str, str, bool], ... |
24 | 80 | ] = ( |
|
0 commit comments