Skip to content

Commit

Permalink
Merge pull request #4 from aws/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
KingOfPoptart authored Jan 16, 2020
2 parents f5d3ab8 + a1cd743 commit 3304d48
Show file tree
Hide file tree
Showing 343 changed files with 10,471 additions and 5,152 deletions.
100 changes: 100 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"tools/*"
],
"rejectCycles": "true",
"version": "1.19.0"
"version": "1.21.0"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-cdk",
"version": "1.19.0",
"version": "1.21.0",
"private": true,
"pkglint": {
"include": "dependencies/node-version"
Expand Down
16 changes: 8 additions & 8 deletions packages/@aws-cdk/alexa-ask/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-cdk/alexa-ask",
"version": "1.19.0",
"version": "1.21.0",
"description": "The CDK Construct Library for Alexa::ASK",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -80,19 +80,19 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "1.19.0",
"cdk-build-tools": "1.19.0",
"cfn2ts": "1.19.0",
"pkglint": "1.19.0"
"@aws-cdk/assert": "1.21.0",
"cdk-build-tools": "1.21.0",
"cfn2ts": "1.21.0",
"pkglint": "1.21.0"
},
"dependencies": {
"@aws-cdk/core": "1.19.0"
"@aws-cdk/core": "1.21.0"
},
"peerDependencies": {
"@aws-cdk/core": "1.19.0"
"@aws-cdk/core": "1.21.0"
},
"engines": {
"node": ">= 10.3.0"
},
"stability": "experimental"
}
}
46 changes: 23 additions & 23 deletions packages/@aws-cdk/app-delivery/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aws-cdk/app-delivery",
"description": "Continuous Integration / Continuous Delivery for CDK Applications",
"version": "1.19.0",
"version": "1.21.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"jsii": {
Expand Down Expand Up @@ -40,24 +40,24 @@
"compat": "cdk-compat"
},
"dependencies": {
"@aws-cdk/aws-cloudformation": "1.19.0",
"@aws-cdk/aws-codebuild": "1.19.0",
"@aws-cdk/aws-codepipeline": "1.19.0",
"@aws-cdk/aws-codepipeline-actions": "1.19.0",
"@aws-cdk/aws-events": "1.19.0",
"@aws-cdk/aws-iam": "1.19.0",
"@aws-cdk/core": "1.19.0",
"@aws-cdk/cx-api": "1.19.0"
"@aws-cdk/aws-cloudformation": "1.21.0",
"@aws-cdk/aws-codebuild": "1.21.0",
"@aws-cdk/aws-codepipeline": "1.21.0",
"@aws-cdk/aws-codepipeline-actions": "1.21.0",
"@aws-cdk/aws-events": "1.21.0",
"@aws-cdk/aws-iam": "1.21.0",
"@aws-cdk/core": "1.21.0",
"@aws-cdk/cx-api": "1.21.0"
},
"devDependencies": {
"@aws-cdk/assert": "1.19.0",
"@aws-cdk/aws-s3": "1.19.0",
"@aws-cdk/assert": "1.21.0",
"@aws-cdk/aws-s3": "1.21.0",
"@types/nodeunit": "^0.0.30",
"cdk-build-tools": "1.19.0",
"cdk-integ-tools": "1.19.0",
"cdk-build-tools": "1.21.0",
"cdk-integ-tools": "1.21.0",
"fast-check": "^1.21.0",
"nodeunit": "^0.11.3",
"pkglint": "1.19.0"
"pkglint": "1.21.0"
},
"repository": {
"type": "git",
Expand All @@ -76,14 +76,14 @@
"cdk"
],
"peerDependencies": {
"@aws-cdk/aws-cloudformation": "1.19.0",
"@aws-cdk/aws-codebuild": "1.19.0",
"@aws-cdk/aws-codepipeline": "1.19.0",
"@aws-cdk/aws-codepipeline-actions": "1.19.0",
"@aws-cdk/aws-events": "1.19.0",
"@aws-cdk/aws-iam": "1.19.0",
"@aws-cdk/core": "1.19.0",
"@aws-cdk/cx-api": "1.19.0"
"@aws-cdk/aws-cloudformation": "1.21.0",
"@aws-cdk/aws-codebuild": "1.21.0",
"@aws-cdk/aws-codepipeline": "1.21.0",
"@aws-cdk/aws-codepipeline-actions": "1.21.0",
"@aws-cdk/aws-events": "1.21.0",
"@aws-cdk/aws-iam": "1.21.0",
"@aws-cdk/core": "1.21.0",
"@aws-cdk/cx-api": "1.21.0"
},
"engines": {
"node": ">= 10.3.0"
Expand All @@ -98,4 +98,4 @@
"docs-public-apis:@aws-cdk/app-delivery.PipelineDeployStackActionProps"
]
}
}
}
22 changes: 22 additions & 0 deletions packages/@aws-cdk/assert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,25 @@ expect(stack).to(haveResource('AWS::CertificateManager::Certificate', {
// Note: some properties omitted here
}));
```
### Check existence of an output
`haveOutput` assertion can be used to check that a stack contains specific output.
Parameters to check against can be:
- `outputName`
- `outputValue`
- `exportName`

If `outputValue` is provided, at least one of `outputName`, `exportName` should be provided as well

Example
```ts
expect(synthStack).to(haveOutput({
outputName: 'TestOutputName',
exportName: 'TestOutputExportName',
outputValue: {
'Fn::GetAtt': [
'TestResource',
'Arn'
]
}
}));
```
25 changes: 19 additions & 6 deletions packages/@aws-cdk/assert/jest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Stack } from "@aws-cdk/core";
import { Stack } from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import { HaveResourceAssertion, ResourcePart } from "./lib/assertions/have-resource";
import { MatchStyle, matchTemplate } from "./lib/assertions/match-template";
import { JestFriendlyAssertion } from './lib/assertion';
import { haveOutput, HaveOutputProperties } from './lib/assertions/have-output';
import { HaveResourceAssertion, ResourcePart } from './lib/assertions/have-resource';
import { MatchStyle, matchTemplate } from './lib/assertions/match-template';
import { expect as ourExpect } from './lib/expect';
import { StackInspector } from './lib/inspector';

declare global {
namespace jest {
Expand All @@ -17,6 +20,8 @@ declare global {
toHaveResourceLike(resourceType: string,
properties?: any,
comparison?: ResourcePart): R;

toHaveOutput(props: HaveOutputProperties): R;
}
}
}
Expand Down Expand Up @@ -50,20 +55,28 @@ expect.extend({
comparison?: ResourcePart) {

const assertion = new HaveResourceAssertion(resourceType, properties, comparison, false);
return assertHaveResource(assertion, actual);
return applyAssertion(assertion, actual);
},

toHaveResourceLike(
actual: cxapi.CloudFormationStackArtifact | Stack,
resourceType: string,
properties?: any,
comparison?: ResourcePart) {

const assertion = new HaveResourceAssertion(resourceType, properties, comparison, true);
return assertHaveResource(assertion, actual);
return applyAssertion(assertion, actual);
},

toHaveOutput(
actual: cxapi.CloudFormationStackArtifact | Stack,
props: HaveOutputProperties) {

return applyAssertion(haveOutput(props), actual);
}
});

function assertHaveResource(assertion: HaveResourceAssertion, actual: cxapi.CloudFormationStackArtifact | Stack) {
function applyAssertion(assertion: JestFriendlyAssertion<StackInspector>, actual: cxapi.CloudFormationStackArtifact | Stack) {
const inspector = ourExpect(actual);
const pass = assertion.assertUsing(inspector);
if (pass) {
Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/assert/lib/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ export abstract class Assertion<InspectorClass extends Inspector> {
}
}

export abstract class JestFriendlyAssertion<InspectorClass extends Inspector> extends Assertion<InspectorClass> {
/**
* Generates an error message that can be used by Jest.
*/
public abstract generateErrorMessage(): string;
}

import { AndAssertion } from "./assertions/and-assertion";

function and<I extends Inspector>(left: Assertion<I>, right: Assertion<I>): Assertion<I> {
Expand Down
116 changes: 116 additions & 0 deletions packages/@aws-cdk/assert/lib/assertions/have-output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { JestFriendlyAssertion } from '../assertion';
import { StackInspector } from '../inspector';

class HaveOutputAssertion extends JestFriendlyAssertion<StackInspector> {
private readonly inspected: InspectionFailure[] = [];

constructor(private readonly outputName?: string, private readonly exportName?: any, private outputValue?: any) {
super();
if (!this.outputName && !this.exportName) {
throw new Error('At least one of [outputName, exportName] should be provided');
}
}

public get description(): string {
const descriptionPartsArray = new Array<string>();

if (this.outputName) {
descriptionPartsArray.push(`name '${this.outputName}'`);
}
if (this.exportName) {
descriptionPartsArray.push(`export name ${JSON.stringify(this.exportName)}`);
}
if (this.outputValue) {
descriptionPartsArray.push(`value ${JSON.stringify(this.outputValue)}`);
}

return 'output with ' + descriptionPartsArray.join(', ');
}

public assertUsing(inspector: StackInspector): boolean {
if (!('Outputs' in inspector.value)) {
return false;
}

for (const [name, props] of Object.entries(inspector.value.Outputs as Record<string, any>)) {
const mismatchedFields = new Array<string>();

if (this.outputName && name !== this.outputName) {
mismatchedFields.push('name');
}

if (this.exportName && JSON.stringify(this.exportName) !== JSON.stringify(props.Export?.Name)) {
mismatchedFields.push('export name');
}

if (this.outputValue && JSON.stringify(this.outputValue) !== JSON.stringify(props.Value)) {
mismatchedFields.push('value');
}

if (mismatchedFields.length === 0) {
return true;
}

this.inspected.push({
output: { [name]: props },
failureReason: `mismatched ${mismatchedFields.join(', ')}`,
});
}

return false;
}

public generateErrorMessage() {
const lines = new Array<string>();

lines.push(`None of ${this.inspected.length} outputs matches ${this.description}.`);

for (const inspected of this.inspected) {
lines.push(`- ${inspected.failureReason} in:`);
lines.push(indent(4, JSON.stringify(inspected.output, null, 2)));
}

return lines.join('\n');
}
}

/**
* Interface for haveOutput function properties
* NOTE that at least one of [outputName, exportName] should be provided
*/
export interface HaveOutputProperties {
/**
* Logical ID of the output
* @default - the logical ID of the output will not be checked
*/
outputName?: string;
/**
* Export name of the output, when it's exported for cross-stack referencing
* @default - the export name is not required and will not be checked
*/
exportName?: any;
/**
* Value of the output;
* @default - the value will not be checked
*/
outputValue?: any;
}

interface InspectionFailure {
output: any;
failureReason: string;
}

/**
* An assertion to check whether Output with particular properties is present in a stack
* @param props properties of the Output that is being asserted against.
* Check ``HaveOutputProperties`` interface to get full list of available parameters
*/
export function haveOutput(props: HaveOutputProperties): JestFriendlyAssertion<StackInspector> {
return new HaveOutputAssertion(props.outputName, props.exportName, props.outputValue);
}

function indent(n: number, s: string) {
const prefix = ' '.repeat(n);
return prefix + s.replace(/\n/g, '\n' + prefix);
}
6 changes: 3 additions & 3 deletions packages/@aws-cdk/assert/lib/assertions/have-resource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Assertion } from "../assertion";
import { Assertion, JestFriendlyAssertion } from "../assertion";
import { StackInspector } from "../inspector";

/**
Expand Down Expand Up @@ -30,8 +30,8 @@ export function haveResourceLike(resourceType: string,

type PropertyPredicate = (props: any, inspection: InspectionFailure) => boolean;

export class HaveResourceAssertion extends Assertion<StackInspector> {
private inspected: InspectionFailure[] = [];
export class HaveResourceAssertion extends JestFriendlyAssertion<StackInspector> {
private readonly inspected: InspectionFailure[] = [];
private readonly part: ResourcePart;
private readonly predicate: PropertyPredicate;

Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/assert/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './inspector';
export * from './synth-utils';

export * from './assertions/exist';
export * from './assertions/have-output';
export * from './assertions/have-resource';
export * from './assertions/have-type';
export * from './assertions/match-template';
Expand Down
Loading

0 comments on commit 3304d48

Please sign in to comment.