From 857f7db33e375eb280128c52536dd893c1f545a4 Mon Sep 17 00:00:00 2001 From: Arun Donti Date: Thu, 6 Oct 2022 17:50:37 -0400 Subject: [PATCH 1/4] feat(integ-tests): environment aware assertions --- packages/@aws-cdk/integ-tests/README.md | 20 +++++++++ .../lib/assertions/private/deploy-assert.ts | 20 ++++++--- .../@aws-cdk/integ-tests/lib/test-case.ts | 23 ++++++++-- .../test/assertions/deploy-assert.test.ts | 42 ++++++++++++++++++- .../integ-tests/test/assertions/sdk.test.ts | 4 +- 5 files changed, 96 insertions(+), 13 deletions(-) diff --git a/packages/@aws-cdk/integ-tests/README.md b/packages/@aws-cdk/integ-tests/README.md index e35714a844fd4..a561459904c9d 100644 --- a/packages/@aws-cdk/integ-tests/README.md +++ b/packages/@aws-cdk/integ-tests/README.md @@ -264,6 +264,26 @@ integ.assertions.awsApiCall('SQS', 'receiveMessage', { }); ``` + +Additionally, you can test non environment-agnostic stacks by setting the environment for the integration tests: + +```ts +declare const app: App; +const env = { region: 'us-west-2' } +const stack = new Stack(app, 'nlb-test', { env: env } ); + +const nlb = new elbv2.NetworkLoadBalancer(stack, 'nlb', { vpc: new ec2.Vpc(stack, 'vpc') }) +// requires region to be set +nlb.logAccessLogs(new s3.Bucket(stack, 'logbucket')) +const integ = new IntegTest(app, 'Integ', { + testCases: [stack], + env: env, +}); +integ.assertions.awsApiCall('Elbv2', 'describeLoadBalancers', { + Names: [nlb.loadBalancerName] +}); +``` + By default, the `AwsApiCall` construct will automatically add the correct IAM policies to allow the Lambda function to make the API call. It does this based on the `service` and `api` that is provided. In the above example the service is `SQS` and the api is diff --git a/packages/@aws-cdk/integ-tests/lib/assertions/private/deploy-assert.ts b/packages/@aws-cdk/integ-tests/lib/assertions/private/deploy-assert.ts index 321082d7f8ce4..177a89fb9d9b4 100644 --- a/packages/@aws-cdk/integ-tests/lib/assertions/private/deploy-assert.ts +++ b/packages/@aws-cdk/integ-tests/lib/assertions/private/deploy-assert.ts @@ -1,8 +1,8 @@ -import { Stack } from '@aws-cdk/core'; +import { Environment, Stack } from '@aws-cdk/core'; import { Construct, IConstruct, Node } from 'constructs'; import { IApiCall } from '../api-call-base'; import { EqualsAssertion } from '../assertions'; -import { ExpectedResult, ActualResult } from '../common'; +import { ActualResult, ExpectedResult } from '../common'; import { md5hash } from '../private/hash'; import { AwsApiCall, LambdaInvokeFunction, LambdaInvokeFunctionProps } from '../sdk'; import { IDeployAssert } from '../types'; @@ -13,7 +13,15 @@ const DEPLOY_ASSERT_SYMBOL = Symbol.for('@aws-cdk/integ-tests.DeployAssert'); /** * Options for DeployAssert */ -export interface DeployAssertProps { } +export interface DeployAssertProps { + + /** + * The environment for the assertions stack + * + * @default - environment-agnostic + */ + readonly env?: Environment +} /** * Construct that allows for registering a list of assertions @@ -25,7 +33,7 @@ export class DeployAssert extends Construct implements IDeployAssert { * Returns whether the construct is a DeployAssert construct */ public static isDeployAssert(x: any): x is DeployAssert { - return x !== null && typeof(x) === 'object' && DEPLOY_ASSERT_SYMBOL in x; + return x !== null && typeof (x) === 'object' && DEPLOY_ASSERT_SYMBOL in x; } /** @@ -42,10 +50,10 @@ export class DeployAssert extends Construct implements IDeployAssert { public scope: Stack; - constructor(scope: Construct) { + constructor(scope: Construct, props?: DeployAssertProps) { super(scope, 'Default'); - this.scope = new Stack(scope, 'DeployAssert'); + this.scope = new Stack(scope, 'DeployAssert', { env: props?.env }); Object.defineProperty(this, DEPLOY_ASSERT_SYMBOL, { value: true }); } diff --git a/packages/@aws-cdk/integ-tests/lib/test-case.ts b/packages/@aws-cdk/integ-tests/lib/test-case.ts index 1d3cce2026bb5..7e22c2261a87a 100644 --- a/packages/@aws-cdk/integ-tests/lib/test-case.ts +++ b/packages/@aws-cdk/integ-tests/lib/test-case.ts @@ -1,5 +1,5 @@ import { IntegManifest, Manifest, TestCase, TestOptions } from '@aws-cdk/cloud-assembly-schema'; -import { attachCustomSynthesis, Stack, ISynthesisSession, StackProps } from '@aws-cdk/core'; +import { attachCustomSynthesis, Environment, ISynthesisSession, Stack, StackProps } from '@aws-cdk/core'; import { Construct } from 'constructs'; import { IDeployAssert } from './assertions'; import { DeployAssert } from './assertions/private/deploy-assert'; @@ -15,6 +15,13 @@ export interface IntegTestCaseProps extends TestOptions { * Stacks to be deployed during the test */ readonly stacks: Stack[]; + + /** + * Specify an environment for the assertions stack + * + * @default - environment-agnostic + */ + readonly env?: Environment } /** @@ -35,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); + this._assert = new DeployAssert(this, { env: props.env }); this.assertions = this._assert; } @@ -63,7 +70,7 @@ export class IntegTestCase extends Construct { /** * Properties of an integration test case stack */ -export interface IntegTestCaseStackProps extends TestOptions, StackProps {} +export interface IntegTestCaseStackProps extends TestOptions, StackProps { } /** * An integration test case stack. Allows the definition of test properties @@ -78,7 +85,7 @@ export class IntegTestCaseStack extends Stack { * Returns whether the construct is a IntegTestCaseStack */ public static isIntegTestCaseStack(x: any): x is IntegTestCaseStack { - return x !== null && typeof(x) === 'object' && TEST_CASE_STACK_SYMBOL in x; + return x !== null && typeof (x) === 'object' && TEST_CASE_STACK_SYMBOL in x; } /** @@ -125,6 +132,13 @@ export interface IntegTestProps extends TestOptions { * @default false */ readonly enableLookups?: boolean; + + /** + * Set an AWS environment (account/region) for the assertions stack. + * + * @default - environment-agnostic + */ + readonly env?: Environment } /** @@ -150,6 +164,7 @@ export class IntegTest extends Construct { allowDestroy: props.allowDestroy, cdkCommandOptions: props.cdkCommandOptions, stackUpdateWorkflow: props.stackUpdateWorkflow, + env: props.env, }); this.assertions = defaultTestCase.assertions; diff --git a/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts b/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts index bbc2609822356..90839f7ea01fb 100644 --- a/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts +++ b/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts @@ -1,7 +1,8 @@ import { Template } from '@aws-cdk/assertions'; -import { App, Stack } from '@aws-cdk/core'; +import { App, CustomResource, Stack } from '@aws-cdk/core'; import { ActualResult, ExpectedResult, InvocationType, LogType } from '../../lib/assertions'; import { DeployAssert } from '../../lib/assertions/private/deploy-assert'; +import { IntegTest } from '../../lib/test-case'; describe('DeployAssert', () => { @@ -164,3 +165,42 @@ describe('DeployAssert', () => { }); }); }); + +describe('Environment aware assertions', () => { + test('throw when environment not provided', () => { + //GIVEN + const app = new App(); + const env = { region: 'us-west-2' }; + const stack = new Stack(app, 'TestStack', { env: env }); + const cr = new CustomResource(stack, 'cr', { serviceToken: 'foo' }); + const integ = new IntegTest(app, 'integ', { + testCases: [stack], + }); + integ.assertions.awsApiCall('Service', 'api', { Reference: cr.getAttString('bar') }); + + // WHEN + expect(() => { + // THEN + app.synth(); + }).toThrow(/only supported for stacks deployed to the same environment/); + }); + + test('not throw when environment matches', () => { + //GIVEN + const app = new App(); + const env = { region: 'us-west-2' }; + const stack = new Stack(app, 'TestStack', { env: env }); + const cr = new CustomResource(stack, 'cr', { serviceToken: 'foo' }); + const integ = new IntegTest(app, 'integ', { + testCases: [stack], + env: env, + }); + integ.assertions.awsApiCall('Service', 'api', { Reference: cr.getAttString('bar') }); + + // WHEN + expect(() => { + // THEN + app.synth(); + }).not.toThrow(/only supported for stacks deployed to the same environment/); + }); +}); diff --git a/packages/@aws-cdk/integ-tests/test/assertions/sdk.test.ts b/packages/@aws-cdk/integ-tests/test/assertions/sdk.test.ts index 672888f937892..3d0cbaa57f13b 100644 --- a/packages/@aws-cdk/integ-tests/test/assertions/sdk.test.ts +++ b/packages/@aws-cdk/integ-tests/test/assertions/sdk.test.ts @@ -1,6 +1,6 @@ -import { Template, Match } from '@aws-cdk/assertions'; +import { Match, Template } from '@aws-cdk/assertions'; import { App, CfnOutput } from '@aws-cdk/core'; -import { LogType, InvocationType, ExpectedResult } from '../../lib/assertions'; +import { ExpectedResult, InvocationType, LogType } from '../../lib/assertions'; import { DeployAssert } from '../../lib/assertions/private/deploy-assert'; describe('AwsApiCall', () => { From 78190fcfa76d6ab9e1668f0e13335b7d972e3584 Mon Sep 17 00:00:00 2001 From: Arun Donti Date: Thu, 6 Oct 2022 19:25:58 -0400 Subject: [PATCH 2/4] docs: update fixture --- packages/@aws-cdk/integ-tests/rosetta/default.ts-fixture | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/@aws-cdk/integ-tests/rosetta/default.ts-fixture b/packages/@aws-cdk/integ-tests/rosetta/default.ts-fixture index 168caf8aaf2af..9ab7231c55eab 100644 --- a/packages/@aws-cdk/integ-tests/rosetta/default.ts-fixture +++ b/packages/@aws-cdk/integ-tests/rosetta/default.ts-fixture @@ -22,6 +22,9 @@ import { CustomResource, } from '@aws-cdk/core'; import * as path from 'path'; +import * as ec2 from '@aws-cdk/aws-ec2'; +import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; +import * as s3 from '@aws-cdk/aws-s3'; import * as sqs from '@aws-cdk/aws-sqs'; import { IStateMachine } from '@aws-cdk/aws-stepfunctions'; import { RequireApproval } from '@aws-cdk/cloud-assembly-schema'; From 7a46a17a3149cd7b71e3daade71676433d6f589a Mon Sep 17 00:00:00 2001 From: Arun Donti Date: Fri, 7 Oct 2022 11:45:39 -0400 Subject: [PATCH 3/4] refactor: bring your own stack instead of passing an environment --- packages/@aws-cdk/integ-tests/README.md | 31 ++++------- .../lib/assertions/private/deploy-assert.ts | 10 ++-- .../@aws-cdk/integ-tests/lib/test-case.ts | 20 ++++---- .../integ-tests/rosetta/default.ts-fixture | 3 -- .../test/assertions/deploy-assert.test.ts | 51 ++++++++++++------- 5 files changed, 60 insertions(+), 55 deletions(-) diff --git a/packages/@aws-cdk/integ-tests/README.md b/packages/@aws-cdk/integ-tests/README.md index a561459904c9d..af75c3e0f03cf 100644 --- a/packages/@aws-cdk/integ-tests/README.md +++ b/packages/@aws-cdk/integ-tests/README.md @@ -192,6 +192,17 @@ const integ = new IntegTest(app, 'Integ', { testCases: [stack] }); integ.assertions.awsApiCall('S3', 'getObject'); ``` +By default an assertions stack is automatically generated for you. You may however provide your own stack to use. + +```ts +declare const app: App; +declare const stack: Stack; +declare const assertionsStack: Stack; + +const integ = new IntegTest(app, 'Integ', { testCases: [stack], assertionsStack: assertionsStack }); +integ.assertions.awsApiCall('S3', 'getObject'); +``` + - Part of a normal CDK deployment In this case you may be using assertions as part of a normal CDK deployment in order to make an assertion on the infrastructure @@ -264,26 +275,6 @@ integ.assertions.awsApiCall('SQS', 'receiveMessage', { }); ``` - -Additionally, you can test non environment-agnostic stacks by setting the environment for the integration tests: - -```ts -declare const app: App; -const env = { region: 'us-west-2' } -const stack = new Stack(app, 'nlb-test', { env: env } ); - -const nlb = new elbv2.NetworkLoadBalancer(stack, 'nlb', { vpc: new ec2.Vpc(stack, 'vpc') }) -// requires region to be set -nlb.logAccessLogs(new s3.Bucket(stack, 'logbucket')) -const integ = new IntegTest(app, 'Integ', { - testCases: [stack], - env: env, -}); -integ.assertions.awsApiCall('Elbv2', 'describeLoadBalancers', { - Names: [nlb.loadBalancerName] -}); -``` - By default, the `AwsApiCall` construct will automatically add the correct IAM policies to allow the Lambda function to make the API call. It does this based on the `service` and `api` that is provided. In the above example the service is `SQS` and the api is diff --git a/packages/@aws-cdk/integ-tests/lib/assertions/private/deploy-assert.ts b/packages/@aws-cdk/integ-tests/lib/assertions/private/deploy-assert.ts index 177a89fb9d9b4..3cce887cc27b0 100644 --- a/packages/@aws-cdk/integ-tests/lib/assertions/private/deploy-assert.ts +++ b/packages/@aws-cdk/integ-tests/lib/assertions/private/deploy-assert.ts @@ -1,4 +1,4 @@ -import { Environment, Stack } from '@aws-cdk/core'; +import { Stack } from '@aws-cdk/core'; import { Construct, IConstruct, Node } from 'constructs'; import { IApiCall } from '../api-call-base'; import { EqualsAssertion } from '../assertions'; @@ -16,11 +16,11 @@ const DEPLOY_ASSERT_SYMBOL = Symbol.for('@aws-cdk/integ-tests.DeployAssert'); export interface DeployAssertProps { /** - * The environment for the assertions stack + * A stack to use for assertions * - * @default - environment-agnostic + * @default - a stack is created for you */ - readonly env?: Environment + readonly stack?: Stack } /** @@ -53,7 +53,7 @@ export class DeployAssert extends Construct implements IDeployAssert { constructor(scope: Construct, props?: DeployAssertProps) { super(scope, 'Default'); - this.scope = new Stack(scope, 'DeployAssert', { env: props?.env }); + this.scope = props?.stack ?? new Stack(scope, 'DeployAssert'); Object.defineProperty(this, DEPLOY_ASSERT_SYMBOL, { value: true }); } diff --git a/packages/@aws-cdk/integ-tests/lib/test-case.ts b/packages/@aws-cdk/integ-tests/lib/test-case.ts index 7e22c2261a87a..a7d6f8e312c50 100644 --- a/packages/@aws-cdk/integ-tests/lib/test-case.ts +++ b/packages/@aws-cdk/integ-tests/lib/test-case.ts @@ -1,5 +1,5 @@ import { IntegManifest, Manifest, TestCase, TestOptions } from '@aws-cdk/cloud-assembly-schema'; -import { attachCustomSynthesis, Environment, ISynthesisSession, Stack, StackProps } from '@aws-cdk/core'; +import { attachCustomSynthesis, ISynthesisSession, Stack, StackProps } from '@aws-cdk/core'; import { Construct } from 'constructs'; import { IDeployAssert } from './assertions'; import { DeployAssert } from './assertions/private/deploy-assert'; @@ -17,11 +17,11 @@ export interface IntegTestCaseProps extends TestOptions { readonly stacks: Stack[]; /** - * Specify an environment for the assertions stack + * Specify a stack to use for assertions * - * @default - environment-agnostic + * @default - a stack is created for you */ - readonly env?: Environment + readonly assertionsStack?: Stack } /** @@ -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, { env: props.env }); + this._assert = new DeployAssert(this, { stack: props.assertionsStack }); this.assertions = this._assert; } @@ -126,7 +126,7 @@ export interface IntegTestProps extends TestOptions { /** * Enable lookups for this test. If lookups are enabled * then `stackUpdateWorkflow` must be set to false. - * Lookups should only be enabled when you are explicitely testing + * Lookups should only be enabled when you are explicitly testing * lookups. * * @default false @@ -134,11 +134,11 @@ export interface IntegTestProps extends TestOptions { readonly enableLookups?: boolean; /** - * Set an AWS environment (account/region) for the assertions stack. + * Specify a stack to use for assertions * - * @default - environment-agnostic + * @default - a stack is created for you */ - readonly env?: Environment + readonly assertionsStack?: Stack } /** @@ -164,7 +164,7 @@ export class IntegTest extends Construct { allowDestroy: props.allowDestroy, cdkCommandOptions: props.cdkCommandOptions, stackUpdateWorkflow: props.stackUpdateWorkflow, - env: props.env, + assertionsStack: props.assertionsStack, }); this.assertions = defaultTestCase.assertions; diff --git a/packages/@aws-cdk/integ-tests/rosetta/default.ts-fixture b/packages/@aws-cdk/integ-tests/rosetta/default.ts-fixture index 9ab7231c55eab..168caf8aaf2af 100644 --- a/packages/@aws-cdk/integ-tests/rosetta/default.ts-fixture +++ b/packages/@aws-cdk/integ-tests/rosetta/default.ts-fixture @@ -22,9 +22,6 @@ import { CustomResource, } from '@aws-cdk/core'; import * as path from 'path'; -import * as ec2 from '@aws-cdk/aws-ec2'; -import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; -import * as s3 from '@aws-cdk/aws-s3'; import * as sqs from '@aws-cdk/aws-sqs'; import { IStateMachine } from '@aws-cdk/aws-stepfunctions'; import { RequireApproval } from '@aws-cdk/cloud-assembly-schema'; diff --git a/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts b/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts index 90839f7ea01fb..2c65008c6f5a8 100644 --- a/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts +++ b/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts @@ -166,34 +166,51 @@ describe('DeployAssert', () => { }); }); -describe('Environment aware assertions', () => { - test('throw when environment not provided', () => { +describe('User provided assertions stack', () => { + test('Same stack for integration test and assertions', () => { //GIVEN const app = new App(); - const env = { region: 'us-west-2' }; - const stack = new Stack(app, 'TestStack', { env: env }); - const cr = new CustomResource(stack, 'cr', { serviceToken: 'foo' }); - const integ = new IntegTest(app, 'integ', { - testCases: [stack], - }); - integ.assertions.awsApiCall('Service', 'api', { Reference: cr.getAttString('bar') }); + const stack = new Stack(app, 'TestStack'); + const deplossert = new DeployAssert(app, { stack }); // WHEN - expect(() => { - // THEN - app.synth(); - }).toThrow(/only supported for stacks deployed to the same environment/); + const cr = new CustomResource(stack, 'cr', { resourceType: 'Custom::Bar', serviceToken: 'foo' }); + deplossert.awsApiCall('Service', 'Api', { Reference: cr.ref }); + + // THEN + const template = Template.fromStack(stack); + template.resourceCountIs('Custom::DeployAssert@SdkCallServiceApi', 1); + template.resourceCountIs('Custom::Bar', 1); + }); + + test('Different stack for integration test and assertions', () => { + //GIVEN + const app = new App(); + const integStack = new Stack(app, 'TestStack'); + const assertionsStack = new Stack(app, 'AssertionsStack'); + const deplossert = new DeployAssert(app, { stack: assertionsStack }); + + // WHEN + const cr = new CustomResource(integStack, 'cr', { resourceType: 'Custom::Bar', serviceToken: 'foo' }); + deplossert.awsApiCall('Service', 'Api', { Reference: cr.ref }); + + // THEN + const integTemplate = Template.fromStack(integStack); + const assertionsTemplate = Template.fromStack(assertionsStack); + integTemplate.resourceCountIs('Custom::Bar', 1); + assertionsTemplate.resourceCountIs('Custom::DeployAssert@SdkCallServiceApi', 1); }); test('not throw when environment matches', () => { //GIVEN const app = new App(); const env = { region: 'us-west-2' }; - const stack = new Stack(app, 'TestStack', { env: env }); - const cr = new CustomResource(stack, 'cr', { serviceToken: 'foo' }); + const integStack = new Stack(app, 'IntegStack', { env: env }); + const assertionsStack = new Stack(app, 'AssertionsStack', { env: env }); + const cr = new CustomResource(integStack, 'cr', { serviceToken: 'foo' }); const integ = new IntegTest(app, 'integ', { - testCases: [stack], - env: env, + testCases: [integStack], + assertionsStack: assertionsStack, }); integ.assertions.awsApiCall('Service', 'api', { Reference: cr.getAttString('bar') }); From 18c8939a642e09a4199a259445a82faf87018e36 Mon Sep 17 00:00:00 2001 From: Arun Donti Date: Fri, 7 Oct 2022 12:32:45 -0400 Subject: [PATCH 4/4] refactor: assertionsStack to assertionStack --- packages/@aws-cdk/integ-tests/README.md | 4 ++-- .../@aws-cdk/integ-tests/lib/test-case.ts | 8 +++---- .../test/assertions/deploy-assert.test.ts | 24 ++++++++++++------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/@aws-cdk/integ-tests/README.md b/packages/@aws-cdk/integ-tests/README.md index af75c3e0f03cf..08c2e70fa811b 100644 --- a/packages/@aws-cdk/integ-tests/README.md +++ b/packages/@aws-cdk/integ-tests/README.md @@ -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'); ``` diff --git a/packages/@aws-cdk/integ-tests/lib/test-case.ts b/packages/@aws-cdk/integ-tests/lib/test-case.ts index a7d6f8e312c50..50aa946ac155c 100644 --- a/packages/@aws-cdk/integ-tests/lib/test-case.ts +++ b/packages/@aws-cdk/integ-tests/lib/test-case.ts @@ -21,7 +21,7 @@ export interface IntegTestCaseProps extends TestOptions { * * @default - a stack is created for you */ - readonly assertionsStack?: Stack + readonly assertionStack?: Stack } /** @@ -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; } @@ -138,7 +138,7 @@ export interface IntegTestProps extends TestOptions { * * @default - a stack is created for you */ - readonly assertionsStack?: Stack + readonly assertionStack?: Stack } /** @@ -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; diff --git a/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts b/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts index 2c65008c6f5a8..df7a5253dba62 100644 --- a/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts +++ b/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts @@ -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); @@ -187,18 +190,21 @@ 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', () => { @@ -206,11 +212,11 @@ describe('User provided assertions stack', () => { 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') });