@@ -1370,37 +1370,109 @@ describe('stack', () => {
1370
1370
1371
1371
// THEN - producers are the same
1372
1372
expect ( ( ) => {
1373
- resourceM . overrideLogicalId ( 'OVERRIDE_LOGICAL_ID ' ) ;
1373
+ resourceM . overrideLogicalId ( 'OVERRIDELOGICALID ' ) ;
1374
1374
} ) . toThrow ( / T h e l o g i c a l I d f o r r e s o u r c e a t p a t h P r o d u c e r \/ R e s o u r c e X X X h a s b e e n l o c k e d a n d c a n n o t b e o v e r r i d d e n / ) ;
1375
1375
} ) ;
1376
1376
1377
+ test ( 'throw error if overrideLogicalId contains non-alphanumeric characters' , ( ) => {
1378
+ // GIVEN: manual
1379
+ const appM = new App ( ) ;
1380
+ const producerM = new Stack ( appM , 'Producer' ) ;
1381
+ const resourceM = new CfnResource ( producerM , 'ResourceXXX' , { type : 'AWS::Resource' } ) ;
1382
+
1383
+ // THEN - producers are the same
1384
+ expect ( ( ) => {
1385
+ resourceM . overrideLogicalId ( 'INVALID_LOGICAL_ID' ) ;
1386
+ } ) . toThrow ( / m u s t o n l y c o n t a i n a l p h a n u m e r i c c h a r a c t e r s / ) ;
1387
+ } ) ;
1388
+
1389
+ test ( 'throw error if overrideLogicalId is over 255 characters' , ( ) => {
1390
+ // GIVEN: manual
1391
+ const appM = new App ( ) ;
1392
+ const producerM = new Stack ( appM , 'Producer' ) ;
1393
+ const resourceM = new CfnResource ( producerM , 'ResourceXXX' , { type : 'AWS::Resource' } ) ;
1394
+
1395
+ // THEN - producers are the same
1396
+ expect ( ( ) => {
1397
+ resourceM . overrideLogicalId (
1398
+ // 256 character long string of "aaaa..."
1399
+ Array ( 256 ) . fill ( 'a' ) . join ( '' ) ,
1400
+ ) ;
1401
+ } ) . toThrow ( / m u s t b e a t m o s t 2 5 5 c h a r a c t e r s l o n g , g o t 2 5 6 c h a r a c t e r s / ) ;
1402
+ } ) ;
1403
+
1404
+ test ( 'throw error if overrideLogicalId is an empty string' , ( ) => {
1405
+ // GIVEN: manual
1406
+ const appM = new App ( ) ;
1407
+ const producerM = new Stack ( appM , 'Producer' ) ;
1408
+ const resourceM = new CfnResource ( producerM , 'ResourceXXX' , { type : 'AWS::Resource' } ) ;
1409
+
1410
+ // THEN - producers are the same
1411
+ expect ( ( ) => {
1412
+ resourceM . overrideLogicalId ( '' ) ;
1413
+ } ) . toThrow ( 'Cannot set an empty logical ID' ) ;
1414
+ } ) ;
1415
+
1377
1416
test ( 'do not throw error if overrideLogicalId is used and logicalId is not locked' , ( ) => {
1378
1417
// GIVEN: manual
1379
1418
const appM = new App ( ) ;
1380
1419
const producerM = new Stack ( appM , 'Producer' ) ;
1381
1420
const resourceM = new CfnResource ( producerM , 'ResourceXXX' , { type : 'AWS::Resource' } ) ;
1382
1421
1383
1422
// THEN - producers are the same
1384
- resourceM . overrideLogicalId ( 'OVERRIDE_LOGICAL_ID' ) ;
1423
+ resourceM . overrideLogicalId ( 'OVERRIDELOGICALID' ) ;
1424
+ producerM . exportValue ( resourceM . getAtt ( 'Att' ) ) ;
1425
+
1426
+ const template = appM . synth ( ) . getStackByName ( producerM . stackName ) . template ;
1427
+ expect ( template ) . toMatchObject ( {
1428
+ Outputs : {
1429
+ ExportsOutputFnGetAttOVERRIDELOGICALIDAtt76AC816F : {
1430
+ Export : {
1431
+ Name : 'Producer:ExportsOutputFnGetAttOVERRIDELOGICALIDAtt76AC816F' ,
1432
+ } ,
1433
+ Value : {
1434
+ 'Fn::GetAtt' : [
1435
+ 'OVERRIDELOGICALID' ,
1436
+ 'Att' ,
1437
+ ] ,
1438
+ } ,
1439
+ } ,
1440
+ } ,
1441
+ Resources : {
1442
+ OVERRIDELOGICALID : {
1443
+ Type : 'AWS::Resource' ,
1444
+ } ,
1445
+ } ,
1446
+ } ) ;
1447
+ } ) ;
1448
+
1449
+ test ( 'do not throw if overrideLogicalId is unresolved' , ( ) => {
1450
+ // GIVEN: manual
1451
+ const appM = new App ( ) ;
1452
+ const producerM = new Stack ( appM , 'Producer' ) ;
1453
+ const resourceM = new CfnResource ( producerM , 'ResourceXXX' , { type : 'AWS::Resource' } ) ;
1454
+
1455
+ // THEN - producers are the same
1456
+ resourceM . overrideLogicalId ( Lazy . string ( { produce : ( ) => 'INVALID_LOGICAL_ID' } ) ) ;
1385
1457
producerM . exportValue ( resourceM . getAtt ( 'Att' ) ) ;
1386
1458
1387
1459
const template = appM . synth ( ) . getStackByName ( producerM . stackName ) . template ;
1388
1460
expect ( template ) . toMatchObject ( {
1389
1461
Outputs : {
1390
- ExportsOutputFnGetAttOVERRIDELOGICALIDAtt2DD28019 : {
1462
+ ExportsOutputFnGetAttINVALIDLOGICALIDAtt6CB9E5B9 : {
1391
1463
Export : {
1392
- Name : 'Producer:ExportsOutputFnGetAttOVERRIDELOGICALIDAtt2DD28019 ' ,
1464
+ Name : 'Producer:ExportsOutputFnGetAttINVALIDLOGICALIDAtt6CB9E5B9 ' ,
1393
1465
} ,
1394
1466
Value : {
1395
1467
'Fn::GetAtt' : [
1396
- 'OVERRIDE_LOGICAL_ID ' ,
1468
+ 'INVALID_LOGICAL_ID ' ,
1397
1469
'Att' ,
1398
1470
] ,
1399
1471
} ,
1400
1472
} ,
1401
1473
} ,
1402
1474
Resources : {
1403
- OVERRIDE_LOGICAL_ID : {
1475
+ INVALID_LOGICAL_ID : {
1404
1476
Type : 'AWS::Resource' ,
1405
1477
} ,
1406
1478
} ,
0 commit comments