diff --git a/tests/aws/services/scheduler/conftest.py b/tests/aws/services/scheduler/conftest.py new file mode 100644 index 0000000000000..3591951039e6b --- /dev/null +++ b/tests/aws/services/scheduler/conftest.py @@ -0,0 +1,29 @@ +import logging + +import pytest + +from localstack.utils.strings import short_uid + +LOG = logging.getLogger(__name__) + + +@pytest.fixture +def events_scheduler_create_schedule_group(aws_client): + schedule_group_arns = [] + + def _events_scheduler_create_schedule_group(name, **kwargs): + if not name: + name = f"events-test-schedule-groupe-{short_uid()}" + response = aws_client.scheduler.create_schedule_group(Name=name, **kwargs) + schedule_group_arn = response["ScheduleGroupArn"] + schedule_group_arns.append(schedule_group_arn) + + return schedule_group_arn + + yield _events_scheduler_create_schedule_group + + for schedule_group_arn in schedule_group_arns: + try: + aws_client.scheduler.delete_schedule_group(ScheduleGroupArn=schedule_group_arn) + except Exception: + LOG.info("Failed to delete schedule group %s", schedule_group_arn) diff --git a/tests/aws/services/scheduler/test_scheduler.py b/tests/aws/services/scheduler/test_scheduler.py index a4fee86e9db50..157c8addd4c14 100644 --- a/tests/aws/services/scheduler/test_scheduler.py +++ b/tests/aws/services/scheduler/test_scheduler.py @@ -2,6 +2,7 @@ from localstack.testing.aws.util import in_default_partition from localstack.testing.pytest import markers +from localstack.utils.common import short_uid @pytest.mark.skipif( @@ -12,3 +13,48 @@ def test_list_schedules(aws_client): # simple smoke test to assert that the provider is available, without creating any schedules result = aws_client.scheduler.list_schedules() assert isinstance(result.get("Schedules"), list) + + +@markers.aws.validated +def test_tag_resource(aws_client, events_scheduler_create_schedule_group, snapshot): + name = short_uid() + schedule_group_arn = events_scheduler_create_schedule_group(name) + + response = aws_client.scheduler.tag_resource( + ResourceArn=schedule_group_arn, + Tags=[ + { + "Key": "TagKey", + "Value": "TagValue", + } + ], + ) + + response = aws_client.scheduler.list_tags_for_resource(ResourceArn=schedule_group_arn) + + assert response["Tags"][0]["Key"] == "TagKey" + assert response["Tags"][0]["Value"] == "TagValue" + + snapshot.match("list-tagged-schedule", response) + + +@markers.aws.validated +def test_untag_resource(aws_client, events_scheduler_create_schedule_group, snapshot): + name = short_uid() + tags = [ + { + "Key": "TagKey", + "Value": "TagValue", + } + ] + schedule_group_arn = events_scheduler_create_schedule_group(name, Tags=tags) + + response = aws_client.scheduler.untag_resource( + ResourceArn=schedule_group_arn, TagKeys=["TagKey"] + ) + + response = aws_client.scheduler.list_tags_for_resource(ResourceArn=schedule_group_arn) + + assert response["Tags"] == [] + + snapshot.match("list-untagged-schedule", response) diff --git a/tests/aws/services/scheduler/test_scheduler.snapshot.json b/tests/aws/services/scheduler/test_scheduler.snapshot.json new file mode 100644 index 0000000000000..cb8ccf8a85b06 --- /dev/null +++ b/tests/aws/services/scheduler/test_scheduler.snapshot.json @@ -0,0 +1,31 @@ +{ + "tests/aws/services/scheduler/test_scheduler.py::test_tag_resource": { + "recorded-date": "04-12-2024, 10:07:28", + "recorded-content": { + "list-tagged-schedule": { + "Tags": [ + { + "Key": "TagKey", + "Value": "TagValue" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } + }, + "tests/aws/services/scheduler/test_scheduler.py::test_untag_resource": { + "recorded-date": "04-12-2024, 10:08:11", + "recorded-content": { + "list-untagged-schedule": { + "Tags": [], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } + } +} diff --git a/tests/aws/services/scheduler/test_scheduler.validation.json b/tests/aws/services/scheduler/test_scheduler.validation.json index ce59d722d9340..487c07eaf3e43 100644 --- a/tests/aws/services/scheduler/test_scheduler.validation.json +++ b/tests/aws/services/scheduler/test_scheduler.validation.json @@ -1,5 +1,11 @@ { "tests/aws/services/scheduler/test_scheduler.py::test_list_schedules": { "last_validated_date": "2024-06-11T22:50:50+00:00" + }, + "tests/aws/services/scheduler/test_scheduler.py::test_tag_resource": { + "last_validated_date": "2024-12-04T10:07:28+00:00" + }, + "tests/aws/services/scheduler/test_scheduler.py::test_untag_resource": { + "last_validated_date": "2024-12-04T10:08:11+00:00" } }