|
3 | 3 |
|
4 | 4 | from settings import DD_CUSTOM_TAGS, DD_SOURCE |
5 | 5 | from steps.common import get_service_from_tags_and_remove_duplicates, parse_event_source |
6 | | -from steps.enums import AwsEventSource |
7 | | -from steps.parsing import parse |
| 6 | +from steps.enums import AwsEventSource, AwsEventType |
| 7 | +from steps.parsing import parse, parse_event_type |
8 | 8 |
|
9 | 9 |
|
10 | 10 | class TestParseEventSource(unittest.TestCase): |
@@ -185,6 +185,59 @@ def test_get_service_from_tags_removing_duplicates(self): |
185 | 185 | ) |
186 | 186 |
|
187 | 187 |
|
| 188 | +class TestParseEventType(unittest.TestCase): |
| 189 | + def test_parse_eventbridge_s3_event_type(self): |
| 190 | + """Test that EventBridge S3 events are correctly identified as EventBridge S3 type""" |
| 191 | + eventbridge_s3_event = { |
| 192 | + "version": "0", |
| 193 | + "id": "test-event-id", |
| 194 | + "detail-type": "Object Created", |
| 195 | + "source": "aws.s3", |
| 196 | + "account": "123456789012", |
| 197 | + "time": "2024-01-15T12:00:00Z", |
| 198 | + "region": "us-east-1", |
| 199 | + "resources": ["arn:aws:s3:::my-bucket"], |
| 200 | + "detail": { |
| 201 | + "bucket": {"name": "my-bucket"}, |
| 202 | + "object": {"key": "my-key.log"}, |
| 203 | + }, |
| 204 | + } |
| 205 | + |
| 206 | + event_type = parse_event_type(eventbridge_s3_event) |
| 207 | + self.assertEqual(event_type, AwsEventType.EVENTBRIDGE_S3) |
| 208 | + |
| 209 | + def test_parse_direct_s3_event_type(self): |
| 210 | + """Test that direct S3 events are still correctly identified as S3 type""" |
| 211 | + direct_s3_event = { |
| 212 | + "Records": [ |
| 213 | + { |
| 214 | + "s3": { |
| 215 | + "bucket": {"name": "my-bucket"}, |
| 216 | + "object": {"key": "my-key"}, |
| 217 | + } |
| 218 | + } |
| 219 | + ] |
| 220 | + } |
| 221 | + |
| 222 | + event_type = parse_event_type(direct_s3_event) |
| 223 | + self.assertEqual(event_type, AwsEventType.S3) |
| 224 | + |
| 225 | + def test_parse_non_s3_eventbridge_event_type(self): |
| 226 | + """Test that non-S3 EventBridge events are identified as EVENTS type""" |
| 227 | + eventbridge_other_event = { |
| 228 | + "version": "0", |
| 229 | + "detail-type": "EC2 Instance State-change Notification", |
| 230 | + "source": "aws.ec2", |
| 231 | + "detail": { |
| 232 | + "instance-id": "i-1234567890abcdef0", |
| 233 | + "state": "terminated" |
| 234 | + }, |
| 235 | + } |
| 236 | + |
| 237 | + event_type = parse_event_type(eventbridge_other_event) |
| 238 | + self.assertEqual(event_type, AwsEventType.EVENTS) |
| 239 | + |
| 240 | + |
188 | 241 | class TestEventBridgeS3Parsing(unittest.TestCase): |
189 | 242 | class Context: |
190 | 243 | function_version = "$LATEST" |
|
0 commit comments