Skip to content

Commit

Permalink
test: add unittest for api._images_grouped
Browse files Browse the repository at this point in the history
To increase test coverage and make sure that no regression will be
introduced.
  • Loading branch information
toabctl committed Sep 30, 2024
1 parent 799a391 commit b2fd250
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion awspub/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from awspub import api, context
from awspub import api, context, image

curdir = pathlib.Path(__file__).parent.resolve()

Expand Down Expand Up @@ -50,3 +50,37 @@ def test_api__images_filtered(group, expected_image_names):

image_names = [i[0] for i in api._images_filtered(ctx, group)]
assert image_names == expected_image_names


@pytest.mark.parametrize(
"group,expected",
[
# without any group, all images should be processed
(
None,
(
{"test-image-1": {"eu-central-1": "ami-123", "eu-central-2": "ami-456"}},
{
"group1": {"test-image-1": {"eu-central-1": "ami-123", "eu-central-2": "ami-456"}},
"group2": {"test-image-1": {"eu-central-1": "ami-123", "eu-central-2": "ami-456"}},
},
),
),
# with a group that no image as, image should be there but nothing in the group
("group-not-used", ({"test-image-1": {"eu-central-1": "ami-123", "eu-central-2": "ami-456"}}, {})),
],
)
def test_api__images_grouped(group, expected):
"""
Test the _images_grouped() function
"""
ctx = context.Context(curdir / "fixtures/config1.yaml", None)
images = [
(
"test-image-1",
image.Image(ctx, "test-image-1"),
{"eu-central-1": image._ImageInfo("ami-123", None), "eu-central-2": image._ImageInfo("ami-456", None)},
)
]
grouped = api._images_grouped(images, group)
assert grouped == expected

0 comments on commit b2fd250

Please sign in to comment.