|
| 1 | +import pytest |
| 2 | + |
| 3 | +from mobster.cmd.generate.oci_image.base_image_utils import ( |
| 4 | + get_images_and_their_annotations, |
| 5 | +) |
| 6 | +from mobster.image import Image |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.asyncio |
| 10 | +@pytest.mark.parametrize( |
| 11 | + ["base_images_refs", "base_images", "expected_output"], |
| 12 | + [ |
| 13 | + pytest.param( |
| 14 | + ["alpine:3.10", None, "foobar:v1"], |
| 15 | + { |
| 16 | + "alpine:3.10": Image.from_image_index_url_and_digest( |
| 17 | + "alpine:3.10", "sha256:1" |
| 18 | + ), |
| 19 | + "foobar:v1": Image.from_image_index_url_and_digest( |
| 20 | + "foobar:v1", "sha256:2" |
| 21 | + ), |
| 22 | + }, |
| 23 | + [ |
| 24 | + ( |
| 25 | + Image.from_image_index_url_and_digest("alpine:3.10", "sha256:1"), |
| 26 | + [ |
| 27 | + { |
| 28 | + "name": "konflux:container:is_builder_image:for_stage", |
| 29 | + "value": "0", |
| 30 | + } |
| 31 | + ], |
| 32 | + ), |
| 33 | + ( |
| 34 | + Image.from_image_index_url_and_digest("foobar:v1", "sha256:2"), |
| 35 | + [{"name": "konflux:container:is_base_image", "value": "true"}], |
| 36 | + ), |
| 37 | + ], |
| 38 | + id="3 Stages, Stage 1 is FROM SCRATCH", |
| 39 | + ), |
| 40 | + pytest.param( |
| 41 | + ["alpine:3.10", None, "foobar:v1", "alpine:3.10"], |
| 42 | + { |
| 43 | + "alpine:3.10": Image.from_image_index_url_and_digest( |
| 44 | + "alpine:3.10", "sha256:1" |
| 45 | + ), |
| 46 | + "foobar:v1": Image.from_image_index_url_and_digest( |
| 47 | + "foobar:v1", "sha256:2" |
| 48 | + ), |
| 49 | + }, |
| 50 | + [ |
| 51 | + ( |
| 52 | + Image.from_image_index_url_and_digest("foobar:v1", "sha256:2"), |
| 53 | + [ |
| 54 | + { |
| 55 | + "name": "konflux:container:is_builder_image:for_stage", |
| 56 | + "value": "2", # Stage 1 is FROM SCRATCH, |
| 57 | + # this value is correct. |
| 58 | + }, |
| 59 | + ], |
| 60 | + ), |
| 61 | + ( |
| 62 | + Image.from_image_index_url_and_digest("alpine:3.10", "sha256:1"), |
| 63 | + [ |
| 64 | + { |
| 65 | + "name": "konflux:container:is_builder_image:for_stage", |
| 66 | + "value": "0", |
| 67 | + }, |
| 68 | + {"name": "konflux:container:is_base_image", "value": "true"}, |
| 69 | + ], |
| 70 | + ), |
| 71 | + ], |
| 72 | + id="4 Stages, Stage 1 is FROM SCRATCH and 4th Stage is the same as Stage 0", |
| 73 | + ), |
| 74 | + ], |
| 75 | +) |
| 76 | +async def test_get_images_and_their_annotations( |
| 77 | + base_images_refs: list[str | None], |
| 78 | + base_images: dict[str, Image], |
| 79 | + expected_output: list[tuple[Image, list[dict[str, str]]]], |
| 80 | +) -> None: |
| 81 | + assert ( |
| 82 | + await get_images_and_their_annotations(base_images_refs, base_images) |
| 83 | + == expected_output |
| 84 | + ) |
0 commit comments