|
1 | 1 | import { expect, haveResource } from '@aws-cdk/assert';
|
2 | 2 | import * as iam from '@aws-cdk/aws-iam';
|
3 |
| -import { Aws, CfnResource, Stack } from '@aws-cdk/core'; |
| 3 | +import { Aws, CfnResource, Stack, Arn } from '@aws-cdk/core'; |
4 | 4 | import { Test } from 'nodeunit';
|
5 | 5 | import { EventBus } from '../lib';
|
6 | 6 |
|
@@ -55,6 +55,65 @@ export = {
|
55 | 55 | test.done();
|
56 | 56 | },
|
57 | 57 |
|
| 58 | + 'imported event bus'(test: Test) { |
| 59 | + const stack = new Stack(); |
| 60 | + |
| 61 | + const eventBus = new EventBus(stack, 'Bus'); |
| 62 | + |
| 63 | + const importEB = EventBus.fromEventBusArn(stack, 'ImportBus', eventBus.eventBusArn); |
| 64 | + |
| 65 | + // WHEN |
| 66 | + new CfnResource(stack, 'Res', { |
| 67 | + type: 'Test::Resource', |
| 68 | + properties: { |
| 69 | + EventBusArn1: eventBus.eventBusArn, |
| 70 | + EventBusArn2: importEB.eventBusArn, |
| 71 | + }, |
| 72 | + }); |
| 73 | + |
| 74 | + expect(stack).to(haveResource('Test::Resource', { |
| 75 | + EventBusArn1: { 'Fn::GetAtt': ['BusEA82B648', 'Arn'] }, |
| 76 | + EventBusArn2: { 'Fn::GetAtt': ['BusEA82B648', 'Arn'] }, |
| 77 | + })); |
| 78 | + |
| 79 | + test.done(); |
| 80 | + }, |
| 81 | + |
| 82 | + 'same account imported event bus has right resource env'(test: Test) { |
| 83 | + const stack = new Stack(); |
| 84 | + |
| 85 | + const eventBus = new EventBus(stack, 'Bus'); |
| 86 | + |
| 87 | + const importEB = EventBus.fromEventBusArn(stack, 'ImportBus', eventBus.eventBusArn); |
| 88 | + |
| 89 | + // WHEN |
| 90 | + test.deepEqual(stack.resolve(importEB.env.account), { 'Fn::Select': [4, { 'Fn::Split': [':', { 'Fn::GetAtt': ['BusEA82B648', 'Arn'] }] }] }); |
| 91 | + test.deepEqual(stack.resolve(importEB.env.region), { 'Fn::Select': [3, { 'Fn::Split': [':', { 'Fn::GetAtt': ['BusEA82B648', 'Arn'] }] }] }); |
| 92 | + |
| 93 | + test.done(); |
| 94 | + }, |
| 95 | + |
| 96 | + 'cross account imported event bus has right resource env'(test: Test) { |
| 97 | + const stack = new Stack(); |
| 98 | + |
| 99 | + const arnParts = { |
| 100 | + resource: 'bus', |
| 101 | + service: 'events', |
| 102 | + account: 'myAccount', |
| 103 | + region: 'us-west-1', |
| 104 | + }; |
| 105 | + |
| 106 | + const arn = Arn.format(arnParts, stack); |
| 107 | + |
| 108 | + const importEB = EventBus.fromEventBusArn(stack, 'ImportBus', arn); |
| 109 | + |
| 110 | + // WHEN |
| 111 | + test.deepEqual(importEB.env.account, arnParts.account); |
| 112 | + test.deepEqual(importEB.env.region, arnParts.region); |
| 113 | + |
| 114 | + test.done(); |
| 115 | + }, |
| 116 | + |
58 | 117 | 'can get bus name'(test: Test) {
|
59 | 118 | // GIVEN
|
60 | 119 | const stack = new Stack();
|
|
0 commit comments