-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
604 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
import * as path from 'path'; | ||
import * as mockfs from 'mock-fs'; | ||
import { AssemblyManifestReader } from '../../src/assembly'; | ||
|
||
describe('cloud assembly manifest reader', () => { | ||
const manifestFile = '/tmp/foo/bar/does/not/exist/manifest.json'; | ||
const manifestStack = '/tmp/foo/bar/does/not/exist/test-stack.template.json'; | ||
const manifestTree = '/tmp/foo/bar/does/not/exist/tree.json'; | ||
const manifestAssets = '/tmp/foo/bar/does/not/exist/test-stack.assets.json'; | ||
beforeEach(() => { | ||
mockfs({ | ||
// Recursively loads all node_modules | ||
node_modules: mockfs.load(path.resolve(__dirname, '../../node_modules')), | ||
[manifestAssets]: JSON.stringify({ | ||
version: '36.0.0', | ||
files: { | ||
abe4e2f4fcc1aaaf53db4829c23a5cf08795d36cce0f68a3321c1c8d728fec44: { | ||
source: { | ||
path: 'asset.abe4e2f4fcc1aaaf53db4829c23a5cf08795d36cce0f68a3321c1c8d728fec44', | ||
packaging: 'zip', | ||
}, | ||
destinations: { | ||
'current_account-current_region': { | ||
bucketName: 'cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}', | ||
objectKey: 'abe4e2f4fcc1aaaf53db4829c23a5cf08795d36cce0f68a3321c1c8d728fec44.zip', | ||
}, | ||
}, | ||
}, | ||
cd12352cc95113284dfa6575f1d74d8dea52dddcaa2f46fa695b33b59c1b4579: { | ||
source: { | ||
path: 'stack.template.json', | ||
packaging: 'file', | ||
}, | ||
destinations: { | ||
'current_account-current_region': { | ||
bucketName: 'cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}', | ||
objectKey: 'cd12352cc95113284dfa6575f1d74d8dea52dddcaa2f46fa695b33b59c1b4579.json', | ||
}, | ||
}, | ||
}, | ||
}, | ||
dockerImages: {}, | ||
}), | ||
[manifestTree]: JSON.stringify({ | ||
version: 'tree-0.1', | ||
tree: { | ||
id: 'App', | ||
path: '', | ||
children: { | ||
'test-stack': { | ||
id: 'test-stack', | ||
path: 'test-stack', | ||
}, | ||
}, | ||
}, | ||
}), | ||
[manifestStack]: JSON.stringify({ | ||
Resources: { | ||
MyFunction1ServiceRole9852B06B: { | ||
Type: 'AWS::IAM::Role', | ||
Properties: {}, | ||
}, | ||
MyFunction12A744C2E: { | ||
Type: 'AWS::Lambda::Function', | ||
Properties: {}, | ||
}, | ||
}, | ||
}), | ||
[manifestFile]: JSON.stringify({ | ||
version: '17.0.0', | ||
artifacts: { | ||
'test-stack.assets': { | ||
type: 'cdk:asset-manifest', | ||
properties: { | ||
file: 'test-stack.assets.json', | ||
}, | ||
}, | ||
Tree: { | ||
type: 'cdk:tree', | ||
properties: { | ||
file: 'tree.json', | ||
}, | ||
}, | ||
'test-stack': { | ||
type: 'aws:cloudformation:stack', | ||
environment: 'aws://unknown-account/unknown-region', | ||
properties: { | ||
templateFile: 'test-stack.template.json', | ||
validateOnSynth: false, | ||
}, | ||
metadata: { | ||
'/test-stack/MyFunction1/ServiceRole/Resource': [ | ||
{ | ||
type: 'aws:cdk:logicalId', | ||
data: 'MyFunction1ServiceRole9852B06B', | ||
}, | ||
], | ||
'/test-stack/MyFunction1/Resource': [ | ||
{ | ||
type: 'aws:cdk:logicalId', | ||
data: 'MyFunction12A744C2E', | ||
}, | ||
], | ||
}, | ||
displayName: 'test-stack', | ||
}, | ||
}, | ||
}), | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
mockfs.restore(); | ||
}); | ||
|
||
test('can read manifest from file', () => { | ||
expect(() => { | ||
AssemblyManifestReader.fromFile(manifestFile); | ||
}).not.toThrow(); | ||
}); | ||
|
||
test('throws if manifest not found', () => { | ||
expect(() => { | ||
AssemblyManifestReader.fromFile('some-other-file'); | ||
}).toThrow(/Cannot read manifest 'some-other-file':/); | ||
}); | ||
|
||
test('throws if manifest file not found', () => { | ||
expect(() => { | ||
AssemblyManifestReader.fromPath('some-other-file'); | ||
}).toThrow(/Cannot read manifest at 'some-other-file':/); | ||
}); | ||
|
||
test('can read manifest file from path', () => { | ||
expect(() => { | ||
AssemblyManifestReader.fromPath(manifestFile); | ||
}).not.toThrow(); | ||
}); | ||
|
||
test('can read manifest from path', () => { | ||
expect(() => { | ||
AssemblyManifestReader.fromPath(path.dirname(manifestFile)); | ||
}).not.toThrow(); | ||
}); | ||
|
||
test('fromPath sets directory correctly', () => { | ||
const manifest = AssemblyManifestReader.fromPath(path.dirname(manifestFile)); | ||
expect(manifest.directory).toEqual('/tmp/foo/bar/does/not/exist'); | ||
}); | ||
|
||
test('can get stacks from manifest', () => { | ||
const manifest = AssemblyManifestReader.fromFile(manifestFile); | ||
|
||
expect(manifest.stackManifests[0]).toEqual({ | ||
assets: expect.anything(), | ||
constructTree: { id: 'test-stack', path: 'test-stack' }, | ||
directory: '/tmp/foo/bar/does/not/exist', | ||
id: 'test-stack', | ||
metadata: { | ||
'test-stack/MyFunction1/Resource': 'MyFunction12A744C2E', | ||
'test-stack/MyFunction1/ServiceRole/Resource': 'MyFunction1ServiceRole9852B06B', | ||
}, | ||
outputs: undefined, | ||
parameters: undefined, | ||
resources: { | ||
MyFunction12A744C2E: { Properties: {}, Type: 'AWS::Lambda::Function' }, | ||
MyFunction1ServiceRole9852B06B: { Properties: {}, Type: 'AWS::IAM::Role' }, | ||
}, | ||
templatePath: 'test-stack.template.json', | ||
}); | ||
expect(manifest.stackManifests[0].fileAssets.length).toEqual(1); | ||
expect(manifest.stackManifests[0].fileAssets[0]).toEqual({ | ||
destination: { | ||
bucketName: 'cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}', | ||
objectKey: 'abe4e2f4fcc1aaaf53db4829c23a5cf08795d36cce0f68a3321c1c8d728fec44.zip', | ||
}, | ||
id: { | ||
assetId: 'abe4e2f4fcc1aaaf53db4829c23a5cf08795d36cce0f68a3321c1c8d728fec44', | ||
destinationId: 'current_account-current_region', | ||
}, | ||
packaging: 'zip', | ||
path: '/tmp/foo/bar/does/not/exist/asset.abe4e2f4fcc1aaaf53db4829c23a5cf08795d36cce0f68a3321c1c8d728fec44', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { StackManifest } from '../../src/assembly'; | ||
|
||
describe('StackManifest', () => { | ||
test('Throws if template has no resources', () => { | ||
expect(() => { | ||
new StackManifest('dir', 'id', 'path', {}, { id: 'id', path: 'path' }, {}, []); | ||
}).toThrow(/CloudFormation template has no resources/); | ||
}); | ||
|
||
test('get file assets', () => { | ||
const stack = new StackManifest( | ||
'dir', | ||
'id', | ||
'path', | ||
{}, | ||
{ id: 'id', path: 'path' }, | ||
{ | ||
Resources: { SomeResource: { Type: 'sometype', Properties: {} } }, | ||
}, | ||
[ | ||
{ | ||
id: { | ||
assetId: 'asset', | ||
destinationId: 'dest', | ||
}, | ||
type: 'file', | ||
source: { path: 'somepath' }, | ||
destination: { objectKey: 'abc', bucketName: 'bucket' }, | ||
genericSource: {}, | ||
genericDestination: {}, | ||
}, | ||
{ | ||
id: { | ||
assetId: 'asset2', | ||
destinationId: 'dest2', | ||
}, | ||
type: 'docker-image', | ||
source: {}, | ||
destination: { imageTag: 'tag', repositoryName: 'repop' }, | ||
genericSource: {}, | ||
genericDestination: {}, | ||
}, | ||
], | ||
); | ||
expect(stack.fileAssets.length).toEqual(1); | ||
expect(stack.fileAssets[0]).toEqual({ | ||
destination: { | ||
bucketName: 'bucket', | ||
objectKey: 'abc', | ||
}, | ||
id: { | ||
assetId: 'asset', | ||
destinationId: 'dest', | ||
}, | ||
packaging: 'file', | ||
path: 'dir/somepath', | ||
}); | ||
}); | ||
|
||
test('can get logicalId for path', () => { | ||
const stack = new StackManifest( | ||
'dir', | ||
'id', | ||
'path', | ||
{ | ||
'stack/bucket': 'SomeBucket', | ||
}, | ||
{ | ||
id: 'id', | ||
path: 'path', | ||
}, | ||
{ | ||
Resources: { | ||
SomeBucket: { | ||
Type: 'AWS::S3::Bucket', | ||
Properties: {}, | ||
}, | ||
}, | ||
}, | ||
[], | ||
); | ||
expect(stack.logicalIdForPath('stack/bucket')).toEqual('SomeBucket'); | ||
}); | ||
|
||
test('can get resource for path', () => { | ||
const stack = new StackManifest( | ||
'dir', | ||
'id', | ||
'path', | ||
{ | ||
'stack/bucket': 'SomeBucket', | ||
}, | ||
{ | ||
id: 'id', | ||
path: 'path', | ||
}, | ||
{ | ||
Resources: { | ||
SomeBucket: { | ||
Type: 'AWS::S3::Bucket', | ||
Properties: { Key: 'Value' }, | ||
}, | ||
}, | ||
}, | ||
[], | ||
); | ||
expect(stack.resourceWithPath('stack/bucket')).toEqual({ | ||
Type: 'AWS::S3::Bucket', | ||
Properties: { Key: 'Value' }, | ||
}); | ||
}); | ||
|
||
test('can get resource for logicalId', () => { | ||
const stack = new StackManifest( | ||
'dir', | ||
'id', | ||
'path', | ||
{ | ||
'stack/bucket': 'SomeBucket', | ||
}, | ||
{ | ||
id: 'id', | ||
path: 'path', | ||
}, | ||
{ | ||
Resources: { | ||
SomeBucket: { | ||
Type: 'AWS::S3::Bucket', | ||
Properties: { Key: 'Value' }, | ||
}, | ||
}, | ||
}, | ||
[], | ||
); | ||
expect(stack.resourceWithLogicalId('SomeBucket')).toEqual({ | ||
Type: 'AWS::S3::Bucket', | ||
Properties: { Key: 'Value' }, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.