Skip to content

Commit

Permalink
chore(cli): make integ tests v2-aware (#17122)
Browse files Browse the repository at this point in the history
Integ tests for v2 requires installing different packages and switching
off some tests that don't make sense.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr committed Oct 25, 2021
1 parent bdf30c6 commit 3eab427
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 125 deletions.
49 changes: 32 additions & 17 deletions packages/aws-cdk/test/integ/cli/app/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
const path = require('path');
const cdk = require('@aws-cdk/core');
const ec2 = require('@aws-cdk/aws-ec2');
const ssm = require('@aws-cdk/aws-ssm');
const iam = require('@aws-cdk/aws-iam');
const sns = require('@aws-cdk/aws-sns');
const lambda = require('@aws-cdk/aws-lambda');
const docker = require('@aws-cdk/aws-ecr-assets');
const core = require('@aws-cdk/core')

var constructs = require('constructs');
if (process.env.PACKAGE_LAYOUT_VERSION === '1') {
var cdk = require('@aws-cdk/core');
var ec2 = require('@aws-cdk/aws-ec2');
var ssm = require('@aws-cdk/aws-ssm');
var iam = require('@aws-cdk/aws-iam');
var sns = require('@aws-cdk/aws-sns');
var lambda = require('@aws-cdk/aws-lambda');
var docker = require('@aws-cdk/aws-ecr-assets');
} else {
var cdk = require('aws-cdk-lib');
var {
aws_ec2: ec2,
aws_ssm: ssm,
aws_iam: iam,
aws_sns: sns,
aws_lambda: lambda,
aws_ecr_assets: docker
} = require('aws-cdk-lib');
}

const { Annotations } = cdk;
const { StackWithNestedStack, StackWithNestedStackUsingParameters } = require('./nested-stack');
const { Annotations } = require('@aws-cdk/core');

const stackPrefix = process.env.STACK_NAME_PREFIX;
if (!stackPrefix) {
Expand Down Expand Up @@ -48,11 +62,11 @@ class YourStack extends cdk.Stack {
class StackUsingContext extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, props);
new core.CfnResource(this, 'Handle', {
new cdk.CfnResource(this, 'Handle', {
type: 'AWS::CloudFormation::WaitConditionHandle'
});

new core.CfnOutput(this, 'Output', {
new cdk.CfnOutput(this, 'Output', {
value: this.availabilityZones,
});
}
Expand Down Expand Up @@ -167,7 +181,7 @@ class MissingSSMParameterStack extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, props);

const parameterName = this.node.tryGetContext('test:ssm-parameter-name');
const parameterName = constructs.Node.of(this).tryGetContext('test:ssm-parameter-name');
if (parameterName) {
const param = getSsmParameterValue(this, parameterName);
new iam.Role(this, 'PhonyRole', { assumedBy: new iam.AccountPrincipal(param) });
Expand Down Expand Up @@ -199,7 +213,7 @@ class DockerStack extends cdk.Stack {

// Add at least a single resource (WaitConditionHandle), otherwise this stack will never
// be deployed (and its assets never built)
new core.CfnResource(this, 'Handle', {
new cdk.CfnResource(this, 'Handle', {
type: 'AWS::CloudFormation::WaitConditionHandle'
});
}
Expand All @@ -216,7 +230,7 @@ class DockerStackWithCustomFile extends cdk.Stack {

// Add at least a single resource (WaitConditionHandle), otherwise this stack will never
// be deployed (and its assets never built)
new core.CfnResource(this, 'Handle', {
new cdk.CfnResource(this, 'Handle', {
type: 'AWS::CloudFormation::WaitConditionHandle'
});
}
Expand All @@ -228,7 +242,7 @@ class FailedStack extends cdk.Stack {
super(parent, id, props);

// fails on 'Property PolicyDocument cannot be empty'.
new core.CfnResource(this, 'EmptyPolicy', {
new cdk.CfnResource(this, 'EmptyPolicy', {
type: 'AWS::IAM::Policy'
})

Expand All @@ -243,9 +257,10 @@ class DefineVpcStack extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, props);

new ec2.Vpc(this, 'VPC', {
const vpc = new ec2.Vpc(this, 'VPC', {
maxAzs: 1,
}).node.applyAspect(new cdk.Tag(VPC_TAG_NAME, VPC_TAG_VALUE));
})
cdk.Aspects.of(vpc).add(new cdk.Tag(VPC_TAG_NAME, VPC_TAG_VALUE));
}
}

Expand Down
14 changes: 11 additions & 3 deletions packages/aws-cdk/test/integ/cli/app/nested-stack.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
const cfn = require('@aws-cdk/aws-cloudformation');
const sns = require('@aws-cdk/aws-sns');
const { Stack, CfnParameter } = require('@aws-cdk/core');
if (process.env.PACKAGE_LAYOUT_VERSION === '1') {
var cfn = require('@aws-cdk/aws-cloudformation');
var sns = require('@aws-cdk/aws-sns');
var { Stack, CfnParameter } = require('@aws-cdk/core');
} else {
var {
aws_cloudformation: cfn,
aws_sns: sns,
} = require('aws-cdk-lib');
var { Stack, CfnParameter } = require('aws-cdk-lib');
}

class StackWithNestedStack extends Stack {
constructor(scope, id) {
Expand Down
39 changes: 22 additions & 17 deletions packages/aws-cdk/test/integ/cli/bootstrapping.integtest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import { randomString, withDefaultFixture } from '../helpers/cdk';
import { MAJOR_VERSION, randomString, withDefaultFixture } from '../helpers/cdk';
import { integTest } from '../helpers/test-helpers';

const timeout = process.env.CODEBUILD_BUILD_ID ? // if the process is running in CodeBuild
Expand Down Expand Up @@ -129,22 +129,27 @@ integTest('deploy old style synthesis to new style bootstrap', withDefaultFixtur
});
}));

integTest('deploying new style synthesis to old style bootstrap fails', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.bootstrapStackName;

await fixture.cdkBootstrapLegacy({
toolkitStackName: bootstrapStackName,
});

// Deploy stack that uses file assets, this fails because the bootstrap stack
// is version checked.
await expect(fixture.cdkDeploy('lambda', {
options: [
'--toolkit-stack-name', bootstrapStackName,
'--context', '@aws-cdk/core:newStyleStackSynthesis=1',
],
})).rejects.toThrow('exited with error');
}));
if (MAJOR_VERSION === '1') {
// For v2, the default bootstrap is the modern bootstrap, so this test is predicated on invalid
// assumptions.

integTest('deploying new style synthesis to old style bootstrap fails', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.bootstrapStackName;

await fixture.cdkBootstrapLegacy({
toolkitStackName: bootstrapStackName,
});

// Deploy stack that uses file assets, this fails because the bootstrap stack
// is version checked.
await expect(fixture.cdkDeploy('lambda', {
options: [
'--toolkit-stack-name', bootstrapStackName,
'--context', '@aws-cdk/core:newStyleStackSynthesis=1',
],
})).rejects.toThrow('exited with error');
}));
}

integTest('can create a legacy bootstrap stack with --public-access-block-configuration=false', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.bootstrapStackName;
Expand Down
Loading

0 comments on commit 3eab427

Please sign in to comment.