|
| 1 | +const mockLoadResourceModel = jest.fn(); |
| 2 | +jest.mock('@aws-cdk/cloudformation-diff/lib/diff/util', () => ({ |
| 3 | + loadResourceModel: mockLoadResourceModel, |
| 4 | +})); |
| 5 | + |
1 | 6 | import {
|
2 | 7 | GetTemplateCommand,
|
3 | 8 | ListStacksCommand,
|
@@ -293,6 +298,238 @@ describe('computeResourceDigests', () => {
|
293 | 298 | const result = computeResourceDigests(template);
|
294 | 299 | expect(result['Q1']).toBe(result['Q2']);
|
295 | 300 | });
|
| 301 | + |
| 302 | + test('uses physical ID if present', () => { |
| 303 | + mockLoadResourceModel.mockReturnValue({ |
| 304 | + primaryIdentifier: ['FooName'] |
| 305 | + }); |
| 306 | + |
| 307 | + const template = { |
| 308 | + Resources: { |
| 309 | + Foo1: { |
| 310 | + Type: 'AWS::S3::Foo', |
| 311 | + Properties: { |
| 312 | + FooName: 'XXXXXXXXX', |
| 313 | + ShouldBeIgnored: true, |
| 314 | + }, |
| 315 | + }, |
| 316 | + Foo2: { |
| 317 | + Type: 'AWS::S3::Foo', |
| 318 | + Properties: { |
| 319 | + FooName: 'XXXXXXXXX', |
| 320 | + ShouldAlsoBeIgnored: true, |
| 321 | + }, |
| 322 | + }, |
| 323 | + }, |
| 324 | + }; |
| 325 | + |
| 326 | + const result = computeResourceDigests(template); |
| 327 | + expect(result['Foo1']).toBe(result['Foo2']); |
| 328 | + }); |
| 329 | + |
| 330 | + test('uses physical ID if present - with dependencies', () => { |
| 331 | + mockLoadResourceModel.mockReturnValue({ |
| 332 | + primaryIdentifier: ['FooName'] |
| 333 | + }); |
| 334 | + |
| 335 | + const template = { |
| 336 | + Resources: { |
| 337 | + Foo1: { |
| 338 | + Type: 'AWS::S3::Foo', |
| 339 | + Properties: { |
| 340 | + FooName: 'XXXXXXXXX', |
| 341 | + ShouldBeIgnored: true, |
| 342 | + }, |
| 343 | + }, |
| 344 | + Foo2: { |
| 345 | + Type: 'AWS::S3::Foo', |
| 346 | + Properties: { |
| 347 | + FooName: 'XXXXXXXXX', |
| 348 | + ShouldAlsoBeIgnored: true, |
| 349 | + }, |
| 350 | + }, |
| 351 | + Bucket1: { |
| 352 | + Type: 'AWS::S3::Bucket', |
| 353 | + Properties: { Dep: { Ref: 'Foo1' } }, |
| 354 | + }, |
| 355 | + Bucket2: { |
| 356 | + Type: 'AWS::S3::Bucket', |
| 357 | + Properties: { Dep: { Ref: 'Foo2' } }, |
| 358 | + }, |
| 359 | + }, |
| 360 | + }; |
| 361 | + |
| 362 | + const result = computeResourceDigests(template); |
| 363 | + expect(result['Bucket1']).toBe(result['Bucket2']); |
| 364 | + }); |
| 365 | + |
| 366 | + test('different physical IDs lead to different digests', () => { |
| 367 | + mockLoadResourceModel.mockReturnValue({ |
| 368 | + primaryIdentifier: ['FooName'] |
| 369 | + }); |
| 370 | + |
| 371 | + const template = { |
| 372 | + Resources: { |
| 373 | + Foo1: { |
| 374 | + Type: 'AWS::S3::Foo', |
| 375 | + Properties: { |
| 376 | + FooName: 'XXXXXXXXX', |
| 377 | + ShouldBeIgnored: true, |
| 378 | + }, |
| 379 | + }, |
| 380 | + Foo2: { |
| 381 | + Type: 'AWS::S3::Foo', |
| 382 | + Properties: { |
| 383 | + FooName: 'YYYYYYYYY', |
| 384 | + ShouldAlsoBeIgnored: true, |
| 385 | + }, |
| 386 | + }, |
| 387 | + }, |
| 388 | + }; |
| 389 | + |
| 390 | + const result = computeResourceDigests(template); |
| 391 | + expect(result['Foo1']).not.toBe(result['Foo2']); |
| 392 | + }); |
| 393 | + |
| 394 | + test('primaryIdentifier is a composite field - different values', () => { |
| 395 | + mockLoadResourceModel.mockReturnValue({ |
| 396 | + primaryIdentifier: ['FooName', 'BarName'] |
| 397 | + }); |
| 398 | + |
| 399 | + const template = { |
| 400 | + Resources: { |
| 401 | + Foo1: { |
| 402 | + Type: 'AWS::S3::Foo', |
| 403 | + Properties: { |
| 404 | + FooName: 'XXXXXXXXX', |
| 405 | + BarName: 'YYYYYYYYY', |
| 406 | + ShouldBeIgnored: true, |
| 407 | + }, |
| 408 | + }, |
| 409 | + Foo2: { |
| 410 | + Type: 'AWS::S3::Foo', |
| 411 | + Properties: { |
| 412 | + FooName: 'XXXXXXXXX', |
| 413 | + BarName: 'ZZZZZZZZZ', |
| 414 | + ShouldAlsoBeIgnored: true, |
| 415 | + }, |
| 416 | + }, |
| 417 | + }, |
| 418 | + }; |
| 419 | + |
| 420 | + const result = computeResourceDigests(template); |
| 421 | + expect(result['Foo1']).not.toBe(result['Foo2']); |
| 422 | + }); |
| 423 | + |
| 424 | + test('primaryIdentifier is a composite field - same value', () => { |
| 425 | + mockLoadResourceModel.mockReturnValue({ |
| 426 | + primaryIdentifier: ['FooName', 'BarName'] |
| 427 | + }); |
| 428 | + |
| 429 | + const template = { |
| 430 | + Resources: { |
| 431 | + Foo1: { |
| 432 | + Type: 'AWS::S3::Foo', |
| 433 | + Properties: { |
| 434 | + FooName: 'XXXXXXXXX', |
| 435 | + BarName: 'YYYYYYYYY', |
| 436 | + ShouldBeIgnored: true, |
| 437 | + }, |
| 438 | + }, |
| 439 | + Foo2: { |
| 440 | + Type: 'AWS::S3::Foo', |
| 441 | + Properties: { |
| 442 | + FooName: 'XXXXXXXXX', |
| 443 | + BarName: 'YYYYYYYYY', |
| 444 | + ShouldAlsoBeIgnored: true, |
| 445 | + }, |
| 446 | + }, |
| 447 | + }, |
| 448 | + }; |
| 449 | + |
| 450 | + const result = computeResourceDigests(template); |
| 451 | + expect(result['Foo1']).toBe(result['Foo2']); |
| 452 | + }); |
| 453 | + |
| 454 | + test('primaryIdentifier is a composite field but not all of them are set in the resource', () => { |
| 455 | + mockLoadResourceModel.mockReturnValue({ |
| 456 | + primaryIdentifier: ['FooName', 'BarName'] |
| 457 | + }); |
| 458 | + |
| 459 | + const template = { |
| 460 | + Resources: { |
| 461 | + Foo1: { |
| 462 | + Type: 'AWS::S3::Foo', |
| 463 | + Properties: { |
| 464 | + FooName: 'XXXXXXXXX', |
| 465 | + ShouldBeIgnored: true, |
| 466 | + }, |
| 467 | + }, |
| 468 | + Foo2: { |
| 469 | + Type: 'AWS::S3::Foo', |
| 470 | + Properties: { |
| 471 | + FooName: 'XXXXXXXXX', |
| 472 | + ShouldAlsoBeIgnored: true, |
| 473 | + }, |
| 474 | + }, |
| 475 | + }, |
| 476 | + }; |
| 477 | + |
| 478 | + const result = computeResourceDigests(template); |
| 479 | + expect(result['Foo1']).not.toBe(result['Foo2']); |
| 480 | + }); |
| 481 | + |
| 482 | + test('resource properties does not contain primaryIdentifier - different values', () => { |
| 483 | + mockLoadResourceModel.mockReturnValue({ |
| 484 | + primaryIdentifier: ['FooName'] |
| 485 | + }); |
| 486 | + |
| 487 | + const template = { |
| 488 | + Resources: { |
| 489 | + Foo1: { |
| 490 | + Type: 'AWS::S3::Foo', |
| 491 | + Properties: { |
| 492 | + ShouldNotBeIgnored: true, |
| 493 | + }, |
| 494 | + }, |
| 495 | + Foo2: { |
| 496 | + Type: 'AWS::S3::Foo', |
| 497 | + Properties: { |
| 498 | + ShouldNotBeIgnoredEither: true, |
| 499 | + }, |
| 500 | + }, |
| 501 | + }, |
| 502 | + }; |
| 503 | + |
| 504 | + const result = computeResourceDigests(template); |
| 505 | + expect(result['Foo1']).not.toBe(result['Foo2']); |
| 506 | + }); |
| 507 | + |
| 508 | + test('resource properties does not contain primaryIdentifier - same value', () => { |
| 509 | + mockLoadResourceModel.mockReturnValue({ |
| 510 | + primaryIdentifier: ['FooName'] |
| 511 | + }); |
| 512 | + |
| 513 | + const template = { |
| 514 | + Resources: { |
| 515 | + Foo1: { |
| 516 | + Type: 'AWS::S3::Foo', |
| 517 | + Properties: { |
| 518 | + SomeProp: true, |
| 519 | + }, |
| 520 | + }, |
| 521 | + Foo2: { |
| 522 | + Type: 'AWS::S3::Foo', |
| 523 | + Properties: { |
| 524 | + SomeProp: true, |
| 525 | + }, |
| 526 | + }, |
| 527 | + }, |
| 528 | + }; |
| 529 | + |
| 530 | + const result = computeResourceDigests(template); |
| 531 | + expect(result['Foo1']).toBe(result['Foo2']); |
| 532 | + }); |
296 | 533 | });
|
297 | 534 |
|
298 | 535 | describe('typed mappings', () => {
|
|
0 commit comments