Skip to content

Commit

Permalink
feat(stepfunctions): add service integrations (#1646)
Browse files Browse the repository at this point in the history
Introducing the `@aws-cdk/aws-stepfunctions-tasks` package, with service integrations for ECS, SNS and SQS. Lambda and Activity integrations have been moved there as well.

Add jest bindings for `haveResource` and `haveResourceLike`.

Allow specifying `placementConstraints` and `placementStrategies` in the constructor of `EC2Service`.

Exposing parts of `TokenMap` so that the reverse mapping of string => Token can be used by non-core libraries, if they need to embed non-literal data representation facilities into complex data structures (used in the SFN tasks to represent data that is extracted from the state JSON via a JSONPath).

BREAKING CHANGES

* If your using Lambdas or Activities in StepFunctions workflows, you must now instantiate `InvokeFunction` or `InvokeActivity` from the `@aws-cdk/aws-stepfunctions-tasks` package around it.
* `PlacementConstraint` used in task definitions is now a union object, constructed using factory functions on the `PlacementConstraint` class.
* Empty placement constraints and strategies will no longer render in the CloudFormation template. This may appear as diffs showing an empty line.
  • Loading branch information
rix0rrr authored May 8, 2019
1 parent 1cc43b3 commit e4ac767
Show file tree
Hide file tree
Showing 100 changed files with 13,867 additions and 1,231 deletions.
2 changes: 1 addition & 1 deletion design/aws-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ into an `{ "Fn::Join" }` expression which includes the relevant intrinsic
functions.

If needed, you can query whether an object includes unresolved tokens by using
the `cdk.unresolved(x)` function.
the `cdk.isToken(x)` function.

Resource attributes should use a type that corresponds to the __resolved__ AWS
CloudFormation type (e.g. `string`, `string[]`).
Expand Down
55 changes: 55 additions & 0 deletions packages/@aws-cdk/assert/jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Stack } from "@aws-cdk/cdk";
import { SynthesizedStack } from "@aws-cdk/cx-api";
import { HaveResourceAssertion, ResourcePart } from "./lib/assertions/have-resource";
import { expect as ourExpect } from './lib/expect';

declare global {
namespace jest {
interface Matchers<R> {
toHaveResource(resourceType: string,
properties?: any,
comparison?: ResourcePart): R;

toHaveResourceLike(resourceType: string,
properties?: any,
comparison?: ResourcePart): R;
}
}
}

expect.extend({
toHaveResource(
actual: SynthesizedStack | Stack,
resourceType: string,
properties?: any,
comparison?: ResourcePart) {

const assertion = new HaveResourceAssertion(resourceType, properties, comparison, false);
return assertHaveResource(assertion, actual);
},
toHaveResourceLike(
actual: SynthesizedStack | Stack,
resourceType: string,
properties?: any,
comparison?: ResourcePart) {

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

function assertHaveResource(assertion: HaveResourceAssertion, actual: SynthesizedStack | Stack) {
const inspector = ourExpect(actual);
const pass = assertion.assertUsing(inspector);
if (pass) {
return {
pass,
message: () => `Not ` + assertion.generateErrorMessage(),
};
} else {
return {
pass,
message: () => assertion.generateErrorMessage(),
};
}
}
24 changes: 14 additions & 10 deletions packages/@aws-cdk/assert/lib/assertions/have-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function haveResourceLike(resourceType: string,

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

class HaveResourceAssertion extends Assertion<StackInspector> {
export class HaveResourceAssertion extends Assertion<StackInspector> {
private inspected: InspectionFailure[] = [];
private readonly part: ResourcePart;
private readonly predicate: PropertyPredicate;
Expand Down Expand Up @@ -66,17 +66,21 @@ class HaveResourceAssertion extends Assertion<StackInspector> {
return false;
}

public assertOrThrow(inspector: StackInspector) {
if (!this.assertUsing(inspector)) {
const lines: string[] = [];
lines.push(`None of ${this.inspected.length} resources matches ${this.description}.`);
public generateErrorMessage() {
const lines: string[] = [];
lines.push(`None of ${this.inspected.length} resources matches ${this.description}.`);

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

throw new Error(lines.join('\n'));
return lines.join('\n');
}

public assertOrThrow(inspector: StackInspector) {
if (!this.assertUsing(inspector)) {
throw new Error(this.generateErrorMessage());
}
}

Expand Down
Loading

0 comments on commit e4ac767

Please sign in to comment.