Skip to content

Commit

Permalink
refactor: assertionsStack to assertionStack
Browse files Browse the repository at this point in the history
  • Loading branch information
Arun Donti committed Oct 7, 2022
1 parent 7a46a17 commit 18c8939
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/integ-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ By default an assertions stack is automatically generated for you. You may howev
```ts
declare const app: App;
declare const stack: Stack;
declare const assertionsStack: Stack;
declare const assertionStack: Stack;

const integ = new IntegTest(app, 'Integ', { testCases: [stack], assertionsStack: assertionsStack });
const integ = new IntegTest(app, 'Integ', { testCases: [stack], assertionStack: assertionStack });
integ.assertions.awsApiCall('S3', 'getObject');
```

Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/integ-tests/lib/test-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface IntegTestCaseProps extends TestOptions {
*
* @default - a stack is created for you
*/
readonly assertionsStack?: Stack
readonly assertionStack?: Stack
}

/**
Expand All @@ -42,7 +42,7 @@ export class IntegTestCase extends Construct {
constructor(scope: Construct, id: string, private readonly props: IntegTestCaseProps) {
super(scope, id);

this._assert = new DeployAssert(this, { stack: props.assertionsStack });
this._assert = new DeployAssert(this, { stack: props.assertionStack });
this.assertions = this._assert;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ export interface IntegTestProps extends TestOptions {
*
* @default - a stack is created for you
*/
readonly assertionsStack?: Stack
readonly assertionStack?: Stack
}

/**
Expand All @@ -164,7 +164,7 @@ export class IntegTest extends Construct {
allowDestroy: props.allowDestroy,
cdkCommandOptions: props.cdkCommandOptions,
stackUpdateWorkflow: props.stackUpdateWorkflow,
assertionsStack: props.assertionsStack,
assertionStack: props.assertionStack,
});
this.assertions = defaultTestCase.assertions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,14 @@ describe('User provided assertions stack', () => {
//GIVEN
const app = new App();
const stack = new Stack(app, 'TestStack');
const deplossert = new DeployAssert(app, { stack });

// WHEN
const cr = new CustomResource(stack, 'cr', { resourceType: 'Custom::Bar', serviceToken: 'foo' });
deplossert.awsApiCall('Service', 'Api', { Reference: cr.ref });
const integ = new IntegTest(app, 'integ', {
testCases: [stack],
assertionStack: stack,
});
integ.assertions.awsApiCall('Service', 'Api', { Reference: cr.ref });

// THEN
const template = Template.fromStack(stack);
Expand All @@ -187,30 +190,33 @@ describe('User provided assertions stack', () => {
//GIVEN
const app = new App();
const integStack = new Stack(app, 'TestStack');
const assertionsStack = new Stack(app, 'AssertionsStack');
const deplossert = new DeployAssert(app, { stack: assertionsStack });
const assertionStack = new Stack(app, 'AssertionsStack');
const integ = new IntegTest(app, 'integ', {
testCases: [integStack],
assertionStack: assertionStack,
});

// WHEN
const cr = new CustomResource(integStack, 'cr', { resourceType: 'Custom::Bar', serviceToken: 'foo' });
deplossert.awsApiCall('Service', 'Api', { Reference: cr.ref });
integ.assertions.awsApiCall('Service', 'Api', { Reference: cr.ref });

// THEN
const integTemplate = Template.fromStack(integStack);
const assertionsTemplate = Template.fromStack(assertionsStack);
const assertionTemplate = Template.fromStack(assertionStack);
integTemplate.resourceCountIs('Custom::Bar', 1);
assertionsTemplate.resourceCountIs('Custom::DeployAssert@SdkCallServiceApi', 1);
assertionTemplate.resourceCountIs('Custom::DeployAssert@SdkCallServiceApi', 1);
});

test('not throw when environment matches', () => {
//GIVEN
const app = new App();
const env = { region: 'us-west-2' };
const integStack = new Stack(app, 'IntegStack', { env: env });
const assertionsStack = new Stack(app, 'AssertionsStack', { env: env });
const assertionStack = new Stack(app, 'AssertionsStack', { env: env });
const cr = new CustomResource(integStack, 'cr', { serviceToken: 'foo' });
const integ = new IntegTest(app, 'integ', {
testCases: [integStack],
assertionsStack: assertionsStack,
assertionStack: assertionStack,
});
integ.assertions.awsApiCall('Service', 'api', { Reference: cr.getAttString('bar') });

Expand Down

0 comments on commit 18c8939

Please sign in to comment.