diff --git a/awspub/tests/test_api.py b/awspub/tests/test_api.py index 566dc83..d075e67 100644 --- a/awspub/tests/test_api.py +++ b/awspub/tests/test_api.py @@ -2,7 +2,7 @@ import pytest -from awspub import api, context +from awspub import api, context, image curdir = pathlib.Path(__file__).parent.resolve() @@ -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