From 5fd20626b36f69e0e1d27764172ba114595f0f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= <2642849+elopez@users.noreply.github.com> Date: Tue, 16 Feb 2021 05:54:28 -0300 Subject: [PATCH] events: fix archive event pattern match check (#3671) * events: fix archive event pattern match check There is a missing `return True` for the positive match case in matches_pattern, causing all valid patterns to fail. * events: add test for valid, non-empty pattern match --- moto/events/models.py | 2 ++ tests/test_events/test_events.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/moto/events/models.py b/moto/events/models.py index 7d9b4d177..9f3cdec6a 100644 --- a/moto/events/models.py +++ b/moto/events/models.py @@ -287,6 +287,8 @@ class Archive(CloudFormationModel): if event_value not in pattern_value: return False + return True + def get_cfn_attribute(self, attribute_name): from moto.cloudformation.exceptions import UnformattedGetAttTemplateException diff --git a/tests/test_events/test_events.py b/tests/test_events/test_events.py index 8907fc752..cffd41228 100644 --- a/tests/test_events/test_events.py +++ b/tests/test_events/test_events.py @@ -1241,7 +1241,8 @@ def test_archive_actual_events(): # given client = boto3.client("events", "eu-central-1") name = "test-archive" - name_2 = "test-archive-2" + name_2 = "test-archive-no-match" + name_3 = "test-archive-matches" event_bus_arn = "arn:aws:events:eu-central-1:{}:event-bus/default".format( ACCOUNT_ID ) @@ -1256,6 +1257,11 @@ def test_archive_actual_events(): EventSourceArn=event_bus_arn, EventPattern=json.dumps({"DetailType": ["type"], "Source": ["test"]}), ) + client.create_archive( + ArchiveName=name_3, + EventSourceArn=event_bus_arn, + EventPattern=json.dumps({"DetailType": ["type"], "Source": ["source"]}), + ) # when response = client.put_events(Entries=[event]) @@ -1271,3 +1277,7 @@ def test_archive_actual_events(): response = client.describe_archive(ArchiveName=name_2) response["EventCount"].should.equal(0) response["SizeBytes"].should.equal(0) + + response = client.describe_archive(ArchiveName=name_3) + response["EventCount"].should.equal(1) + response["SizeBytes"].should.be.greater_than(0)