|
1 | 1 | import pytest |
2 | 2 |
|
3 | 3 | from arnparse import arnparse |
4 | | - |
5 | 4 | from arnparse.arnparse import MalformedArnError |
6 | 5 |
|
7 | 6 |
|
| 7 | +def test__definition(): |
| 8 | + arn = arnparse('arn:partition:service:region:account-id:resource') |
| 9 | + assert arn.partition == 'partition' |
| 10 | + assert arn.service == 'service' |
| 11 | + assert arn.region == 'region' |
| 12 | + assert arn.account_id == 'account-id' |
| 13 | + assert arn.resource_type is None |
| 14 | + assert arn.resource == 'resource' |
| 15 | + |
| 16 | + arn = arnparse('arn:partition:service:region:account-id:resourcetype/resource') |
| 17 | + assert arn.partition == 'partition' |
| 18 | + assert arn.service == 'service' |
| 19 | + assert arn.region == 'region' |
| 20 | + assert arn.account_id == 'account-id' |
| 21 | + assert arn.resource_type == 'resourcetype' |
| 22 | + assert arn.resource == 'resource' |
| 23 | + |
| 24 | + arn = arnparse('arn:partition:service:region:account-id:resourcetype/resource/qualifier') |
| 25 | + assert arn.partition == 'partition' |
| 26 | + assert arn.service == 'service' |
| 27 | + assert arn.region == 'region' |
| 28 | + assert arn.account_id == 'account-id' |
| 29 | + assert arn.resource_type == 'resourcetype' |
| 30 | + assert arn.resource == 'resource/qualifier' |
| 31 | + |
| 32 | + arn = arnparse('arn:partition:service:region:account-id:resourcetype/resource:qualifier') |
| 33 | + assert arn.partition == 'partition' |
| 34 | + assert arn.service == 'service' |
| 35 | + assert arn.region == 'region' |
| 36 | + assert arn.account_id == 'account-id' |
| 37 | + assert arn.resource_type == 'resourcetype' |
| 38 | + assert arn.resource == 'resource:qualifier' |
| 39 | + |
| 40 | + arn = arnparse('arn:partition:service:region:account-id:resourcetype:resource') |
| 41 | + assert arn.partition == 'partition' |
| 42 | + assert arn.service == 'service' |
| 43 | + assert arn.region == 'region' |
| 44 | + assert arn.account_id == 'account-id' |
| 45 | + assert arn.resource_type == 'resourcetype' |
| 46 | + assert arn.resource == 'resource' |
| 47 | + |
| 48 | + arn = arnparse('arn:partition:service:region:account-id:resourcetype:resource:qualifier') |
| 49 | + assert arn.partition == 'partition' |
| 50 | + assert arn.service == 'service' |
| 51 | + assert arn.region == 'region' |
| 52 | + assert arn.account_id == 'account-id' |
| 53 | + assert arn.resource_type == 'resourcetype' |
| 54 | + assert arn.resource == 'resource:qualifier' |
| 55 | + |
| 56 | + |
8 | 57 | def test__arnparse__resource_type_with_slash(): |
9 | 58 | arn_str = 'arn:aws:ec2:us-east-1:123456789012:vpc/vpc-fd580e98' |
10 | 59 |
|
@@ -243,3 +292,42 @@ def test__s3(): |
243 | 292 | assert arn.account_id is None |
244 | 293 | assert arn.resource_type is None |
245 | 294 | assert arn.resource == 'my_corporate_bucket/Development/*' |
| 295 | + |
| 296 | + |
| 297 | +def test__cloudwatch_logs(): |
| 298 | + arn_str = 'arn:aws:logs:us-east-1:123456789012:log-group:/aws/lambda/my-function:*' |
| 299 | + |
| 300 | + arn = arnparse(arn_str) |
| 301 | + |
| 302 | + assert arn.partition == 'aws' |
| 303 | + assert arn.service == 'logs' |
| 304 | + assert arn.region == 'us-east-1' |
| 305 | + assert arn.account_id == '123456789012' |
| 306 | + assert arn.resource_type == 'log-group' |
| 307 | + assert arn.resource == '/aws/lambda/my-function:*' |
| 308 | + |
| 309 | + |
| 310 | +def test__secrets_manager(): |
| 311 | + arn_str = 'arn:aws:secretsmanager:us-east-1:123456789012:secret:myfolder/MyFirstSecret-ocq1Wq' |
| 312 | + |
| 313 | + arn = arnparse(arn_str) |
| 314 | + |
| 315 | + assert arn.partition == 'aws' |
| 316 | + assert arn.service == 'secretsmanager' |
| 317 | + assert arn.region == 'us-east-1' |
| 318 | + assert arn.account_id == '123456789012' |
| 319 | + assert arn.resource_type == 'secret' |
| 320 | + assert arn.resource == 'myfolder/MyFirstSecret-ocq1Wq' |
| 321 | + |
| 322 | + |
| 323 | +def test__batch(): |
| 324 | + arn_str = 'arn:aws:batch:us-east-1:123456789012:job-definition/my-job-definition:1' |
| 325 | + |
| 326 | + arn = arnparse(arn_str) |
| 327 | + |
| 328 | + assert arn.partition == 'aws' |
| 329 | + assert arn.service == 'batch' |
| 330 | + assert arn.region == 'us-east-1' |
| 331 | + assert arn.account_id == '123456789012' |
| 332 | + assert arn.resource_type == 'job-definition' |
| 333 | + assert arn.resource == 'my-job-definition:1' |
0 commit comments