|
| 1 | +import nodeunit = require('nodeunit'); |
| 2 | +import { App, Aws, Resource, Stack } from '../../lib'; |
| 3 | +import { generatePhysicalName } from '../../lib/private/physical-name-generator'; |
| 4 | + |
| 5 | +export = nodeunit.testCase({ |
| 6 | + 'generates correct physical names'(test: nodeunit.Test) { |
| 7 | + const app = new App(); |
| 8 | + const stack = new Stack(app, 'TestStack', { env: { account: '012345678912', region: 'bermuda-triangle-1' } }); |
| 9 | + |
| 10 | + const testResourceA = new TestResource(stack, 'A'); |
| 11 | + const testResourceB = new TestResource(testResourceA, 'B'); |
| 12 | + |
| 13 | + test.equal(generatePhysicalName(testResourceA), 'teststackteststackaa164c141d59b37c1b663'); |
| 14 | + test.equal(generatePhysicalName(testResourceB), 'teststackteststackab27595cd34d8188283a1f'); |
| 15 | + |
| 16 | + test.done(); |
| 17 | + }, |
| 18 | + |
| 19 | + 'generates different names in different accounts'(test: nodeunit.Test) { |
| 20 | + const appA = new App(); |
| 21 | + const stackA = new Stack(appA, 'TestStack', { env: { account: '012345678912', region: 'bermuda-triangle-1' } }); |
| 22 | + const resourceA = new TestResource(stackA, 'Resource'); |
| 23 | + |
| 24 | + const appB = new App(); |
| 25 | + const stackB = new Stack(appB, 'TestStack', { env: { account: '012345678913', region: 'bermuda-triangle-1' } }); |
| 26 | + const resourceB = new TestResource(stackB, 'Resource'); |
| 27 | + |
| 28 | + test.notEqual(generatePhysicalName(resourceA), generatePhysicalName(resourceB)); |
| 29 | + |
| 30 | + test.done(); |
| 31 | + }, |
| 32 | + |
| 33 | + 'generates different names in different regions'(test: nodeunit.Test) { |
| 34 | + const appA = new App(); |
| 35 | + const stackA = new Stack(appA, 'TestStack', { env: { account: '012345678912', region: 'bermuda-triangle-1' } }); |
| 36 | + const resourceA = new TestResource(stackA, 'Resource'); |
| 37 | + |
| 38 | + const appB = new App(); |
| 39 | + const stackB = new Stack(appB, 'TestStack', { env: { account: '012345678912', region: 'bermuda-triangle-2' } }); |
| 40 | + const resourceB = new TestResource(stackB, 'Resource'); |
| 41 | + |
| 42 | + test.notEqual(generatePhysicalName(resourceA), generatePhysicalName(resourceB)); |
| 43 | + |
| 44 | + test.done(); |
| 45 | + }, |
| 46 | + |
| 47 | + 'fails when the region is an unresolved token'(test: nodeunit.Test) { |
| 48 | + const app = new App(); |
| 49 | + const stack = new Stack(app, 'TestStack', { env: { account: '012345678912', region: Aws.REGION } }); |
| 50 | + const testResource = new TestResource(stack, 'A'); |
| 51 | + |
| 52 | + test.throws(() => generatePhysicalName(testResource), |
| 53 | + /Cannot generate a physical name for TestStack\/A, because the region is un-resolved or missing/); |
| 54 | + |
| 55 | + test.done(); |
| 56 | + }, |
| 57 | + |
| 58 | + 'fails when the region is not provided'(test: nodeunit.Test) { |
| 59 | + const app = new App(); |
| 60 | + const stack = new Stack(app, 'TestStack', { env: { account: '012345678912' } }); |
| 61 | + const testResource = new TestResource(stack, 'A'); |
| 62 | + |
| 63 | + test.throws(() => generatePhysicalName(testResource), |
| 64 | + /Cannot generate a physical name for TestStack\/A, because the region is un-resolved or missing/); |
| 65 | + |
| 66 | + test.done(); |
| 67 | + }, |
| 68 | + |
| 69 | + 'fails when the account is an unresolved token'(test: nodeunit.Test) { |
| 70 | + const app = new App(); |
| 71 | + const stack = new Stack(app, 'TestStack', { env: { account: Aws.ACCOUNT_ID, region: 'bermuda-triangle-1' } }); |
| 72 | + const testResource = new TestResource(stack, 'A'); |
| 73 | + |
| 74 | + test.throws(() => generatePhysicalName(testResource), |
| 75 | + /Cannot generate a physical name for TestStack\/A, because the account is un-resolved or missing/); |
| 76 | + |
| 77 | + test.done(); |
| 78 | + }, |
| 79 | + |
| 80 | + 'fails when the account is not provided'(test: nodeunit.Test) { |
| 81 | + const app = new App(); |
| 82 | + const stack = new Stack(app, 'TestStack', { env: { region: 'bermuda-triangle-1' } }); |
| 83 | + const testResource = new TestResource(stack, 'A'); |
| 84 | + |
| 85 | + test.throws(() => generatePhysicalName(testResource), |
| 86 | + /Cannot generate a physical name for TestStack\/A, because the account is un-resolved or missing/); |
| 87 | + |
| 88 | + test.done(); |
| 89 | + }, |
| 90 | +}); |
| 91 | + |
| 92 | +class TestResource extends Resource {} |
0 commit comments